internal object GetValue(bool raw) { object obj2 = MdConstant.GetValue(this.Module.MetadataImport, this.m_tkField, this.FieldType.GetTypeHandleInternal(), raw); if (obj2 == DBNull.Value) { throw new NotSupportedException(Environment.GetResourceString("Arg_EnumLitValueNotFound")); } return(obj2); }
internal object GetConstantValue(bool raw) { object obj2 = MdConstant.GetValue(this.Module.MetadataImport, this.m_token, this.PropertyType.GetTypeHandleInternal(), raw); if (obj2 == DBNull.Value) { throw new InvalidOperationException(Environment.GetResourceString("Arg_EnumLitValueNotFound")); } return(obj2); }
internal object GetConstantValue(bool raw) { object obj = MdConstant.GetValue(this.GetRuntimeModule().MetadataImport, this.m_token, this.PropertyType.GetTypeHandleInternal(), raw); DBNull dbNull = DBNull.Value; if (obj != dbNull) { return(obj); } throw new InvalidOperationException(Environment.GetResourceString("Arg_EnumLitValueNotFound")); }
private object GetValue(bool raw) { object obj = MdConstant.GetValue(this.GetRuntimeModule().MetadataImport, this.m_tkField, this.FieldType.GetTypeHandleInternal(), raw); DBNull dbNull = DBNull.Value; if (obj != dbNull) { return(obj); } throw new NotSupportedException(Environment.GetResourceString("Arg_EnumLitValueNotFound")); }
internal object GetConstantValue(bool raw) { Object defaultValue = MdConstant.GetValue(GetRuntimeModule().MetadataImport, m_token, PropertyType.GetTypeHandleInternal(), raw); if (defaultValue == DBNull.Value) { // Arg_EnumLitValueNotFound -> "Literal value was not found." throw new InvalidOperationException(Environment.GetResourceString("Arg_EnumLitValueNotFound")); } return(defaultValue); }
internal object GetConstantValue(bool raw) { object?defaultValue = MdConstant.GetValue(GetRuntimeModule().MetadataImport, m_token, PropertyType.TypeHandle, raw); if (defaultValue == DBNull.Value) { // Arg_EnumLitValueNotFound -> "Literal value was not found." throw new InvalidOperationException(SR.Arg_EnumLitValueNotFound); } return(defaultValue !); }
[System.Security.SecuritySafeCritical] // auto-generated private unsafe Object GetValue(bool raw) { // Cannot cache these because they could be user defined non-agile enumerations Object value = MdConstant.GetValue(GetRuntimeModule().MetadataImport, m_tkField, FieldType.GetTypeHandleInternal(), raw); if (value == DBNull.Value) { throw new NotSupportedException(Environment.GetResourceString("Arg_EnumLitValueNotFound")); } return(value); }
private object?GetValue(bool raw) { // Cannot cache these because they could be user defined non-agile enumerations object?value = MdConstant.GetValue(GetRuntimeModule().MetadataImport, m_tkField, FieldType.GetTypeHandleInternal(), raw); if (value == DBNull.Value) { throw new NotSupportedException(SR.Arg_EnumLitValueNotFound); } return(value); }
internal object GetDefaultValue(bool raw) { object missing = null; if (!this.m_noDefaultValue) { if (this.ParameterType == typeof(DateTime)) { if (raw) { CustomAttributeTypedArgument argument = CustomAttributeData.Filter(CustomAttributeData.GetCustomAttributes(this), typeof(DateTimeConstantAttribute), 0); if (argument.ArgumentType != null) { return(new DateTime((long)argument.Value)); } } else { object[] customAttributes = this.GetCustomAttributes(typeof(DateTimeConstantAttribute), false); if ((customAttributes != null) && (customAttributes.Length != 0)) { return(((DateTimeConstantAttribute)customAttributes[0]).Value); } } } if (!System.Reflection.MetadataToken.IsNullToken(this.m_tkParamDef)) { missing = MdConstant.GetValue(this.m_scope, this.m_tkParamDef, this.ParameterType.GetTypeHandleInternal(), raw); } if (missing == DBNull.Value) { if (raw) { IList <CustomAttributeData> attrs = CustomAttributeData.GetCustomAttributes(this); CustomAttributeTypedArgument argument2 = CustomAttributeData.Filter(attrs, s_CustomConstantAttributeType, "Value"); if (argument2.ArgumentType == null) { argument2 = CustomAttributeData.Filter(attrs, s_DecimalConstantAttributeType, "Value"); if (argument2.ArgumentType == null) { for (int i = 0; i < attrs.Count; i++) { if (attrs[i].Constructor.DeclaringType == s_DecimalConstantAttributeType) { ParameterInfo[] parameters = attrs[i].Constructor.GetParameters(); if (parameters.Length != 0) { if (parameters[2].ParameterType == typeof(uint)) { IList <CustomAttributeTypedArgument> constructorArguments = attrs[i].ConstructorArguments; CustomAttributeTypedArgument argument3 = constructorArguments[4]; int lo = (int)((uint)argument3.Value); CustomAttributeTypedArgument argument4 = constructorArguments[3]; int mid = (int)((uint)argument4.Value); CustomAttributeTypedArgument argument5 = constructorArguments[2]; int hi = (int)((uint)argument5.Value); CustomAttributeTypedArgument argument6 = constructorArguments[1]; byte num5 = (byte)argument6.Value; CustomAttributeTypedArgument argument7 = constructorArguments[0]; byte scale = (byte)argument7.Value; argument2 = new CustomAttributeTypedArgument(new decimal(lo, mid, hi, num5 != 0, scale)); } else { IList <CustomAttributeTypedArgument> list3 = attrs[i].ConstructorArguments; CustomAttributeTypedArgument argument8 = list3[4]; int num7 = (int)argument8.Value; CustomAttributeTypedArgument argument9 = list3[3]; int num8 = (int)argument9.Value; CustomAttributeTypedArgument argument10 = list3[2]; int num9 = (int)argument10.Value; CustomAttributeTypedArgument argument11 = list3[1]; byte num10 = (byte)argument11.Value; CustomAttributeTypedArgument argument12 = list3[0]; byte num11 = (byte)argument12.Value; argument2 = new CustomAttributeTypedArgument(new decimal(num7, num8, num9, num10 != 0, num11)); } } } } } } if (argument2.ArgumentType != null) { missing = argument2.Value; } } else { object[] objArray2 = this.GetCustomAttributes(s_CustomConstantAttributeType, false); if (objArray2.Length != 0) { missing = ((CustomConstantAttribute)objArray2[0]).Value; } else { objArray2 = this.GetCustomAttributes(s_DecimalConstantAttributeType, false); if (objArray2.Length != 0) { missing = ((DecimalConstantAttribute)objArray2[0]).Value; } } } } if ((missing == DBNull.Value) && this.IsOptional) { missing = Type.Missing; } } return(missing); }
private Object GetDefaultValueInternal(bool raw) { Contract.Assert(!m_noMetadata); if (m_noDefaultValue) { return(DBNull.Value); } object defaultValue = null; // Why check the parameter type only for DateTime and only for the ctor arguments? // No check on the parameter type is done for named args and for Decimal. // We should move this after MdToken.IsNullToken(m_tkParamDef) and combine it // with the other custom attribute logic. But will that be a breaking change? // For a DateTime parameter on which both an md constant and a ca constant are set, // which one should win? if (ParameterType == typeof(DateTime)) { if (raw) { CustomAttributeTypedArgument value = CustomAttributeData.Filter( CustomAttributeData.GetCustomAttributes(this), typeof(DateTimeConstantAttribute), 0); if (value.ArgumentType != null) { return(new DateTime((long)value.Value)); } } else { object[] dt = GetCustomAttributes(typeof(DateTimeConstantAttribute), false); if (dt != null && dt.Length != 0) { return(((DateTimeConstantAttribute)dt[0]).Value); } } } #region Look for a default value in metadata if (!MdToken.IsNullToken(m_tkParamDef)) { // This will return DBNull.Value if no constant value is defined on m_tkParamDef in the metadata. defaultValue = MdConstant.GetValue(m_scope, m_tkParamDef, ParameterType.GetTypeHandleInternal(), raw); } #endregion if (defaultValue == DBNull.Value) { #region Look for a default value in the custom attributes if (raw) { foreach (CustomAttributeData attr in CustomAttributeData.GetCustomAttributes(this)) { Type attrType = attr.Constructor.DeclaringType; if (attrType == typeof(DateTimeConstantAttribute)) { defaultValue = DateTimeConstantAttribute.GetRawDateTimeConstant(attr); } else if (attrType == typeof(DecimalConstantAttribute)) { defaultValue = DecimalConstantAttribute.GetRawDecimalConstant(attr); } else if (attrType.IsSubclassOf(s_CustomConstantAttributeType)) { defaultValue = CustomConstantAttribute.GetRawConstant(attr); } } } else { Object[] CustomAttrs = GetCustomAttributes(s_CustomConstantAttributeType, false); if (CustomAttrs.Length != 0) { defaultValue = ((CustomConstantAttribute)CustomAttrs[0]).Value; } else { CustomAttrs = GetCustomAttributes(s_DecimalConstantAttributeType, false); if (CustomAttrs.Length != 0) { defaultValue = ((DecimalConstantAttribute)CustomAttrs[0]).Value; } } } #endregion } if (defaultValue == DBNull.Value) { m_noDefaultValue = true; } return(defaultValue); }
private object GetDefaultValueInternal(bool raw) { if (this.m_noDefaultValue) { return(DBNull.Value); } object obj = null; if (this.ParameterType == typeof(DateTime)) { if (raw) { CustomAttributeTypedArgument customAttributeTypedArgument = CustomAttributeData.Filter(CustomAttributeData.GetCustomAttributes(this), typeof(DateTimeConstantAttribute), 0); if (customAttributeTypedArgument.ArgumentType != null) { return(new DateTime((long)customAttributeTypedArgument.Value)); } } else { object[] customAttributes = this.GetCustomAttributes(typeof(DateTimeConstantAttribute), false); if (customAttributes != null && customAttributes.Length != 0) { return(((DateTimeConstantAttribute)customAttributes[0]).Value); } } } if (!System.Reflection.MetadataToken.IsNullToken(this.m_tkParamDef)) { obj = MdConstant.GetValue(this.m_scope, this.m_tkParamDef, this.ParameterType.GetTypeHandleInternal(), raw); } if (obj == DBNull.Value) { if (raw) { using (IEnumerator <CustomAttributeData> enumerator = CustomAttributeData.GetCustomAttributes(this).GetEnumerator()) { while (enumerator.MoveNext()) { CustomAttributeData customAttributeData = enumerator.Current; Type declaringType = customAttributeData.Constructor.DeclaringType; if (declaringType == typeof(DateTimeConstantAttribute)) { obj = DateTimeConstantAttribute.GetRawDateTimeConstant(customAttributeData); } else if (declaringType == typeof(DecimalConstantAttribute)) { obj = DecimalConstantAttribute.GetRawDecimalConstant(customAttributeData); } else if (declaringType.IsSubclassOf(RuntimeParameterInfo.s_CustomConstantAttributeType)) { obj = CustomConstantAttribute.GetRawConstant(customAttributeData); } } goto IL_1A7; } } object[] customAttributes2 = this.GetCustomAttributes(RuntimeParameterInfo.s_CustomConstantAttributeType, false); if (customAttributes2.Length != 0) { obj = ((CustomConstantAttribute)customAttributes2[0]).Value; } else { customAttributes2 = this.GetCustomAttributes(RuntimeParameterInfo.s_DecimalConstantAttributeType, false); if (customAttributes2.Length != 0) { obj = ((DecimalConstantAttribute)customAttributes2[0]).Value; } } } IL_1A7: if (obj == DBNull.Value) { this.m_noDefaultValue = true; } return(obj); }
private object GetDefaultValueInternal(bool raw) { if (this.m_noDefaultValue) { return((object)DBNull.Value); } object obj = (object)null; if (this.ParameterType == typeof(DateTime)) { if (raw) { CustomAttributeTypedArgument attributeTypedArgument = CustomAttributeData.Filter(CustomAttributeData.GetCustomAttributes((ParameterInfo)this), typeof(DateTimeConstantAttribute), 0); if (attributeTypedArgument.ArgumentType != (Type)null) { return((object)new DateTime((long)attributeTypedArgument.Value)); } } else { object[] customAttributes = this.GetCustomAttributes(typeof(DateTimeConstantAttribute), false); if (customAttributes != null && customAttributes.Length != 0) { return(((CustomConstantAttribute)customAttributes[0]).Value); } } } if (!System.Reflection.MetadataToken.IsNullToken(this.m_tkParamDef)) { obj = MdConstant.GetValue(this.m_scope, this.m_tkParamDef, this.ParameterType.GetTypeHandleInternal(), raw); } if (obj == DBNull.Value) { if (raw) { foreach (CustomAttributeData customAttribute in (IEnumerable <CustomAttributeData>)CustomAttributeData.GetCustomAttributes((ParameterInfo)this)) { Type declaringType = customAttribute.Constructor.DeclaringType; if (declaringType == typeof(DateTimeConstantAttribute)) { obj = (object)DateTimeConstantAttribute.GetRawDateTimeConstant(customAttribute); } else if (declaringType == typeof(DecimalConstantAttribute)) { obj = (object)DecimalConstantAttribute.GetRawDecimalConstant(customAttribute); } else if (declaringType.IsSubclassOf(RuntimeParameterInfo.s_CustomConstantAttributeType)) { obj = CustomConstantAttribute.GetRawConstant(customAttribute); } } } else { object[] customAttributes1 = this.GetCustomAttributes(RuntimeParameterInfo.s_CustomConstantAttributeType, false); if (customAttributes1.Length != 0) { obj = ((CustomConstantAttribute)customAttributes1[0]).Value; } else { object[] customAttributes2 = this.GetCustomAttributes(RuntimeParameterInfo.s_DecimalConstantAttributeType, false); if (customAttributes2.Length != 0) { obj = (object)((DecimalConstantAttribute)customAttributes2[0]).Value; } } } } if (obj == DBNull.Value) { this.m_noDefaultValue = true; } return(obj); }