public FieldDefinition GetFieldDefinitionWithId(MemberTypeId id)
        {
            FieldDefinition fieldDefinition;

            this._fields.TryGetValue(id, out fieldDefinition);
            return(fieldDefinition);
        }
        public PropertyDefinition GetPropertyDefinitionWithId(MemberTypeId id)
        {
            PropertyDefinition propertyDefinition;

            this._properties.TryGetValue(id, out propertyDefinition);
            return(propertyDefinition);
        }
Exemple #3
0
 public PropertyDefinition(PropertyInfo propertyInfo, MemberTypeId id)
     : base((MemberInfo)propertyInfo, id)
 {
     this.PropertyInfo = propertyInfo;
     this.SaveablePropertyAttribute = propertyInfo.GetCustomAttribute <SaveablePropertyAttribute>();
     this.SetMethod = this.PropertyInfo.GetSetMethod(true);
     if (this.SetMethod == (MethodInfo)null && this.PropertyInfo.DeclaringType != (Type)null)
     {
         PropertyInfo property = this.PropertyInfo.DeclaringType.GetProperty(this.PropertyInfo.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
         if (property != (PropertyInfo)null)
         {
             this.SetMethod = property.GetSetMethod(true);
         }
     }
     if (this.SetMethod == (MethodInfo)null)
     {
         throw new Exception("Property " + this.PropertyInfo.Name + " at Type " + this.PropertyInfo.DeclaringType.FullName + " does not have setter method.");
     }
     this.GetMethod = this.PropertyInfo.GetGetMethod(true);
     if (this.GetMethod == (MethodInfo)null && this.PropertyInfo.DeclaringType != (Type)null)
     {
         PropertyInfo property = this.PropertyInfo.DeclaringType.GetProperty(this.PropertyInfo.Name);
         if (property != (PropertyInfo)null)
         {
             this.GetMethod = property.GetGetMethod(true);
         }
     }
     if (this.GetMethod == (MethodInfo)null)
     {
         throw new Exception("Property " + this.PropertyInfo.Name + " at Type " + this.PropertyInfo.DeclaringType.FullName + " does not have getter method.");
     }
 }
 public void CollectProperties()
 {
     foreach (PropertyInfo property in this.Type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
     {
         Attribute[] array = property.GetCustomAttributes(typeof(SaveablePropertyAttribute)).ToArray <Attribute>();
         if (array.Length != 0)
         {
             SaveablePropertyAttribute propertyAttribute = (SaveablePropertyAttribute)array[0];
             MemberTypeId       memberTypeId             = new MemberTypeId(TypeDefinitionBase.GetClassLevel(property.DeclaringType), propertyAttribute.LocalSaveId);
             PropertyDefinition propertyDefinition       = new PropertyDefinition(property, memberTypeId);
             if (this._properties.ContainsKey(memberTypeId))
             {
                 this._errors.Add("SaveId " + (object)memberTypeId + " of property " + propertyDefinition.PropertyInfo.Name + " is already defined in type " + this.Type.FullName);
             }
             else
             {
                 this._properties.Add(memberTypeId, propertyDefinition);
                 this.MemberDefinitions.Add((MemberDefinition)propertyDefinition);
             }
         }
     }
 }
 public void CollectFields()
 {
     foreach (FieldInfo fieldInfo in TypeDefinition.GetFieldsOfType(this.Type).ToArray <FieldInfo>())
     {
         Attribute[] array = fieldInfo.GetCustomAttributes(typeof(SaveableFieldAttribute)).ToArray <Attribute>();
         if (array.Length != 0)
         {
             SaveableFieldAttribute saveableFieldAttribute = (SaveableFieldAttribute)array[0];
             MemberTypeId           memberTypeId           = new MemberTypeId(TypeDefinitionBase.GetClassLevel(fieldInfo.DeclaringType), saveableFieldAttribute.LocalSaveId);
             FieldDefinition        fieldDefinition        = new FieldDefinition(fieldInfo, memberTypeId);
             if (this._fields.ContainsKey(memberTypeId))
             {
                 this._errors.Add("SaveId " + (object)memberTypeId + " of field " + (object)fieldDefinition.FieldInfo + " is already defined in type " + this.Type.FullName);
             }
             else
             {
                 this._fields.Add(memberTypeId, fieldDefinition);
                 this.MemberDefinitions.Add((MemberDefinition)fieldDefinition);
             }
         }
     }
     foreach (CustomField customField in this.CustomFields)
     {
         string          name            = customField.Name;
         short           saveId          = customField.SaveId;
         FieldInfo       field           = this.Type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
         MemberTypeId    memberTypeId    = new MemberTypeId(TypeDefinitionBase.GetClassLevel(field.DeclaringType), saveId);
         FieldDefinition fieldDefinition = new FieldDefinition(field, memberTypeId);
         if (this._fields.ContainsKey(memberTypeId))
         {
             this._errors.Add("SaveId " + (object)memberTypeId + " of field " + (object)fieldDefinition.FieldInfo + " is already defined in type " + this.Type.FullName);
         }
         else
         {
             this._fields.Add(memberTypeId, fieldDefinition);
             this.MemberDefinitions.Add((MemberDefinition)fieldDefinition);
         }
     }
 }
Exemple #6
0
 protected MemberDefinition(MemberInfo memberInfo, MemberTypeId id)
 {
     this.MemberInfo = memberInfo;
     this.Id         = id;
 }
 public FieldDefinition(FieldInfo fieldInfo, MemberTypeId id)
     : base((MemberInfo)fieldInfo, id)
 {
     this.FieldInfo = fieldInfo;
     this.SaveableFieldAttribute = fieldInfo.GetCustomAttribute <SaveableFieldAttribute>();
 }