Example #1
0
        DebugType(Process process, ICorDebugType corType)
        {
            if (corType == null)
            {
                throw new ArgumentNullException("corType");
            }

            this.process        = process;
            this.corType        = corType;
            this.corElementType = (CorElementType)corType.Type;

            if (this.IsClass || this.IsValueType)
            {
                this.corClass   = corType.Class;
                this.module     = process.GetModule(corClass.Module);
                this.classProps = module.MetaData.GetTypeDefProps(corClass.Token);
            }

            if (this.IsClass || this.IsValueType || this.IsArray || this.IsPointer)
            {
                foreach (ICorDebugType t in corType.EnumerateTypeParameters().Enumerator)
                {
                    typeArguments.Add(DebugType.Create(process, t));
                }
            }

            this.fullName = GetFullName();
        }
Example #2
0
		DebugType(Process process, ICorDebugType corType)
		{
			if (corType == null) throw new ArgumentNullException("corType");
			
			this.process = process;
			this.corType = corType;
			this.corElementType = (CorElementType)corType.Type;
			
			if (this.IsClass || this.IsValueType) {
				this.corClass = corType.Class;
				this.module = process.GetModule(corClass.Module);
				this.classProps = module.MetaData.GetTypeDefProps(corClass.Token);
			}
			
			if (this.IsClass || this.IsValueType || this.IsArray || this.IsPointer) {
				foreach(ICorDebugType t in corType.EnumerateTypeParameters().Enumerator) {
					typeArguments.Add(DebugType.Create(process, t));
				}
			}
			
			this.fullName = GetFullName();
		}
        public static ITypeReference ToTypeReference(this ICorDebugType corType, Process process)
        {
            switch ((CorElementType)corType.GetTheType())
            {
            case CorElementType.VOID:
                return(KnownTypeReference.Void);

            case CorElementType.BOOLEAN:
                return(KnownTypeReference.Boolean);

            case CorElementType.CHAR:
                return(KnownTypeReference.Char);

            case CorElementType.I1:
                return(KnownTypeReference.SByte);

            case CorElementType.U1:
                return(KnownTypeReference.Byte);

            case CorElementType.I2:
                return(KnownTypeReference.Int16);

            case CorElementType.U2:
                return(KnownTypeReference.UInt16);

            case CorElementType.I4:
                return(KnownTypeReference.Int32);

            case CorElementType.U4:
                return(KnownTypeReference.UInt32);

            case CorElementType.I8:
                return(KnownTypeReference.Int64);

            case CorElementType.U8:
                return(KnownTypeReference.UInt64);

            case CorElementType.R4:
                return(KnownTypeReference.Single);

            case CorElementType.R8:
                return(KnownTypeReference.Double);

            case CorElementType.STRING:
                return(KnownTypeReference.String);

            case CorElementType.PTR:
                return(new PointerTypeReference(corType.GetFirstTypeParameter().ToTypeReference(process)));

            case CorElementType.BYREF:
                return(new ByReferenceTypeReference(corType.GetFirstTypeParameter().ToTypeReference(process)));

            case CorElementType.VALUETYPE:
            case CorElementType.CLASS:
                // Get generic arguments
                List <ITypeReference> genericArguments = new List <ITypeReference>();
                foreach (ICorDebugType t in corType.EnumerateTypeParameters().GetEnumerator())
                {
                    genericArguments.Add(t.ToTypeReference(process));
                }
                var            module = process.GetModule(corType.GetClass().GetModule());
                ITypeReference typeDefinitionReference = ToTypeDefinitionReference(module, corType.GetClass().GetToken());
                if (genericArguments.Count > 0)
                {
                    return(new ParameterizedTypeReference(typeDefinitionReference, genericArguments));
                }
                else
                {
                    return(typeDefinitionReference);
                }

            case CorElementType.ARRAY:
                return(new ArrayTypeReference(corType.GetFirstTypeParameter().ToTypeReference(process),
                                              (int)corType.GetRank()));

            case CorElementType.GENERICINST:
                throw new NotSupportedException();

            case CorElementType.I:
                return(KnownTypeReference.IntPtr);

            case CorElementType.U:
                return(KnownTypeReference.UIntPtr);

            case CorElementType.OBJECT:
                return(KnownTypeReference.Object);

            case CorElementType.SZARRAY:
                return(new ArrayTypeReference(corType.GetFirstTypeParameter().ToTypeReference(process)));

            case CorElementType.CMOD_REQD:
            case CorElementType.CMOD_OPT:
                return(corType.GetFirstTypeParameter().ToTypeReference(process));

            default:
                throw new InvalidOperationException("Invalid value for CorElementType");
            }
        }