public static void AddFields <TOutput>(IContainer container, ComplexGraphType <object> obj) where TOutput : class { var outputType = typeof(TOutput); var objectType = obj.GetType(); var filter = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly; var methods = objectType.GetMethods(filter); var objectTypeProperties = objectType.GetProperties(filter); foreach (var propertyInfo in objectTypeProperties) { if (propertyInfo.GetMethod != null && propertyInfo.GetMethod.IsPublic) { AddField(container, obj, outputType, propertyInfo, methods.FirstOrDefault(m => m.Name == $"Get{propertyInfo.Name}")); } } foreach (var propertyInfo in outputType.GetProperties(filter)) { //Skip properties that are already defined in the object type if (objectTypeProperties.Any(p => p.Name == propertyInfo.Name)) { continue; } if (propertyInfo.GetMethod != null && propertyInfo.GetMethod.IsPublic) { AddField(container, obj, outputType, propertyInfo, methods.FirstOrDefault(m => m.Name == $"Get{propertyInfo.Name}")); } } }
public static void AutoMap <TSource>(this ComplexGraphType <TSource> graph, IReadOnlyList <string>?exclusions = null) { var type = typeof(TSource); try { MapProperties(graph, type, exclusions); } catch (GetGraphException exception) { throw new Exception($"Failed to map '{graph.GetType().Name}'. {exception.Message}"); } }
internal static void AutoMap <TDbContext, TSource>( ComplexGraphType <TSource> graph, IEfGraphQLService <TDbContext> graphService, IReadOnlyList <string>?exclusions = null) where TDbContext : DbContext { var type = typeof(TSource); try { MapNavigationProperties(graph, graphService, type, exclusions); MapProperties(graph, type, exclusions); } catch (GetGraphException exception) { throw new Exception($"Failed to map '{graph.GetType().Name}'. {exception.Message}"); } }