private PacketDataTypes() { this.container = new Dictionary <string, PacketDataType>(); Assembly assembly = Assembly.GetExecutingAssembly(); IEnumerable <Type> types = assembly.GetTypes().Where(c => c.GetInterface(typeof(IPacketDataTypeParser).Name) != null && c.GetCustomAttributes(typeof(APacketDataTypeParser), false).Length == 1); foreach (Type type in types) { APacketDataTypeParser attribute = (APacketDataTypeParser)(type.GetCustomAttributes(typeof(APacketDataTypeParser), false)[0]); PacketDataType dataType = null; if (!container.ContainsKey(attribute.DataType)) { dataType = new PacketDataType(attribute.DataType); this.container.Add(attribute.DataType, dataType); } else { dataType = this.container[attribute.DataType]; } FieldInfo instanceField = type.GetField("instance", BindingFlags.NonPublic | BindingFlags.Static); if (instanceField != null) { dataType.AddParser(attribute.Protocol, (IPacketDataTypeParser)instanceField.GetValue(null)); } } }
public PacketField(string name, PacketDataType dataType, object defaultValue) { this.name = name; this.dataType = dataType; this.defaultValue = defaultValue; }
public PacketField(string name, PacketDataType dataType) { this.name = name; this.dataType = dataType; }
private PacketDataTypes() { this.container = new Dictionary<string, PacketDataType>(); Assembly assembly = Assembly.GetExecutingAssembly(); IEnumerable<Type> types = assembly.GetTypes().Where(c => c.GetInterface(typeof(IPacketDataTypeParser).Name) != null && c.GetCustomAttributes(typeof(APacketDataTypeParser), false).Length == 1); foreach(Type type in types) { APacketDataTypeParser attribute = (APacketDataTypeParser)(type.GetCustomAttributes(typeof(APacketDataTypeParser), false)[0]); PacketDataType dataType = null; if(!container.ContainsKey(attribute.DataType)) { dataType = new PacketDataType(attribute.DataType); this.container.Add(attribute.DataType, dataType); } else { dataType = this.container[attribute.DataType]; } FieldInfo instanceField = type.GetField("instance", BindingFlags.NonPublic | BindingFlags.Static); if(instanceField != null) { dataType.AddParser(attribute.Protocol, (IPacketDataTypeParser)instanceField.GetValue(null)); } } }