public static HeroDefinition Create(byte[] data, int version) { HeroDefinition.Types types = (HeroDefinition.Types) 0; if (version == 1) { types = (HeroDefinition.Types)((int)BitConverter.ToUInt16(data, 4) >> 3 & 15); } else if (version == 2) { types = (HeroDefinition.Types)((int)BitConverter.ToUInt16(data, 16) >> 3 & 15); } switch (types) { case HeroDefinition.Types.Node: return((HeroDefinition) new HeroNodeDef(data, version)); case HeroDefinition.Types.Enumeration: return((HeroDefinition) new HeroEnumDef(data, version)); case HeroDefinition.Types.Field: return((HeroDefinition) new HeroFieldDef(data, version)); case HeroDefinition.Types.Class: return((HeroDefinition) new HeroClassDef(data, version)); case HeroDefinition.Types.Association: return((HeroDefinition) new HeroAssociationDef(data, version)); default: return((HeroDefinition)null); } }
protected HeroDefinition(byte[] data, int version) { this.Data = data; this.version = version; if (version == 1) { this.DomType = (int)BitConverter.ToUInt16(this.Data, 4) >> 1 & 3; this.Type = (HeroDefinition.Types)((int)BitConverter.ToUInt16(this.Data, 4) >> 3 & 15); this.Name = this.GetString(BitConverter.ToUInt16(this.Data, 16)); this.Description = this.GetString(BitConverter.ToUInt16(this.Data, 18)); this.Id = BitConverter.ToUInt64(this.Data, 8); } else if (version == 2) { this.DomType = (int)BitConverter.ToUInt16(this.Data, 16) >> 1 & 3; this.Type = (HeroDefinition.Types)((int)BitConverter.ToUInt16(this.Data, 16) >> 3 & 15); this.Name = this.GetString(BitConverter.ToUInt16(this.Data, 20)); this.Description = this.GetString(BitConverter.ToUInt16(this.Data, 22)); this.Id = BitConverter.ToUInt64(this.Data, 8); } switch (this.Type) { case HeroDefinition.Types.Node: break; case HeroDefinition.Types.Enumeration: break; case HeroDefinition.Types.Field: break; case HeroDefinition.Types.Class: break; case HeroDefinition.Types.Association: break; case HeroDefinition.Types.Script: break; default: throw new InvalidDataException("definition type was unknown"); } }