public static unsafe object GetValue(MetadataImport scope, int token, RuntimeTypeHandle fieldTypeHandle, bool raw) { int num2; long num4; CorElementType end = CorElementType.End; long num = 0L; string str = scope.GetDefaultValue(token, out num, out num2, out end); RuntimeType runtimeType = fieldTypeHandle.GetRuntimeType(); if (!runtimeType.IsEnum || raw) { if (runtimeType == typeof(DateTime)) { num4 = 0L; switch (end) { case CorElementType.I8: num4 = num; goto Label_0129; case CorElementType.U8: num4 = num; goto Label_0129; case CorElementType.Void: return(DBNull.Value); } throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); } switch (end) { case CorElementType.Void: return(DBNull.Value); case CorElementType.Boolean: return(*(((int *)&num)) != 0); case CorElementType.Char: return((char)*(((ushort *)&num))); case CorElementType.I1: return(*(((sbyte *)&num))); case CorElementType.U1: return(*(((byte *)&num))); case CorElementType.I2: return(*(((short *)&num))); case CorElementType.U2: return(*(((ushort *)&num))); case CorElementType.I4: return(*(((int *)&num))); case CorElementType.U4: return(*(((uint *)&num))); case CorElementType.I8: return(num); case CorElementType.U8: return((ulong)num); case CorElementType.R4: return(*(((float *)&num))); case CorElementType.R8: return(*(((double *)&num))); case CorElementType.String: if (str == null) { return(string.Empty); } return(str); case CorElementType.Class: return(null); } throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); } long num3 = 0L; switch (end) { case CorElementType.Void: return(DBNull.Value); case CorElementType.Char: num3 = *((ushort *)&num); break; case CorElementType.I1: num3 = *((sbyte *)&num); break; case CorElementType.U1: num3 = *((byte *)&num); break; case CorElementType.I2: num3 = *((short *)&num); break; case CorElementType.U2: num3 = *((ushort *)&num); break; case CorElementType.I4: num3 = *((int *)&num); break; case CorElementType.U4: num3 = *((uint *)&num); break; case CorElementType.I8: num3 = num; break; case CorElementType.U8: num3 = num; break; default: throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); } return(RuntimeType.CreateEnum(runtimeType, num3)); Label_0129: return(new DateTime(num4)); }
[System.Security.SecurityCritical] // auto-generated public static unsafe Object GetValue(MetadataImport scope, int token, RuntimeTypeHandle fieldTypeHandle, bool raw) { CorElementType corElementType = 0; long buffer = 0; int length; String stringVal; stringVal = scope.GetDefaultValue(token, out buffer, out length, out corElementType); RuntimeType fieldType = fieldTypeHandle.GetRuntimeType(); if (fieldType.IsEnum && raw == false) { long defaultValue = 0; switch (corElementType) { #region Switch case CorElementType.Void: return(DBNull.Value); case CorElementType.Char: defaultValue = *(char *)&buffer; break; case CorElementType.I1: defaultValue = *(sbyte *)&buffer; break; case CorElementType.U1: defaultValue = *(byte *)&buffer; break; case CorElementType.I2: defaultValue = *(short *)&buffer; break; case CorElementType.U2: defaultValue = *(ushort *)&buffer; break; case CorElementType.I4: defaultValue = *(int *)&buffer; break; case CorElementType.U4: defaultValue = *(uint *)&buffer; break; case CorElementType.I8: defaultValue = buffer; break; case CorElementType.U8: defaultValue = buffer; break; default: throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); #endregion } return(RuntimeType.CreateEnum(fieldType, defaultValue)); } else if (fieldType == typeof(DateTime)) { long defaultValue = 0; switch (corElementType) { #region Switch case CorElementType.Void: return(DBNull.Value); case CorElementType.I8: defaultValue = buffer; break; case CorElementType.U8: defaultValue = buffer; break; default: throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); #endregion } return(new DateTime(defaultValue)); } else { switch (corElementType) { #region Switch case CorElementType.Void: return(DBNull.Value); case CorElementType.Char: return(*(char *)&buffer); case CorElementType.I1: return(*(sbyte *)&buffer); case CorElementType.U1: return(*(byte *)&buffer); case CorElementType.I2: return(*(short *)&buffer); case CorElementType.U2: return(*(ushort *)&buffer); case CorElementType.I4: return(*(int *)&buffer); case CorElementType.U4: return(*(uint *)&buffer); case CorElementType.I8: return(buffer); case CorElementType.U8: return((ulong)buffer); case CorElementType.Boolean: // The boolean value returned from the metadata engine is stored as a // BOOL, which actually maps to an int. We need to read it out as an int // to avoid problems on big-endian machines. return(*(int *)&buffer != 0); case CorElementType.R4: return(*(float *)&buffer); case CorElementType.R8: return(*(double *)&buffer); case CorElementType.String: // A string constant can be empty but never null. // A nullref constant can only be type CorElementType.Class. return(stringVal == null ? String.Empty : stringVal); case CorElementType.Class: return(null); default: throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); #endregion } } }
public static unsafe object GetValue(MetadataImport scope, int token, RuntimeTypeHandle fieldTypeHandle, bool raw) { CorElementType corElementType = 0; long buffer = 0; int length; string stringVal; stringVal = scope.GetDefaultValue(token, out buffer, out length, out corElementType); RuntimeType fieldType = fieldTypeHandle.GetRuntimeType(); if (fieldType.IsEnum && raw == false) { // NOTE: Unlike in `TypeBuilder.SetConstantValue`, if `fieldType` describes // a nullable enum type `Nullable<TEnum>`, we do not unpack it to `TEnum` to // successfully enter this `if` clause. Default values of `TEnum?`-typed // parameters have been reported as values of the underlying type, changing // this now might be a breaking change. long defaultValue = 0; switch (corElementType) { #region Switch case CorElementType.Void: return(DBNull.Value); case CorElementType.Char: defaultValue = *(char *)&buffer; break; case CorElementType.I1: defaultValue = *(sbyte *)&buffer; break; case CorElementType.U1: defaultValue = *(byte *)&buffer; break; case CorElementType.I2: defaultValue = *(short *)&buffer; break; case CorElementType.U2: defaultValue = *(ushort *)&buffer; break; case CorElementType.I4: defaultValue = *(int *)&buffer; break; case CorElementType.U4: defaultValue = *(uint *)&buffer; break; case CorElementType.I8: defaultValue = buffer; break; case CorElementType.U8: defaultValue = buffer; break; case CorElementType.Class: return(null); default: throw new FormatException(SR.Arg_BadLiteralFormat); #endregion } return(RuntimeType.CreateEnum(fieldType, defaultValue)); } else if (fieldType == typeof(DateTime)) { long defaultValue = 0; switch (corElementType) { #region Switch case CorElementType.Void: return(DBNull.Value); case CorElementType.I8: defaultValue = buffer; break; case CorElementType.U8: defaultValue = buffer; break; case CorElementType.Class: return(null); default: throw new FormatException(SR.Arg_BadLiteralFormat); #endregion } return(new DateTime(defaultValue)); } else { switch (corElementType) { #region Switch case CorElementType.Void: return(DBNull.Value); case CorElementType.Char: return(*(char *)&buffer); case CorElementType.I1: return(*(sbyte *)&buffer); case CorElementType.U1: return(*(byte *)&buffer); case CorElementType.I2: return(*(short *)&buffer); case CorElementType.U2: return(*(ushort *)&buffer); case CorElementType.I4: return(*(int *)&buffer); case CorElementType.U4: return(*(uint *)&buffer); case CorElementType.I8: return(buffer); case CorElementType.U8: return((ulong)buffer); case CorElementType.Boolean: // The boolean value returned from the metadata engine is stored as a // BOOL, which actually maps to an int. We need to read it out as an int // to avoid problems on big-endian machines. return(*(int *)&buffer != 0); case CorElementType.R4: return(*(float *)&buffer); case CorElementType.R8: return(*(double *)&buffer); case CorElementType.String: // A string constant can be empty but never null. // A nullref constant can only be type CorElementType.Class. return(stringVal == null ? string.Empty : stringVal); case CorElementType.Class: return(null); default: throw new FormatException(SR.Arg_BadLiteralFormat); #endregion } } }
public static unsafe object GetValue(MetadataImport scope, int token, RuntimeTypeHandle fieldTypeHandle, bool raw) { CorElementType corElementType = CorElementType.End; long num1 = 0; int length; string defaultValue = scope.GetDefaultValue(token, out num1, out length, out corElementType); RuntimeType runtimeType = fieldTypeHandle.GetRuntimeType(); if (runtimeType.IsEnum && !raw) { long num2; switch (corElementType) { case CorElementType.Void: return((object)DBNull.Value); case CorElementType.Char: num2 = (long)*(ushort *)&num1; break; case CorElementType.I1: num2 = (long)*(sbyte *)&num1; break; case CorElementType.U1: num2 = (long)*(byte *)&num1; break; case CorElementType.I2: num2 = (long)*(short *)&num1; break; case CorElementType.U2: num2 = (long)*(ushort *)&num1; break; case CorElementType.I4: num2 = (long)*(int *)&num1; break; case CorElementType.U4: num2 = (long)*(uint *)&num1; break; case CorElementType.I8: num2 = num1; break; case CorElementType.U8: num2 = num1; break; default: throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); } return(RuntimeType.CreateEnum(runtimeType, num2)); } if ((Type)runtimeType == typeof(DateTime)) { if (corElementType == CorElementType.Void) { return((object)DBNull.Value); } long ticks; if (corElementType != CorElementType.I8) { if (corElementType != CorElementType.U8) { throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); } ticks = num1; } else { ticks = num1; } return((object)new DateTime(ticks)); } switch (corElementType) { case CorElementType.Void: return((object)DBNull.Value); case CorElementType.Boolean: return((object)((uint)*(int *)&num1 > 0U)); case CorElementType.Char: return((object)(char)*(ushort *)&num1); case CorElementType.I1: return((object)*(sbyte *)&num1); case CorElementType.U1: return((object)*(byte *)&num1); case CorElementType.I2: return((object)*(short *)&num1); case CorElementType.U2: return((object)*(ushort *)&num1); case CorElementType.I4: return((object)*(int *)&num1); case CorElementType.U4: return((object)*(uint *)&num1); case CorElementType.I8: return((object)num1); case CorElementType.U8: return((object)(ulong)num1); case CorElementType.R4: return((object)*(float *)&num1); case CorElementType.R8: return((object)*(double *)&num1); case CorElementType.String: return((object)defaultValue ?? (object)string.Empty); case CorElementType.Class: return((object)null); default: throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); } }
public static unsafe object?GetValue(MetadataImport scope, int token, RuntimeTypeHandle fieldTypeHandle, bool raw) { CorElementType corElementType = 0; long buffer = 0; int length; string? stringVal = scope.GetDefaultValue(token, out buffer, out length, out corElementType); RuntimeType fieldType = fieldTypeHandle.GetRuntimeType(); if (fieldType.IsEnum && !raw) { // NOTE: Unlike in `TypeBuilder.SetConstantValue`, if `fieldType` describes // a nullable enum type `Nullable<TEnum>`, we do not unpack it to `TEnum` to // successfully enter this `if` clause. Default values of `TEnum?`-typed // parameters have been reported as values of the underlying type, changing // this now might be a breaking change. long defaultValue = 0; switch (corElementType) { #region Switch case CorElementType.ELEMENT_TYPE_VOID: return(DBNull.Value); case CorElementType.ELEMENT_TYPE_CHAR: defaultValue = *(char *)&buffer; break; case CorElementType.ELEMENT_TYPE_I1: defaultValue = *(sbyte *)&buffer; break; case CorElementType.ELEMENT_TYPE_U1: defaultValue = *(byte *)&buffer; break; case CorElementType.ELEMENT_TYPE_I2: defaultValue = *(short *)&buffer; break; case CorElementType.ELEMENT_TYPE_U2: defaultValue = *(ushort *)&buffer; break; case CorElementType.ELEMENT_TYPE_I4: defaultValue = *(int *)&buffer; break; case CorElementType.ELEMENT_TYPE_U4: defaultValue = *(uint *)&buffer; break; case CorElementType.ELEMENT_TYPE_I8: defaultValue = buffer; break; case CorElementType.ELEMENT_TYPE_U8: defaultValue = buffer; break; case CorElementType.ELEMENT_TYPE_CLASS: return(null); default: throw new FormatException(SR.Arg_BadLiteralFormat); #endregion } return(RuntimeType.CreateEnum(fieldType, defaultValue)); } else if (fieldType == typeof(DateTime)) { long defaultValue = 0; switch (corElementType) { #region Switch case CorElementType.ELEMENT_TYPE_VOID: return(DBNull.Value); case CorElementType.ELEMENT_TYPE_I8: defaultValue = buffer; break; case CorElementType.ELEMENT_TYPE_U8: defaultValue = buffer; break; case CorElementType.ELEMENT_TYPE_CLASS: return(null); default: throw new FormatException(SR.Arg_BadLiteralFormat); #endregion } return(new DateTime(defaultValue)); } else { return(corElementType switch { CorElementType.ELEMENT_TYPE_VOID => DBNull.Value, CorElementType.ELEMENT_TYPE_CHAR => *(char *)&buffer, CorElementType.ELEMENT_TYPE_I1 => *(sbyte *)&buffer, CorElementType.ELEMENT_TYPE_U1 => *(byte *)&buffer, CorElementType.ELEMENT_TYPE_I2 => *(short *)&buffer, CorElementType.ELEMENT_TYPE_U2 => *(ushort *)&buffer, CorElementType.ELEMENT_TYPE_I4 => *(int *)&buffer, CorElementType.ELEMENT_TYPE_U4 => *(uint *)&buffer, CorElementType.ELEMENT_TYPE_I8 => buffer, CorElementType.ELEMENT_TYPE_U8 => (ulong)buffer, CorElementType.ELEMENT_TYPE_BOOLEAN => (*(int *)&buffer != 0), CorElementType.ELEMENT_TYPE_R4 => *(float *)&buffer, CorElementType.ELEMENT_TYPE_R8 => *(double *)&buffer, CorElementType.ELEMENT_TYPE_STRING => stringVal ?? string.Empty, CorElementType.ELEMENT_TYPE_CLASS => null, _ => throw new FormatException(SR.Arg_BadLiteralFormat), });
public unsafe static object GetValue(MetadataImport scope, int token, RuntimeTypeHandle fieldTypeHandle, bool raw) { CorElementType corElementType = CorElementType.End; long num = 0L; int num2; string defaultValue = scope.GetDefaultValue(token, out num, out num2, out corElementType); RuntimeType runtimeType = fieldTypeHandle.GetRuntimeType(); if (runtimeType.IsEnum && !raw) { long value; switch (corElementType) { case CorElementType.Void: return(DBNull.Value); case CorElementType.Char: value = (long)((ulong)(*(ushort *)(&num))); goto IL_C8; case CorElementType.I1: value = (long)(*(sbyte *)(&num)); goto IL_C8; case CorElementType.U1: value = (long)((ulong)(*(byte *)(&num))); goto IL_C8; case CorElementType.I2: value = (long)(*(short *)(&num)); goto IL_C8; case CorElementType.U2: value = (long)((ulong)(*(ushort *)(&num))); goto IL_C8; case CorElementType.I4: value = (long)(*(int *)(&num)); goto IL_C8; case CorElementType.U4: value = (long)((ulong)(*(uint *)(&num))); goto IL_C8; case CorElementType.I8: value = num; goto IL_C8; case CorElementType.U8: value = num; goto IL_C8; } throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); IL_C8: return(RuntimeType.CreateEnum(runtimeType, value)); } if (!(runtimeType == typeof(DateTime))) { switch (corElementType) { case CorElementType.Void: return(DBNull.Value); case CorElementType.Boolean: return(*(int *)(&num) != 0); case CorElementType.Char: return((char)(*(ushort *)(&num))); case CorElementType.I1: return(*(sbyte *)(&num)); case CorElementType.U1: return(*(byte *)(&num)); case CorElementType.I2: return(*(short *)(&num)); case CorElementType.U2: return(*(ushort *)(&num)); case CorElementType.I4: return(*(int *)(&num)); case CorElementType.U4: return(*(uint *)(&num)); case CorElementType.I8: return(num); case CorElementType.U8: return((ulong)num); case CorElementType.R4: return(*(float *)(&num)); case CorElementType.R8: return(*(double *)(&num)); case CorElementType.String: if (defaultValue != null) { return(defaultValue); } return(string.Empty); case CorElementType.Class: return(null); } throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); } if (corElementType != CorElementType.Void) { long ticks; if (corElementType != CorElementType.I8) { if (corElementType != CorElementType.U8) { throw new FormatException(Environment.GetResourceString("Arg_BadLiteralFormat")); } ticks = num; } else { ticks = num; } return(new DateTime(ticks)); } return(DBNull.Value); }