Пример #1
0
        public IEnumerable <IType> GenerateTypeDescriptors <T>() where T : class
        {
            var rootType = typeof(T);

            var graphQLType = GraphQLTypeHelpers.GetGraphQLType(
                rootType,
                out _
                );

            IType graphQLRootType;
            var   rootTypeName = namingConventions.GetTypeName(rootType);
            var   flags        = BindingFlags.Public | BindingFlags.Instance;

            var members = Enumerable.Concat <MemberInfo>(
                rootType.GetFields(flags),
                rootType.GetProperties(flags)
                );

            switch (graphQLType)
            {
            case TypeKind.Object:
                //var ctor = typeof(ObjectType<>)
                //    .MakeGenericType(rootType)
                //    .GetConstructor(new Type[] { typeof(Action<>).MakeGenericType(IObjectTypeDescriptor<>) })
                //    ?? throw new Exception();

                graphQLRootType = new ObjectType(
                    desc =>
                {
                    desc.Name(rootTypeName);

                    foreach (var member in members)
                    {
                    }
                }
                    );

                break;

            case TypeKind.Interface:
                graphQLRootType = new InterfaceType(
                    desc => desc.Name(rootTypeName)
                    );

                break;

            default:
                throw new NotImplementedException();
            }

            throw new NotImplementedException();
        }
Пример #2
0
        private IType MockITypeGenerator(Type type, out bool isCompleted)
        {
            if (GraphQLTypeHelpers.IsBuiltInScalarType(type))
            {
                throw new Exception();
            }

            isCompleted = false;
            IType result;

            var graphQLTypeKind = GraphQLTypeHelpers.GetGraphQLType(
                type,
                out var isNullable
                );

            var typeName = namingConventions.GetTypeName(type);

            switch (graphQLTypeKind)
            {
            case TypeKind.Object:
                result = new ObjectType(
                    desc => desc.Name(typeName)
                    );

                break;

            case TypeKind.Interface:
                result = new InterfaceType(
                    desc => desc.Name(typeName)
                    );

                break;

            case TypeKind.Enum:
                result = typeof(EnumType <>)
                         .MakeGenericType(type)
                         .GetConstructor(Array.Empty <Type>())
                         ?.Invoke(Array.Empty <object>()) as EnumType
                         ?? throw new Exception();

                isCompleted = true;

                break;

            case TypeKind.List:
                var memberType = GraphQLTypeHelpers.GetListMemberType(type);

                if (!typeRegistrar.TryGetValue(memberType, out var memberIType))
                {
                    throw new Exception();
                }

                result = new ListType(memberIType);
                break;

            default:
                throw new NotImplementedException();
            }

            return(result);
        }