/// <summary> /// Resolves a property reference. /// </summary> /// <param name="propertyRef">The property reference to resolve.</param> /// <param name="assembly">The assembly that declares the reference.</param> /// <returns>The property referred to by the reference.</returns> internal IProperty Resolve( PropertyReference propertyRef, ClrAssembly assembly) { var declaringType = Resolve(propertyRef.DeclaringType, assembly); var standinReplacer = CreateStandinReplacingVisitor(declaringType); var propertyType = TypeHelpers.BoxIfReferenceType( standinReplacer.Visit(Resolve(propertyRef.PropertyType, assembly, declaringType, true))); var parameterTypes = propertyRef.Parameters .Select(param => TypeHelpers.BoxIfReferenceType( standinReplacer.Visit( Resolve(param.ParameterType, assembly, declaringType, true)))) .ToImmutableArray(); return(PickSingleResolvedMember( propertyRef, propertyIndex.GetAll( declaringType, ClrPropertySignature.Create( propertyRef.Name, propertyType, parameterTypes)))); }
/// <summary> /// Creates a reference resolver. /// </summary> /// <param name="resolver"> /// The assembly resolver to use. /// </param> /// <param name="typeEnvironment"> /// The reference resolver's type environment. /// </param> public ReferenceResolver( AssemblyResolver resolver, TypeEnvironment typeEnvironment) { this.AssemblyResolver = resolver; this.TypeEnvironment = typeEnvironment; this.assemblyCache = new Dictionary <string, IAssembly>(); this.typeResolvers = new Dictionary <IAssembly, TypeResolver>(); this.cacheLock = new ReaderWriterLockSlim(); this.fieldIndex = new Index <IType, KeyValuePair <string, IType>, IField>( type => type.Fields .Select(field => new KeyValuePair <KeyValuePair <string, IType>, IField>( new KeyValuePair <string, IType>( field.Name.ToString(), field.FieldType), field))); this.methodIndex = new Index <IType, ClrMethodSignature, IMethod>( type => type.Methods .Concat( type.Properties.SelectMany(prop => prop.Accessors)) .Select(method => new KeyValuePair <ClrMethodSignature, IMethod>( ClrMethodSignature.Create(method), method))); this.propertyIndex = new Index <IType, ClrPropertySignature, IProperty>( type => type.Properties.Select(prop => new KeyValuePair <ClrPropertySignature, IProperty>( ClrPropertySignature.Create(prop), prop))); }