Exemplo n.º 1
0
 private GlobalProperty(String name, Type type, Type ownerType, int size, GlobalPropertyMetadata metadata)
 {
     Name = name;
     Type = type;
     OwnerType = ownerType;
     Size = size;
     IsArray = type.IsArray;
     GlobalPropertyMetadata = metadata ?? new GlobalPropertyMetadata();
 }
Exemplo n.º 2
0
 public static GlobalProperty Register(String name, Type propertyType, Type ownerType,
     GlobalPropertyMetadata metadata)
 {
     int size = 0;
     Type typeToSize;
     if (propertyType.IsArray)
     {
         typeToSize = propertyType.GetElementType();
     }
     else
     {
         typeToSize = propertyType;
     }
     if (typeToSize.IsValueType && Nullable.GetUnderlyingType(typeToSize) == null)
     {
         foreach (FieldInfo fieldInfo in typeToSize.GetFields())
         {
             object[] attributeData = fieldInfo.GetCustomAttributes(typeof(FieldSizeIgnoreAttribute), false);
             //++ if there is an array, it's impossible to size anyways
             if (fieldInfo.FieldType.IsArray && attributeData.Length == 0)
             {
                 size = -1;
                 break;
             }
             if (attributeData.Length == 0)
             {
                 size += Marshal.SizeOf(fieldInfo.FieldType);
             }
         }
     }
     return new GlobalProperty(name, propertyType, ownerType, size, metadata);
 }