[DataMember] Help

garysimmons
edited November 2011 in DotNet
Hi Guys,

As a programmer is currently in the process of moving over to C# and .net (coming C++ and before that C) I am having a little trouble grasping some of the practices with regards operation structures in the 'lite' framework.

The [DataMember] directive? used is really confusing me in Operation derived classes. I have attached a snippet of code below from 'lite' project's JoinRequest class and was hoping someone here could explain to me exactly how these DataMembers work and how the effect the properties that they are defined above.
 public class JoinRequest : Operation
    {
     
       ....snipped......  

        [DataMember(Code = (byte)ParameterKey.ActorProperties, IsOptional = true)]
        public Hashtable ActorProperties { get; set; }

        [DataMember(Code = (byte)ParameterKey.Broadcast, IsOptional = true)]
        public bool BroadcastActorProperties { get; set; }

        [DataMember(Code = (byte)ParameterKey.GameId)]
        public string GameId { get; set; }

        [DataMember(Code = (byte)ParameterKey.GameProperties, IsOptional = true)]
        public Hashtable GameProperties { get; set; }
    }

Above you can see that there are 4 DataMember directives that define a value for 'Code'. And yet looking through the classes source (and those of the base classes) there is no member that exists called 'Code'? What am I missing?

Comments

  • DataMember is used as "Attribute". It's setup as class (within our assembly) and used for reflection in our framework. High level: This allows us to identify the properties we should fill in with values from the client's requests or the other way round.

    DataMember(Code = (byte)ParameterKey.ActorProperties, IsOptional = true)
    The "Code" in this case is in the DataMember. When used as attribute, the line above is initializing a DataMember for the property ActorProperties.