public EnumTypeDescriptor(TypeSerializers typeSerializers, Type type) { _typeSerializers = typeSerializers; _type = type; _name = typeSerializers.TypeToName(type); _signed = IsSignedEnum(type); _flags = IsFlagsEnum(type); var undertype = type.GetEnumUnderlyingType(); var enumValues = type.GetEnumValues(); IEnumerable<ulong> enumValuesUlongs; if (undertype == typeof(int)) enumValuesUlongs = enumValues.Cast<int>().Select(i => (ulong)i); else if (undertype == typeof(uint)) enumValuesUlongs = enumValues.Cast<uint>().Select(i => (ulong)i); else if (undertype == typeof(sbyte)) enumValuesUlongs = enumValues.Cast<sbyte>().Select(i => (ulong)i); else if (undertype == typeof(byte)) enumValuesUlongs = enumValues.Cast<byte>().Select(i => (ulong)i); else if (undertype == typeof(short)) enumValuesUlongs = enumValues.Cast<short>().Select(i => (ulong)i); else if (undertype == typeof(ushort)) enumValuesUlongs = enumValues.Cast<ushort>().Select(i => (ulong)i); else if (undertype == typeof(long)) enumValuesUlongs = enumValues.Cast<long>().Select(i => (ulong)i); else enumValuesUlongs = enumValues.Cast<ulong>(); _pairs = type.GetEnumNames().Zip(enumValuesUlongs.ToArray(), (s, v) => new KeyValuePair<string, ulong>(s, v)).ToList(); }
public ObjectTypeDescriptor(TypeSerializers typeSerializers, Type type) { _type = type; Sealed = _type.IsSealed; _name = typeSerializers.TypeToName(type); }