예제 #1
0
파일: Resolver.cs 프로젝트: 3H54N/eazdevirt
        ITypeDefOrRef ResolveType_NoLock(Int32 position)
        {
            this.Stream.Position = position;

            InlineOperand operand = new InlineOperand(this.Reader);
            if (operand.IsToken)
            {
                MDToken token = new MDToken(operand.Token);

                if (token.Table == Table.TypeDef)
                    return this.Module.ResolveTypeDef(token.Rid);
                else if (token.Table == Table.TypeRef)
                    return this.Module.ResolveTypeRef(token.Rid);
                else if (token.Table == Table.TypeSpec)
                    return this.Module.ResolveTypeSpec(token.Rid);

                throw new Exception("Unable to resolve type: bad MDToken table");
            }
            else
            {
                TypeData data = operand.Data as TypeData;

                // Resolve via name
                TypeName typeName = new TypeName(data.Name);
                NameResolver nameResolver = new NameResolver(this.Module);
                ITypeDefOrRef typeDefOrRef = nameResolver.ResolveTypeDefOrRef(typeName);

                if (typeDefOrRef == null)
                {
                    throw new Exception(String.Format(
                        "Unable to resolve ITypeDefOrRef from given name: {0}",
                        typeName.FullName));
                }

                // Apply generics, if any (resulting in a TypeSpec)
                if (data.GenericTypes.Length > 0)
                    typeDefOrRef = ApplyGenerics(typeDefOrRef, data);

                if (typeDefOrRef == null)
                {
                    throw new Exception(String.Format(
                        "Unable to apply generic types: {0}", typeName.FullName
                        ));
                }

                // Apply [], *, &
                typeDefOrRef = SigUtil.FromBaseSig(typeDefOrRef.ToTypeSig(), typeName.Modifiers)
                    .ToTypeDefOrRef();

                return typeDefOrRef;
            }
        }
예제 #2
0
파일: Resolver.cs 프로젝트: 3H54N/eazdevirt
        IField ResolveField_NoLock(Int32 position)
        {
            this.Stream.Position = position;

            InlineOperand operand = new InlineOperand(this.Reader);
            if (operand.IsToken)
            {
                MDToken token = new MDToken(operand.Token);
                return this.Module.ResolveField(token.Rid);
            }
            else
            {
                FieldData data = operand.Data as FieldData;
                ITypeDefOrRef declaringType = this.ResolveType_NoLock(data.FieldType.Position);
                if (declaringType == null)
                    throw new Exception("[ResolveField_NoLock] Unable to resolve type as TypeDef or TypeRef");

                NameResolver nameResolver = new NameResolver(this.Module);
                IField field = nameResolver.ResolveField(declaringType, data.Name);
                if (field == null)
                {
                    throw new Exception(String.Format(
                    "[ResolveField_NoLock] Unable to resolve field: DeclaringType={0}, Field={1}",
                    declaringType.ReflectionFullName, data.Name));
                }

                return field;
            }
        }