public static DBG.CorType[] ToCorTypes(this IDebuggerType[] types) { if (types == null) return null; var ctypes = new DBG.CorType[types.Length]; for (int i = 0; i < types.Length; i++) { var t = (DebuggerType)types[i]; ctypes[i] = t.CorType; } return ctypes; }
public static DBG.CorType[] ToCorTypes(this IDebuggerType[] types) { if (types == null) { return(null); } var ctypes = new DBG.CorType[types.Length]; for (int i = 0; i < types.Length; i++) { var t = (DebuggerType)types[i]; ctypes[i] = t.CorType; } return(ctypes); }
public static IEnumerable <CorPropertyInfo> GetProperties(CorType type, bool checkBaseClasses = true) { for (; type != null; type = type.Base) { uint token; var mdi = type.GetMetaDataImport(out token); var pdTokens = MDAPI.GetPropertyTokens(mdi, token); foreach (var pdToken in pdTokens) { var info = ReadPropertyInfo(mdi, pdToken, type); if (info != null) { yield return(info); } } if (!checkBaseClasses) { break; } } }
public static CorMethodInfo GetToStringMethod(CorType type) { //TODO: Check for method overrides! for (; type != null; type = type.Base) { var mdi = type.GetMetaDataImport(out uint token); var mdTokens = MDAPI.GetMethodTokens(mdi, token); foreach (var mdToken in mdTokens) { var info = ReadMethodInfo(mdi, mdToken, type); if (info == null) { continue; } if (IsToString(info)) { return(info); } } } return(null); }
public static IEnumerable <CorFieldInfo> GetFieldInfos(CorType type, bool checkBaseClasses = true) { for (; type != null; type = type.Base) { var cls = type.Class; var mdi = cls?.Module?.GetMetaDataInterface <IMetaDataImport>(); var fdTokens = MDAPI.GetFieldTokens(mdi, cls?.Token ?? 0); foreach (var fdToken in fdTokens) { var info = ReadFieldInfo(mdi, fdToken, type); Debug.Assert(info != null); if (info != null) { yield return(info); } } if (!checkBaseClasses) { break; } } }
DBG.CorType[] CreateTypesThrow(object[] types) { if (types == null) { return(null); } var res = new DBG.CorType[types.Length]; for (int i = 0; i < res.Length; i++) { var type = types[i]; var dt = type as DebuggerType; if (dt != null) { res[i] = dt.CorType; } else { res[i] = ((DebuggerType)FindTypeThrow(type as Type)).CorType; } } return(res); }
static CorFieldInfo ReadFieldInfo(IMetaDataImport mdi, uint token, CorType type) { if (mdi == null) { return(null); } var name = MDAPI.GetFieldName(mdi, token); if (name == null) { return(null); } var fieldType = GetFieldTypeSig(mdi, token); if (fieldType == null) { return(null); } var attrs = MDAPI.GetFieldAttributes(mdi, token); var constant = MDAPI.GetFieldConstant(mdi, token, out var constantType); return(new CorFieldInfo(type, token, name, fieldType, attrs, constant)); }
public bool Equals(CorType other) => !ReferenceEquals(other, null) && RawObject == other.RawObject;
unsafe static CorPropertyInfo ReadPropertyInfo(IMetaDataImport mdi, uint token, CorType type) { if (mdi == null) { return(null); } var name = MDAPI.GetPropertyName(mdi, token); if (name == null) { return(null); } if (!MDAPI.GetPropertyGetterSetter(mdi, token, out uint mdGetter, out uint mdSetter)) { return(null); } var getSig = GetMethodSignature(mdi, mdGetter); var setSig = GetMethodSignature(mdi, mdSetter); if (getSig == null) { return(null); } if (getSig.ParamsAfterSentinel != null) { return(null); } if (getSig.GenParamCount != 0) { return(null); } if (getSig.Params.Count != 0) { return(null); } if (getSig.RetType.RemovePinnedAndModifiers().GetElementType() == ElementType.Void) { return(null); } if (setSig != null && setSig.ParamsAfterSentinel != null) { setSig = null; } if (setSig != null && setSig.GenParamCount != 0) { setSig = null; } if (setSig != null && setSig.Params.Count != 1) { setSig = null; } if (setSig != null && setSig.RetType.RemovePinnedAndModifiers().GetElementType() != ElementType.Void) { setSig = null; } if (setSig != null && getSig.HasThis != setSig.HasThis) { setSig = null; } if (setSig != null && !Equals(getSig.RetType.RemovePinnedAndModifiers(), setSig.Params[0].RemovePinnedAndModifiers())) { setSig = null; } if (setSig == null) { mdSetter = 0; } if (!MDAPI.GetMethodAttributes(mdi, mdGetter, out var getMethodAttrs, out var getMethodImplAttrs)) { return(null); } var browseState = GetDebuggerBrowsableState(mdi, token); return(new CorPropertyInfo(type, token, mdGetter, mdSetter, name, getSig, setSig, getMethodAttrs, browseState)); }
DBG.CorType[] CreateTypesThrow(object[] types) { if (types == null) return null; var res = new DBG.CorType[types.Length]; for (int i = 0; i < res.Length; i++) { var type = types[i]; var dt = type as DebuggerType; if (dt != null) res[i] = dt.CorType; else res[i] = ((DebuggerType)FindTypeThrow(type as Type)).CorType; } return res; }
public bool Equals(CorType other) { return(!ReferenceEquals(other, null) && RawObject == other.RawObject); }
/// <summary> /// Gets the <c>System.Nullable</c> fields if it's a nullable type /// </summary> /// <param name="hasValueInfo">Updated with <c>hasValue</c> field</param> /// <param name="valueInfo">Updated with 'value' field</param> /// <param name="nullableElemType">Updated with nullable element type</param> /// <returns></returns> public bool GetSystemNullableFields(out TokenAndName hasValueInfo, out TokenAndName valueInfo, out CorType nullableElemType) { return(Utils.GetSystemNullableFields(this, out hasValueInfo, out valueInfo, out nullableElemType)); }
public T WriteType <T>(T output, CorType type, TypePrinterFlags flags, Func <DnEval> getEval = null) where T : ITypeOutput { new TypePrinter(output, flags, getEval).Write(type); return(output); }
public CorValue CreateValue(CorType type) { return(eval.CreateValueForType(type)); }
public static bool GetSystemNullableFields(this CorType type, out TokenAndName hasValueInfo, out TokenAndName valueInfo, out CorType nullableElemType) { nullableElemType = null; if (!type.GetSystemNullableFields(out hasValueInfo, out valueInfo)) { return(false); } nullableElemType = type.FirstTypeParameter; return(nullableElemType != null); }
unsafe static CorPropertyInfo ReadPropertyInfo(IMetaDataImport mdi, uint token, CorType type) { if (mdi == null) { return(null); } uint chProperty, dwPropFlags, mdSetter, mdGetter; int hr = mdi.GetPropertyProps(token, IntPtr.Zero, IntPtr.Zero, 0, out chProperty, out dwPropFlags, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, out mdSetter, out mdGetter, IntPtr.Zero, 0, IntPtr.Zero); char[] nameBuf = null; if (hr >= 0 && chProperty != 0) { nameBuf = new char[chProperty]; fixed(char *p = &nameBuf[0]) hr = mdi.GetPropertyProps(token, IntPtr.Zero, new IntPtr(p), (uint)nameBuf.Length, out chProperty, out dwPropFlags, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, out mdSetter, out mdGetter, IntPtr.Zero, 0, IntPtr.Zero); } if (hr < 0) { return(null); } string name = chProperty <= 1 ? string.Empty : new string(nameBuf, 0, (int)chProperty - 1); var getSig = GetMethodSignature(mdi, mdGetter); var setSig = GetMethodSignature(mdi, mdSetter); if (getSig == null) { return(null); } if (getSig.ParamsAfterSentinel != null) { return(null); } if (getSig.GenParamCount != 0) { return(null); } if (getSig.Params.Count != 0) { return(null); } if (getSig.RetType.RemovePinnedAndModifiers().GetElementType() == ElementType.Void) { return(null); } if (setSig != null && setSig.ParamsAfterSentinel != null) { setSig = null; } if (setSig != null && setSig.GenParamCount != 0) { setSig = null; } if (setSig != null && setSig.Params.Count != 1) { setSig = null; } if (setSig != null && setSig.RetType.RemovePinnedAndModifiers().GetElementType() != ElementType.Void) { setSig = null; } if (setSig != null && getSig.HasThis != setSig.HasThis) { setSig = null; } if (setSig != null && !Equals(getSig.RetType.RemovePinnedAndModifiers(), setSig.Params[0].RemovePinnedAndModifiers())) { setSig = null; } if (setSig == null) { mdSetter = 0; } MethodAttributes getMethodAttrs; MethodImplAttributes dwImplAttrs; IntPtr pvSigBlob; hr = mdi.GetMethodProps(mdGetter, IntPtr.Zero, IntPtr.Zero, 0, out chProperty, out getMethodAttrs, out pvSigBlob, out chProperty, out chProperty, out dwImplAttrs); if (hr < 0) { return(null); } var browseState = GetDebuggerBrowsableState(mdi, token); return(new CorPropertyInfo(type, token, mdGetter, mdSetter, name, getSig, setSig, getMethodAttrs, browseState)); }
public CorValue CreateValue(CorType type) => eval.CreateValueForType(type);