static Value GetLiteralValue(Thread evalThread, IField fieldInfo) { var constValue = fieldInfo.ConstantValue; if (constValue == null || constValue is string) { return(Eval.CreateValue(evalThread, constValue)); } else if (fieldInfo.Type.IsPrimitiveType()) { Value val = Eval.NewObjectNoConstructor(evalThread, fieldInfo.Type); val.CorGenericValue.SetValue(fieldInfo.Type.GetDefinition().KnownTypeCode, constValue); return(val); } else if (fieldInfo.Type.Kind == TypeKind.Enum) { Value val = Eval.NewObjectNoConstructor(evalThread, fieldInfo.Type); Value backingField = val.GetFieldValue("value__"); var enumType = fieldInfo.Type.GetDefinition().EnumUnderlyingType.GetDefinition().KnownTypeCode; backingField.CorGenericValue.SetValue(enumType, constValue); return(val); } else { throw new NotSupportedException(); } }
/// <summary> Get the value of given field. </summary> public Value GetFieldValue(Thread evalThread, IField fieldInfo) { return(Value.GetFieldValue(evalThread, this, fieldInfo)); }
/// <summary> Get the value of given field. </summary> public Value GetFieldValue(FieldInfo fieldInfo) { return(Value.GetFieldValue(this, fieldInfo)); }