public static TraceLoggingTypeInfo CreateDefaultTypeInfo( Type dataType, List <Type> recursionCheck) { TraceLoggingTypeInfo result; if (recursionCheck.Contains(dataType)) { #if PROJECTN throw new NotSupportedException(SR.GetResourceString("EventSource_RecursiveTypeDefinition", null)); #else throw new NotSupportedException(Environment.GetResourceString("EventSource_RecursiveTypeDefinition")); #endif } recursionCheck.Add(dataType); var eventAttrib = Statics.GetCustomAttribute <EventDataAttribute>(dataType); if (eventAttrib != null || Statics.GetCustomAttribute <CompilerGeneratedAttribute>(dataType) != null || IsGenericMatch(dataType, typeof(KeyValuePair <,>))) { var analysis = new TypeAnalysis(dataType, eventAttrib, recursionCheck); result = new InvokeTypeInfo(dataType, analysis); } else if (dataType.IsArray) { var elementType = dataType.GetElementType(); if (elementType == typeof(Boolean)) { result = ScalarArrayTypeInfo.Boolean(); } else if (elementType == typeof(Byte)) { result = ScalarArrayTypeInfo.Byte(); } else if (elementType == typeof(SByte)) { result = ScalarArrayTypeInfo.SByte(); } else if (elementType == typeof(Int16)) { result = ScalarArrayTypeInfo.Int16(); } else if (elementType == typeof(UInt16)) { result = ScalarArrayTypeInfo.UInt16(); } else if (elementType == typeof(Int32)) { result = ScalarArrayTypeInfo.Int32(); } else if (elementType == typeof(UInt32)) { result = ScalarArrayTypeInfo.UInt32(); } else if (elementType == typeof(Int64)) { result = ScalarArrayTypeInfo.Int64(); } else if (elementType == typeof(UInt64)) { result = ScalarArrayTypeInfo.UInt64(); } else if (elementType == typeof(Char)) { result = ScalarArrayTypeInfo.Char(); } else if (elementType == typeof(Double)) { result = ScalarArrayTypeInfo.Double(); } else if (elementType == typeof(Single)) { result = ScalarArrayTypeInfo.Single(); } else if (elementType == typeof(IntPtr)) { result = ScalarArrayTypeInfo.IntPtr(); } else if (elementType == typeof(UIntPtr)) { result = ScalarArrayTypeInfo.UIntPtr(); } else if (elementType == typeof(Guid)) { result = ScalarArrayTypeInfo.Guid(); } else { result = new ArrayTypeInfo(dataType, TraceLoggingTypeInfo.GetInstance(elementType, recursionCheck)); } } else { if (Statics.IsEnum(dataType)) { dataType = Enum.GetUnderlyingType(dataType); } if (dataType == typeof(String)) { result = new StringTypeInfo(); } else if (dataType == typeof(Boolean)) { result = ScalarTypeInfo.Boolean(); } else if (dataType == typeof(Byte)) { result = ScalarTypeInfo.Byte(); } else if (dataType == typeof(SByte)) { result = ScalarTypeInfo.SByte(); } else if (dataType == typeof(Int16)) { result = ScalarTypeInfo.Int16(); } else if (dataType == typeof(UInt16)) { result = ScalarTypeInfo.UInt16(); } else if (dataType == typeof(Int32)) { result = ScalarTypeInfo.Int32(); } else if (dataType == typeof(UInt32)) { result = ScalarTypeInfo.UInt32(); } else if (dataType == typeof(Int64)) { result = ScalarTypeInfo.Int64(); } else if (dataType == typeof(UInt64)) { result = ScalarTypeInfo.UInt64(); } else if (dataType == typeof(Char)) { result = ScalarTypeInfo.Char(); } else if (dataType == typeof(Double)) { result = ScalarTypeInfo.Double(); } else if (dataType == typeof(Single)) { result = ScalarTypeInfo.Single(); } else if (dataType == typeof(DateTime)) { result = new DateTimeTypeInfo(); } else if (dataType == typeof(Decimal)) { result = new DecimalTypeInfo(); } else if (dataType == typeof(IntPtr)) { result = ScalarTypeInfo.IntPtr(); } else if (dataType == typeof(UIntPtr)) { result = ScalarTypeInfo.UIntPtr(); } else if (dataType == typeof(Guid)) { result = ScalarTypeInfo.Guid(); } else if (dataType == typeof(TimeSpan)) { result = new TimeSpanTypeInfo(); } else if (dataType == typeof(DateTimeOffset)) { result = new DateTimeOffsetTypeInfo(); } else if (dataType == typeof(EmptyStruct)) { result = new NullTypeInfo(); } else if (IsGenericMatch(dataType, typeof(Nullable <>))) { result = new NullableTypeInfo(dataType, recursionCheck); } else { var elementType = FindEnumerableElementType(dataType); if (elementType != null) { result = new EnumerableTypeInfo(dataType, TraceLoggingTypeInfo.GetInstance(elementType, recursionCheck)); } else { #if PROJECTN throw new ArgumentException(SR.Format("EventSource_NonCompliantTypeError", dataType.Name)); #else throw new ArgumentException(Environment.GetResourceString("EventSource_NonCompliantTypeError", dataType.Name)); #endif } } } return(result); }
public static TraceLoggingTypeInfo <DataType> CreateDefaultTypeInfo <DataType>( List <Type> recursionCheck) { TraceLoggingTypeInfo result; var dataType = typeof(DataType); if (recursionCheck.Contains(dataType)) { throw new NotSupportedException(Environment.GetResourceString("EventSource_RecursiveTypeDefinition")); } recursionCheck.Add(dataType); var eventAttrib = Statics.GetCustomAttribute <EventDataAttribute>(dataType); if (eventAttrib != null || Statics.GetCustomAttribute <CompilerGeneratedAttribute>(dataType) != null) { var analysis = new TypeAnalysis(dataType, eventAttrib, recursionCheck); result = new InvokeTypeInfo <DataType>(analysis); } else if (dataType.IsArray) { var elementType = dataType.GetElementType(); if (elementType == typeof(Boolean)) { result = new BooleanArrayTypeInfo(); } else if (elementType == typeof(Byte)) { result = new ByteArrayTypeInfo(); } else if (elementType == typeof(SByte)) { result = new SByteArrayTypeInfo(); } else if (elementType == typeof(Int16)) { result = new Int16ArrayTypeInfo(); } else if (elementType == typeof(UInt16)) { result = new UInt16ArrayTypeInfo(); } else if (elementType == typeof(Int32)) { result = new Int32ArrayTypeInfo(); } else if (elementType == typeof(UInt32)) { result = new UInt32ArrayTypeInfo(); } else if (elementType == typeof(Int64)) { result = new Int64ArrayTypeInfo(); } else if (elementType == typeof(UInt64)) { result = new UInt64ArrayTypeInfo(); } else if (elementType == typeof(Char)) { result = new CharArrayTypeInfo(); } else if (elementType == typeof(Double)) { result = new DoubleArrayTypeInfo(); } else if (elementType == typeof(Single)) { result = new SingleArrayTypeInfo(); } else if (elementType == typeof(IntPtr)) { result = new IntPtrArrayTypeInfo(); } else if (elementType == typeof(UIntPtr)) { result = new UIntPtrArrayTypeInfo(); } else if (elementType == typeof(Guid)) { result = new GuidArrayTypeInfo(); } else { result = (TraceLoggingTypeInfo <DataType>)CreateInstance( typeof(ArrayTypeInfo <>).MakeGenericType(elementType), GetTypeInfoInstance(elementType, recursionCheck)); } } else if (Statics.IsEnum(dataType)) { var underlyingType = Enum.GetUnderlyingType(dataType); if (underlyingType == typeof(Int32)) { result = new EnumInt32TypeInfo <DataType>(); } else if (underlyingType == typeof(UInt32)) { result = new EnumUInt32TypeInfo <DataType>(); } else if (underlyingType == typeof(Byte)) { result = new EnumByteTypeInfo <DataType>(); } else if (underlyingType == typeof(SByte)) { result = new EnumSByteTypeInfo <DataType>(); } else if (underlyingType == typeof(Int16)) { result = new EnumInt16TypeInfo <DataType>(); } else if (underlyingType == typeof(UInt16)) { result = new EnumUInt16TypeInfo <DataType>(); } else if (underlyingType == typeof(Int64)) { result = new EnumInt64TypeInfo <DataType>(); } else if (underlyingType == typeof(UInt64)) { result = new EnumUInt64TypeInfo <DataType>(); } else { // Unexpected throw new NotSupportedException(Environment.GetResourceString("EventSource_NotSupportedEnumType", dataType.Name, underlyingType.Name)); } } else if (dataType == typeof(String)) { result = new StringTypeInfo(); } else if (dataType == typeof(Boolean)) { result = new BooleanTypeInfo(); } else if (dataType == typeof(Byte)) { result = new ByteTypeInfo(); } else if (dataType == typeof(SByte)) { result = new SByteTypeInfo(); } else if (dataType == typeof(Int16)) { result = new Int16TypeInfo(); } else if (dataType == typeof(UInt16)) { result = new UInt16TypeInfo(); } else if (dataType == typeof(Int32)) { result = new Int32TypeInfo(); } else if (dataType == typeof(UInt32)) { result = new UInt32TypeInfo(); } else if (dataType == typeof(Int64)) { result = new Int64TypeInfo(); } else if (dataType == typeof(UInt64)) { result = new UInt64TypeInfo(); } else if (dataType == typeof(Char)) { result = new CharTypeInfo(); } else if (dataType == typeof(Double)) { result = new DoubleTypeInfo(); } else if (dataType == typeof(Single)) { result = new SingleTypeInfo(); } else if (dataType == typeof(DateTime)) { result = new DateTimeTypeInfo(); } else if (dataType == typeof(Decimal)) { result = new DecimalTypeInfo(); } else if (dataType == typeof(IntPtr)) { result = new IntPtrTypeInfo(); } else if (dataType == typeof(UIntPtr)) { result = new UIntPtrTypeInfo(); } else if (dataType == typeof(Guid)) { result = new GuidTypeInfo(); } else if (dataType == typeof(TimeSpan)) { result = new TimeSpanTypeInfo(); } else if (dataType == typeof(DateTimeOffset)) { result = new DateTimeOffsetTypeInfo(); } else if (dataType == typeof(EmptyStruct)) { result = new NullTypeInfo <EmptyStruct>(); } else if (IsGenericMatch(dataType, typeof(KeyValuePair <,>))) { var args = GetGenericArguments(dataType); result = (TraceLoggingTypeInfo <DataType>)CreateInstance( typeof(KeyValuePairTypeInfo <,>).MakeGenericType(args[0], args[1]), recursionCheck); } else if (IsGenericMatch(dataType, typeof(Nullable <>))) { var args = GetGenericArguments(dataType); result = (TraceLoggingTypeInfo <DataType>)CreateInstance( typeof(NullableTypeInfo <>).MakeGenericType(args[0]), recursionCheck); } else { var elementType = FindEnumerableElementType(dataType); if (elementType != null) { result = (TraceLoggingTypeInfo <DataType>)CreateInstance( typeof(EnumerableTypeInfo <,>).MakeGenericType(dataType, elementType), GetTypeInfoInstance(elementType, recursionCheck)); } else { throw new ArgumentException(Environment.GetResourceString("EventSource_NonCompliantTypeError", dataType.Name)); } } return((TraceLoggingTypeInfo <DataType>)result); }