private IEnumerable<FieldInfo> FixDeclaringTypes(FieldInfo[] fields, TypeInfo[] types) { var fixedFields = new List<FieldInfo>(); var typeFullNames = types.Select(t => t.FullName).ToArray(); foreach (var field in fields) { if (types.Contains(field.DeclaringType)) { fixedFields.Add(field); continue; } if (typeFullNames.Contains(field.DeclaringType.FullName)) { var type = types.Single(t => t.FullName == field.DeclaringType.FullName); var realField = type.Fields.Single(m => m.Name == field.Name); fixedFields.Add(realField); } } return fixedFields; }
private IEnumerable<MethodInfo> FixDeclaringTypes(MethodInfo[] methods, TypeInfo[] types) { var fixedMethods = new List<MethodInfo>(); var typeFullNames = types.Select(t => t.FullName).ToArray(); foreach (var method in methods) { if (types.Contains(method.DeclaringType)) { fixedMethods.Add(method); continue; } if (typeFullNames.Contains(method.DeclaringType.FullName)) { var type = types.Single(t => t.FullName == method.DeclaringType.FullName); var realMethod = type.Methods.SingleOrDefault(m => m.MemberReference.ToString() == method.MemberReference.ToString()); if (realMethod == null) { realMethod = type.Accessors.Single(m => m.MemberReference.ToString() == method.MemberReference.ToString()); } fixedMethods.Add(realMethod); } } return fixedMethods; }