68 base(declaringType, fieldType, name, sig,
modifiers, field, flags)
70 if (IsStatic ==
false)
73 Debug.Assert(constant ==
null || constant.GetType().IsPrimitive || constant is
string);
74 this.constant = constant;
77 internal object GetConstantValue()
81 var field = GetField();
82 constant = field.GetRawConstantValue();
90 protected override void EmitGetImpl(
CodeEmitter ilgen)
94 DeclaringType.EmitRunClassConstructor(ilgen);
99 var v = GetConstantValue();
102 ilgen.Emit(OpCodes.Ldnull);
104 else if (constant is
int || constant is
short || constant is ushort || constant is
byte || constant is sbyte || constant is
char || constant is
bool)
106 ilgen.EmitLdc_I4(((IConvertible)constant).ToInt32(
null));
108 else if (constant is
string)
110 ilgen.Emit(OpCodes.Ldstr, (
string)constant);
112 else if (constant is
float)
114 ilgen.EmitLdc_R4((
float)constant);
116 else if (constant is
double)
118 ilgen.EmitLdc_R8((
double)constant);
120 else if (constant is
long)
122 ilgen.EmitLdc_I8((
long)constant);
124 else if (constant is uint)
126 ilgen.EmitLdc_I4(unchecked((
int)((IConvertible)constant).ToUInt32(
null)));
128 else if (constant is ulong)
130 ilgen.EmitLdc_I8(unchecked((
long)(ulong)constant));
134 throw new InvalidOperationException(constant.GetType().FullName);
138 protected override void EmitSetImpl(
CodeEmitter ilgen)
142 ilgen.Emit(OpCodes.Pop);
147#if !EXPORTER && !IMPORTER && !FIRST_PASS
149 internal override object GetValue(
object obj)
151 var field = GetField();
152 return FieldTypeWrapper.IsPrimitive || field ==
null ? GetConstantValue() : field.GetValue(
null);
155 internal override void SetValue(
object obj,
object value)