public ObjectType(string name, string comment, ObjectType inherits) : base(name) { Comment = comment; Inherits = inherits; this.fields = new SortedList<int, Field>(); }
private void AnalyzeTypeType(Type type) { ObjectType objectType = new ObjectType(type.GenericFullName(), "Tuple of values.", null); foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { AnalyzeType(objectType, property); } objectType.Validate(); this.types.Add(objectType.Name, objectType); }
private void AnalyzeType(ObjectType objectType, Type type, SerializeFieldAttribute attribute, string fieldName) { if (this.types.ContainsKey(type.GenericFullName())) { objectType.AddField(attribute.Index, new Field(this.types[type.GenericFullName()], type.SpecificFullName(), fieldName, attribute.Comment, attribute.Condition, attribute.MinVersion)); } else if (type.IsSubclassOf(this.serializableType)) { AnalyzeType(type); objectType.AddField(attribute.Index, new Field(this.types[type.GenericFullName()], type.SpecificFullName(), fieldName, attribute.Comment, attribute.Condition, attribute.MinVersion)); } else if (IsListOf(type)) { AnalyzeListType(type); objectType.AddField(attribute.Index, new Field(this.types[type.GenericFullName()], type.SpecificFullName(), fieldName, attribute.Comment, attribute.Condition, attribute.MinVersion)); } else if (type.IsEnum) { AnalyzeEnumType(type); objectType.AddField(attribute.Index, new Field(this.types[type.GenericFullName()], type.SpecificFullName(), fieldName, attribute.Comment, attribute.Condition, attribute.MinVersion)); } else { Console.WriteLine("** Type {0} not recognized", type.GenericFullName()); Console.ReadLine(); } }
private void AnalyzeType(ObjectType objectType, PropertyInfo property) { var attribute = (SerializeFieldAttribute)property.GetCustomAttributes(this.serializeFieldAttribute, false).SingleOrDefault(); if (attribute != null) { AnalyzeType( objectType, attribute.AlternateType == null ? property.PropertyType : attribute.AlternateType, attribute, property.Name); } }
private void AnalyzeType(ObjectType objectType, FieldInfo field) { var attribute = (SerializeFieldAttribute)field.GetCustomAttributes(this.serializeFieldAttribute, false).SingleOrDefault(); if (attribute != null) { AnalyzeType( objectType, attribute.AlternateType == null ? field.FieldType : attribute.AlternateType, attribute, field.Name); } }
private void AnalyzeSerializableType(Type type) { var soa = (SerializeObjectAttribute)type.GetCustomAttributes(this.serializeObjectAttribute, false).SingleOrDefault(); if (soa != null) { ObjectType inherits = null; if (type.BaseType != typeof(object)) { if (!this.types.ContainsKey(type.BaseType.GenericFullName())) { AnalyzeType(type.BaseType); } inherits = this.types[type.BaseType.GenericFullName()] as ObjectType; } ObjectType objectType = new ObjectType(type.GenericFullName(), soa.Comment, inherits); foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { if (field.DeclaringType == type) { AnalyzeType(objectType, field); } } foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { if (property.DeclaringType == type) { AnalyzeType(objectType, property); } } if (soa == null) { Console.WriteLine(" Serialize Object Attribute on type " + type.FullName + " missing"); Console.ReadLine(); } objectType.Validate(); this.types.Add(objectType.Name, objectType); } else { Console.WriteLine("Type {0} has no SerializeObjectAttribute!", type.FullName); Console.ReadLine(); } }