Ejemplo n.º 1
0
        public FieldInfo Field(FieldReference reference, GenericScope genericScope)
        {
            Argument.NotNull(nameof(reference), reference);

            var definition    = reference.Resolve();
            var declaringType = Type(reference.DeclaringType, genericScope);

            genericScope = genericScope.With(definition.DeclaringType.GenericParameters, declaringType.GenericTypeArguments);

            var interpretedType = declaringType as InterpretedType;

            if (ShouldBeRuntime(definition) && interpretedType == null)
            {
                var token = reference.MetadataToken.ToInt32();
                return((FieldInfo)declaringType
                       .GetMembers()
                       .First(m => m.MetadataToken == token));
            }
            if (interpretedType == null)
            {
                throw InterpretedMemberInNonInterpretedType(reference, declaringType);
            }

            return(new InterpretedField(
                       interpretedType,
                       definition.Name,
                       Type(reference.FieldType, genericScope),
                       (System.Reflection.FieldAttributes)definition.Attributes
                       ));
        }
Ejemplo n.º 2
0
        private InterpretedType NewInterpretedGenericPathType(Type declaringType, Type definitionType, TypeDefinition definition, Type[] genericArguments, GenericScope genericScope)
        {
            genericScope = genericScope.With(definition.GenericParameters, genericArguments);

            var lazyBaseType = definition.BaseType != null ? new Lazy <Type>(() => Type(definition.BaseType, genericScope)) : LazyNullType;

            return(new InterpretedGenericPathType(
                       definitionType,
                       lazyBaseType,
                       LazyInterfacesOf(definition, lazyBaseType, genericScope),
                       t => LazyMembersOf(t, definition, genericScope),
                       genericArguments
                       ));
        }
Ejemplo n.º 3
0
        public MethodBase Method(MethodReference reference, GenericScope genericScope)
        {
            Argument.NotNull(nameof(reference), reference);
            var definition = reference.Resolve();

            if (definition == null)
            {
                throw new Exception($"Failed to resolve definition for method {reference}.");
            }

            var declaringType = Type(reference.DeclaringType, genericScope);

            genericScope = genericScope.With(definition.DeclaringType.GenericParameters, declaringType.GenericTypeArguments);
            return(Method(declaringType, definition, reference, genericScope));
        }
Ejemplo n.º 4
0
        private MethodBase Method(Type declaringType, MethodDefinition definition, MethodReference reference, GenericScope genericScope)
        {
            var genericArguments = Empty <Type> .Array;
            var generic          = reference as GenericInstanceMethod;

            if (generic != null)
            {
                genericArguments = generic.GenericArguments.Select(a => Type(a, genericScope)).ToArray();
                genericScope     = genericScope.With(definition.GenericParameters, genericArguments);
            }

            var        cacheKey = new MethodKey(declaringType, definition, genericArguments);
            MethodBase method;

            if (_methodCache.TryGetValue(cacheKey, out method))
            {
                return(method);
            }

            method = MethodUncached(declaringType, definition, reference, genericArguments, genericScope);
            _methodCache[cacheKey] = method;
            return(method);
        }