public override object Clone() { SirenCustomEnum val = new SirenCustomEnum(Name) { Attribute = Attribute.Clone() as SirenEnumAttribute }; val.FieldNames.AddRange(FieldNames); val.FieldValues.AddRange(FieldValues); val.UnderlyType = UnderlyType; return val; }
public override object Clone() { SirenCustomEnum val = new SirenCustomEnum(Name) { Attribute = Attribute.Clone() as SirenEnumAttribute }; val.FieldNames.AddRange(FieldNames); val.FieldValues.AddRange(FieldValues); val.UnderlyType = UnderlyType; return(val); }
public override bool LoadFrom(Stream stream) { base.LoadFrom(stream); Attribute.LoadFrom(stream); BaseTypeName = stream.ReadString(); //types uint typeCount = stream.ReadUInt(); for (int i = 0; i < typeCount; i++) { byte isClass = (byte)stream.ReadByte(); if (isClass == 1) { SirenCustomClass type = new SirenCustomClass(); type.LoadFrom(stream); type.Parent = this; Types.Add(type.Name, type); } else { SirenCustomEnum type = new SirenCustomEnum(); type.LoadFrom(stream); type.Parent = this; Types.Add(type.Name, type); } } //fields uint fieldCount = stream.ReadUInt(); for (int i = 0; i < fieldCount; i++) { SirenField field = new SirenField(); field.LoadFrom(stream); field.ParentType = this; FieldNameDict.Add(field.Name, field); field.Index = (ushort)(FieldNameDict.Count - 1); } return(true); }
static SirenMachine() { BuildinTypes.Add(Bool.Name, Bool); BuildinTypes.Add(Int8.Name, Int8); BuildinTypes.Add(UInt8.Name, UInt8); BuildinTypes.Add(Int16.Name, Int16); BuildinTypes.Add(UInt16.Name, UInt16); BuildinTypes.Add(Int32.Name, Int32); BuildinTypes.Add(UInt32.Name, UInt32); BuildinTypes.Add(Int64.Name, Int64); BuildinTypes.Add(UInt64.Name, UInt64); BuildinTypes.Add(Float.Name, Float); BuildinTypes.Add(Double.Name, Double); BuildinTypes.Add(String.Name, String); BuildinTypes.Add(Blob.Name, Blob); BuildinTypes.Add(List.Name, List); BuildinTypes.Add(Dictionary.Name, Dictionary); //alias BuildinTypes.Add("int8", Int8); BuildinTypes.Add("uint8", UInt8); BuildinTypes.Add("int16", Int16); BuildinTypes.Add("uint16", UInt16); BuildinTypes.Add("int32", Int32); BuildinTypes.Add("uint32", UInt32); BuildinTypes.Add("long", Int64); BuildinTypes.Add("ulong", UInt64); BuildinTypes.Add("string", String); BuildinTypes.Add("String", String); BuildinTypes.Add("blob", Blob); //register types var allAssemblies = GetAllAssemblies(); foreach (var assemblyName in allAssemblies) { var assembly = Assembly.Load(assemblyName.Value); var types = assembly.GetTypes(); foreach (var type in types) { var attr2 = type.GetCustomAttributes(typeof(SirenClassAttribute), false); if (attr2.Length > 0) { SirenCustomClass sirenClass = new SirenCustomClass(type, attr2[0] as SirenClassAttribute); AllSirenClasses.Add(type, sirenClass); } var attr3 = type.GetCustomAttributes(typeof(SirenEnumAttribute), false); if (attr3.Length > 0) { SirenCustomEnum sirenEnum = new SirenCustomEnum(type, attr3[0] as SirenEnumAttribute); AllSirenEnums.Add(type, sirenEnum); } } } foreach (var sirenClass in AllSirenClasses) { sirenClass.Value.Initialize(); } foreach (var sirenClass in AllSirenEnums) { sirenClass.Value.Initialize(); } }
public override bool LoadFrom(Stream stream) { base.LoadFrom(stream); Attribute.LoadFrom(stream); BaseTypeName = stream.ReadString(); //types uint typeCount = stream.ReadUInt(); for (int i = 0; i < typeCount; i++) { byte isClass = (byte)stream.ReadByte(); if (isClass == 1) { SirenCustomClass type = new SirenCustomClass(); type.LoadFrom(stream); type.Parent = this; Types.Add(type.Name, type); } else { SirenCustomEnum type = new SirenCustomEnum(); type.LoadFrom(stream); type.Parent = this; Types.Add(type.Name, type); } } //fields uint fieldCount = stream.ReadUInt(); for (int i = 0; i < fieldCount; i++) { SirenField field = new SirenField(); field.LoadFrom(stream); field.ParentType = this; FieldNameDict.Add(field.Name, field); field.Index = (ushort)(FieldNameDict.Count - 1); } return true; }
public void SerializeEnum(object obj, SirenCustomEnum sirenEnum) { Writer.OnValue(obj); }