protected override void EmitGetImpl(CodeEmitter ilgen) { // Reading a field should trigger the cctor, but since we're inlining the value // we have to trigger it explicitly DeclaringType.EmitRunClassConstructor(ilgen); // NOTE even though you're not supposed to access a constant static final (the compiler is supposed // to inline them), we have to support it (because it does happen, e.g. if the field becomes final // after the referencing class was compiled, or when we're accessing an unsigned primitive .NET field) object v = GetConstantValue(); if(v == null) { ilgen.Emit(OpCodes.Ldnull); } else if(constant is int || constant is short || constant is ushort || constant is byte || constant is sbyte || constant is char || constant is bool) { ilgen.EmitLdc_I4(((IConvertible)constant).ToInt32(null)); } else if(constant is string) { ilgen.Emit(OpCodes.Ldstr, (string)constant); } else if(constant is float) { ilgen.EmitLdc_R4((float)constant); } else if(constant is double) { ilgen.EmitLdc_R8((double)constant); } else if(constant is long) { ilgen.EmitLdc_I8((long)constant); } else if(constant is uint) { ilgen.EmitLdc_I4(unchecked((int)((IConvertible)constant).ToUInt32(null))); } else if(constant is ulong) { ilgen.EmitLdc_I8(unchecked((long)(ulong)constant)); } else { throw new InvalidOperationException(constant.GetType().FullName); } }