private FieldInfo ResolveField(Cci.IFieldReference fieldRef) { var fieldDef = fieldRef.GetResolvedField(_context); if (fieldDef != null && IsLocal(fieldRef.GetContainingType(_context))) { return _fieldBuilders[fieldDef]; } FieldInfo result; if (_fieldRefs.TryGetValue(fieldRef, out result)) { return result; } Type declaringType = ResolveType(fieldRef.GetContainingType(_context)); Cci.ISpecializedFieldReference specializedRef = fieldRef.AsSpecializedFieldReference; if (specializedRef != null) { if (IsLocal(specializedRef.UnspecializedVersion.GetContainingType(_context))) { // declaring type is TypeBuilder or TypeBuilderInstantiation since it's defined in the module being built: FieldBuilder fieldBuilder = _fieldBuilders[(Cci.IFieldDefinition)specializedRef.UnspecializedVersion.AsDefinition(_context)]; result = TypeBuilder.GetField(declaringType, fieldBuilder); } else { FieldInfo unspecializedDefinition = ResolveField(specializedRef.UnspecializedVersion); result = new FieldRef(declaringType, fieldRef.Name, unspecializedDefinition.FieldType); } } else { GenericContext genericContext; if (declaringType.IsGenericTypeDefinition) { genericContext = new GenericContext(declaringType.GetGenericArguments(), Type.EmptyTypes); } else { genericContext = default(GenericContext); } // TODO: modifiers? Type fieldType = ResolveType(fieldRef.GetType(_context), genericContext); result = new FieldRef(declaringType, fieldRef.Name, fieldType); } _fieldRefs.Add(fieldRef, result); return result; }