static TypeAccessor() { object tmp; var type = typeof(T); if (type == typeof(bool)) { tmp = new BooleanAccessor(); } if (type == typeof(byte)) { tmp = new ByteAccessor(); } if (type == typeof(sbyte)) { tmp = new SByteAccessor(); } if (type == typeof(ushort)) { tmp = new UInt16Accessor(); } if (type == typeof(short)) { tmp = new Int16Accessor(); } if (type == typeof(uint)) { tmp = new UInt32Accessor(); } if (type == typeof(int)) { tmp = new Int32Accessor(); } if (type == typeof(ulong)) { tmp = new UInt64Accessor(); } if (type == typeof(long)) { tmp = new Int64Accessor(); } if (type == typeof(float)) { tmp = new SingleAccessor(); } if (type == typeof(double)) { tmp = new DoubleAccessor(); } else if (type == typeof(Text)) { tmp = new TextAccessor(); } else if (type == typeof(Data)) { tmp = new DataAccessor(); } else if (type == typeof(Pointer)) { tmp = new PointerAccessor(); } else { #if FULLCLR bool isGroup = Attribute.IsDefined(type, typeof(GroupAttribute)); #else TypeInfo typeInfo = type.GetTypeInfo(); bool isGroup = typeInfo.IsDefined(typeof(GroupAttribute)); #endif if (isGroup) { tmp = new GroupAccessor <T>(); } else { #if FULLCLR var @struct = (StructAttribute)Attribute.GetCustomAttribute(type, typeof(StructAttribute)); #else var @struct = typeInfo.GetCustomAttribute <StructAttribute>(); #endif if (@struct == null) { #if FULLCLR if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(FixedSizeList <>)) { tmp = Activator.CreateInstance( typeof(FixedSizeListAccessor <>).MakeGenericType(type.GetGenericArguments())); } #else if (typeInfo.IsGenericType && type.GetGenericTypeDefinition() == typeof(FixedSizeList <>)) { tmp = Activator.CreateInstance( typeof(FixedSizeListAccessor <>).MakeGenericType(type.GenericTypeArguments)); } #endif else { tmp = new MissingMetadataAccessor <T>(); } } else { checked { tmp = StructAccessor <T> .Create(@struct.PreferredSize, (short)@struct.DataWords, (short)@struct.Pointers); } } } } Instance = (TypeAccessor <T>)tmp; }
static TypeAccessor() { object tmp; switch (Type.GetTypeCode(typeof(T))) { case TypeCode.Boolean: tmp = new BooleanAccessor(); break; case TypeCode.Byte: tmp = new ByteAccessor(); break; case TypeCode.SByte: tmp = new SByteAccessor(); break; case TypeCode.UInt16: tmp = new UInt16Accessor(); break; case TypeCode.Int16: tmp = new Int16Accessor(); break; case TypeCode.UInt32: tmp = new UInt32Accessor(); break; case TypeCode.Int32: tmp = new Int32Accessor(); break; case TypeCode.UInt64: tmp = new UInt64Accessor(); break; case TypeCode.Int64: tmp = new Int64Accessor(); break; case TypeCode.Single: tmp = new SingleAccessor(); break; case TypeCode.Double: tmp = new DoubleAccessor(); break; default: if (typeof(T) == typeof(Text)) { tmp = new TextAccessor(); } else if (typeof(T) == typeof(Data)) { tmp = new DataAccessor(); } else if (typeof(T) == typeof(Pointer)) { tmp = new PointerAccessor(); } else if (Attribute.IsDefined(typeof(T), typeof(GroupAttribute))) { tmp = new GroupAccessor <T>(); } else { var @struct = (StructAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(StructAttribute)); if (@struct == null) { if (typeof(T).IsGenericType && typeof(T).GetGenericTypeDefinition() == typeof(FixedSizeList <>)) { tmp = Activator.CreateInstance( typeof(FixedSizeListAccessor <>).MakeGenericType(typeof(T).GetGenericArguments())); } else { tmp = new MissingMetadataAccessor <T>(); } } else { checked { tmp = StructAccessor <T> .Create(@struct.PreferredSize, (short)@struct.DataWords, (short)@struct.Pointers); } } } break; } Instance = (TypeAccessor <T>)tmp; }