Ejemplo n.º 1
0
        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}"));
                }
            }
        }
Ejemplo n.º 2
0
        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}");
            }
        }
Ejemplo n.º 3
0
        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}");
            }
        }