public CorType Create(DmdType type) { if ((object)type == null) { throw new ArgumentNullException(nameof(type)); } if (recursionCounter++ > 100) { throw new InvalidOperationException(); } CorType result; int i; ReadOnlyCollection <DmdType> types; CorType[] corTypes; DnModule dnModule; switch (type.TypeSignatureKind) { case DmdTypeSignatureKind.Type: if (!engine.TryGetDnModule(type.Module.GetDebuggerModule() ?? throw new InvalidOperationException(), out dnModule)) { throw new InvalidOperationException(); } Debug.Assert((type.MetadataToken >> 24) == 0x02); result = dnModule.CorModule.GetClassFromToken((uint)type.MetadataToken).GetParameterizedType(type.IsValueType ? CorElementType.ValueType : CorElementType.Class); break; case DmdTypeSignatureKind.Pointer: result = Create(type.GetElementType()); result = appDomain.GetPtr(result); break; case DmdTypeSignatureKind.ByRef: result = Create(type.GetElementType()); result = appDomain.GetByRef(result); break; case DmdTypeSignatureKind.TypeGenericParameter: case DmdTypeSignatureKind.MethodGenericParameter: throw new InvalidOperationException(); case DmdTypeSignatureKind.SZArray: result = Create(type.GetElementType()); result = appDomain.GetSZArray(result); break; case DmdTypeSignatureKind.MDArray: result = Create(type.GetElementType()); result = appDomain.GetArray(result, (uint)type.GetArrayRank()); break; case DmdTypeSignatureKind.GenericInstance: result = Create(type.GetGenericTypeDefinition()); types = type.GetGenericArguments(); corTypes = new CorType[types.Count]; for (i = 0; i < corTypes.Length; i++) { corTypes[i] = Create(types[i]); } result = result.Class.GetParameterizedType(type.IsValueType ? CorElementType.ValueType : CorElementType.Class, corTypes); break; case DmdTypeSignatureKind.FunctionPointer: var methodSig = type.GetFunctionPointerMethodSignature(); types = methodSig.GetParameterTypes(); corTypes = new CorType[1 + types.Count + methodSig.GetVarArgsParameterTypes().Count]; corTypes[0] = Create(methodSig.ReturnType); for (i = 0; i < types.Count; i++) { corTypes[i + 1] = Create(types[i]); } types = methodSig.GetVarArgsParameterTypes(); for (i = 0; i < types.Count; i++) { corTypes[i + 1 + methodSig.GetParameterTypes().Count] = Create(types[i]); } result = appDomain.GetFnPtr(corTypes); break; default: throw new InvalidOperationException(); } if (result == null) { throw new InvalidOperationException(); } recursionCounter--; return(result); }
public IDebuggerType ToArray(int rank) => debugger.Dispatcher.UI(() => { var res = CorAppDomain?.GetArray(type, (uint)rank); return(res == null ? null : new DebuggerType(debugger, res)); });