diff options
-rw-r--r-- | src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs b/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs index 2c4850921c..78a1ed5bb5 100644 --- a/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs +++ b/src/mscorlib/src/System/Reflection/Emit/FieldBuilder.cs @@ -178,6 +178,13 @@ namespace System.Reflection.Emit { m_typeBuilder.ThrowIfCreated(); + if (defaultValue == null && m_fieldType.IsValueType) + { + // nullable types can hold null value. + if (!(m_fieldType.IsGenericType && m_fieldType.GetGenericTypeDefinition() == typeof(Nullable<>))) + throw new ArgumentException(SR.Argument_ConstantNull); + } + TypeBuilder.SetConstantValue(m_typeBuilder.GetModuleBuilder(), GetToken().Token, m_fieldType, defaultValue); } |