473,503 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Correct way of serializing a "Quasi-singlton" class?

Is the following code correct for serializing a quasi-single class, that is
a class that has a descreet (though more than one, so not a true singleton)
number of static instances and no dynamically creatable instances? Please
forgive my use of terms. Quasi-signleton is a term I made up and static
instances is a little bogus too but I don't know the correct terms for what
I mean if there are any. However, I think the code below should be self
explanitory in this regard.

using System;
using System.Runtime.Serialization;

namespace SWIFT.Configuration.Workflow
{
/// <summary>
/// This class represents the various types of object which the swift
system is comprised of.
/// </summary>
/// <remarks>
/// There is only one intance of this class per each represented SWIFT
object type, similar to how there exists only one
/// instance of a System.Type object per class.
/// </remarks>
[Serializable]
public class ObjectType: ISerializable
{
private enum pObjectTypeEnum
{
Workspace,
Document,
Task,
User,
DataForm
}

public static readonly ObjectType Workspace = new
ObjectType(pObjectTypeEnum.Workspace,
"d37bdf57-8298-416e-b880-51892b78f63a", "Workspace");
public static readonly ObjectType Document = new
ObjectType(pObjectTypeEnum.Document, "289ef8ef-f56b-4b01-92b4-0191b222ddc3",
"Document");
public static readonly ObjectType Task = new
ObjectType(pObjectTypeEnum.Task, "e06b7ce4-3d30-45e4-bf94-118046be851f",
"Task");
public static readonly ObjectType User = new
ObjectType(pObjectTypeEnum.User, "17aedaeb-dfcb-4cf3-a13b-d6f02195a81f",
"User");
public static readonly ObjectType DataForm = new
ObjectType(pObjectTypeEnum.DataForm, "ace70065-d136-402f-96f3-0606cded7754",
"Data Form");

private static readonly System.Collections.Hashtable mcTypesByID = new
System.Collections.Hashtable();

public readonly string SysKey;
public readonly string Name;

private readonly int miType;

private ObjectType(pObjectTypeEnum eType, string sKey, string sName)
{
SysKey = sKey;
Name = sName;
miType = (int)eType;

mcTypesByID.Add(miType, this);
}

public new void GetObjectData(SerializationInfo info, StreamingContext
context)
{
info.AddValue("TypeID", miType);
info.SetType(typeof(ObjectType.ObjectTypeSerialize r));
}

internal ObjectType GetByType(int TypeID)
{
return (ObjectType)mcTypesByID[TypeID];
}

[Serializable]
private class ObjectTypeSerializer : IObjectReference, ISerializable
{
private readonly int miType;

private ObjectTypeSerializer(SerializationInfo info, StreamingContext
context)
{
miType = info.GetInt32("TypeID");
}

//required as part of ISerializable
public void GetObjectData(SerializationInfo info, StreamingContext
context) {}

public object GetRealObject(StreamingContext context)
{
return WFDataType.GetByType(miType);
}
}
}
}
Nov 15 '05 #1
0 1389

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4161
by: Dave C. | last post by:
Hi, I have a few things on my databases which seem to be neither true system objects or user objects - notably a table called 'dtproperties' (created by Enterprise manager as I understand,...
17
7235
by: Torbjørn Pettersen | last post by:
I've got a table where I want some of the cells to use a background image. The cells have variable height, so I am using an image with a rather small height to fill up the background of the cells,...
235
11496
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
0
1708
by: Philipp Lenssen | last post by:
There's a new quasi-standard in the world of HTML; the <a rel="nofollow" href="...">...</a>. It is already or soon implemented in Google, Yahoo, and MSN Search, as well as many different blogging...
15
122073
by: Gérard Talbot | last post by:
Hello all, I'd like to know and understand the difference between, say, <img src="/ImageFilename.png" width="123" height="456" alt=""> and <img src="/ImageFilename.png" style="width:...
22
3677
by: bq | last post by:
Hello, Two questions related to floating point support: What C compilers for the wintel (MS Windows + x86) platform are C99 compliant as far as <math.h> and <tgmath.h> are concerned? What...
28
2907
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
93
3870
by: jacob navia | last post by:
In this group there is a bunch of people that call themselves 'regulars' that insist in something called "portability". Portability for them means the least common denominator. Write your code...
2
2844
by: dkmd_nielsen | last post by:
I have two rather simple class methods coded in Ruby...my own each iterator: The iterator is used internally within the class/namespace, and be available externally. That way I can keep...
25
30788
by: Peng Yu | last post by:
Hi, It is possible to change the length of "\t" to a number other than 8. std::cout << "\t"; Thanks, Peng
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.