static Value GetLiteralValue(DebugFieldInfo fieldInfo) { CorElementType corElemType = (CorElementType)fieldInfo.FieldProps.ConstantType; if (corElemType == CorElementType.CLASS) { // Only null literals are allowed return(Eval.CreateValue(fieldInfo.AppDomain, null)); } else if (corElemType == CorElementType.STRING) { string str = Marshal.PtrToStringUni(fieldInfo.FieldProps.ConstantPtr, (int)fieldInfo.FieldProps.ConstantStringLength); return(Eval.CreateValue(fieldInfo.AppDomain, str)); } else { DebugType type = DebugType.CreateFromType(fieldInfo.AppDomain.Mscorlib, DebugType.CorElementTypeToManagedType(corElemType)); if (fieldInfo.FieldType.IsEnum && fieldInfo.FieldType.GetEnumUnderlyingType() == type) { Value val = Eval.NewObjectNoConstructor((DebugType)fieldInfo.FieldType); Value backingField = val.GetMemberValue("value__"); backingField.CorGenericValue.SetValue(fieldInfo.FieldProps.ConstantPtr); return(val); } else { Value val = Eval.NewObjectNoConstructor(type); val.CorGenericValue.SetValue(fieldInfo.FieldProps.ConstantPtr); return(val); } } }
public static Value CreateValue(AppDomain appDomain, object value) { if (value == null) { ICorDebugClass corClass = appDomain.ObjectType.CorType.GetClass(); Thread thread = GetEvaluationThread(appDomain); ICorDebugEval corEval = thread.CorThread.CreateEval(); ICorDebugValue corValue = corEval.CreateValue((uint)CorElementType.CLASS, corClass); return(new Value(appDomain, corValue)); } else if (value is string) { return(Eval.NewString(appDomain, (string)value)); } else { if (!value.GetType().IsPrimitive) { throw new DebuggerException("Value must be primitve type. Seen " + value.GetType()); } Value val = Eval.NewObjectNoConstructor(DebugType.CreateFromType(appDomain.Mscorlib, value.GetType())); val.PrimitiveValue = value; return(val); } }