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(); }
private void CompleteResolverTypeBindings( ITypeInspector inspector, INamingConventions naming) { foreach (ResolverTypeBindingInfo binding in _bindings.OfType <ResolverTypeBindingInfo>() .ToList()) { ComplexTypeBindingInfo typeBinding = null; if (binding.SourceType == null) { binding.SourceType = typeof(object); } if (binding.SourceType != null && binding.TypeName.IsEmpty) { typeBinding = _bindings.OfType <ComplexTypeBindingInfo>() .FirstOrDefault(t => t.Type == binding.SourceType); if (typeBinding == null) { binding.TypeName = naming.GetTypeName( binding.SourceType, TypeKind.Object); } else { binding.TypeName = typeBinding.Name; } } typeBinding = _bindings.OfType <ComplexTypeBindingInfo>() .FirstOrDefault(t => t.Name.Equals(binding.TypeName)); if (typeBinding == null) { _bindings.Add(new ComplexTypeBindingInfo { Name = binding.TypeName, Type = binding.SourceType }); } else if (binding.SourceType == typeof(object)) { binding.SourceType = typeBinding.Type; } foreach (ResolverFieldBindingInfo field in binding.Fields) { if (field.FieldName.IsEmpty) { field.FieldName = naming.GetMemberName( field.FieldMember, MemberKind.ObjectField); } } if (binding.BindingBehavior == BindingBehavior.Implicit) { AddImplicitResolverBindings(inspector, naming, binding); } } }
private void CompleteResolverBindings(INamingConventions naming) { foreach (ResolverBindingInfo binding in _bindings.OfType <ResolverBindingInfo>() .ToList()) { if (binding.TypeName.IsEmpty) { ComplexTypeBindingInfo typeBinding = _bindings.OfType <ComplexTypeBindingInfo>() .FirstOrDefault(t => t.Type == binding.SourceType); binding.TypeName = typeBinding == null ? naming.GetTypeName(binding.SourceType) : typeBinding.Name; } if (binding.FieldName.IsEmpty) { binding.FieldName = naming.GetMemberName( binding.Member, MemberKind.ObjectField); } if (!_bindings.OfType <ComplexTypeBindingInfo>() .Any(t => t.Name.Equals(binding.TypeName))) { _bindings.Add(new ComplexTypeBindingInfo { Name = binding.TypeName, Type = binding.SourceType }); } } }
/// <inheritdoc /> public virtual NameString GetTypeName(Type runtimeType) { if (runtimeType is null) { throw new ArgumentNullException(nameof(runtimeType)); } string name = _namingConventions.GetTypeName(runtimeType); if (!name.EndsWith(_typePostFix, StringComparison.Ordinal)) { name += _typePostFix; } return(name); }
private void CompleteComplexTypeBindings( INamingConventions naming) { foreach (ComplexTypeBindingInfo binding in _bindings.OfType <ComplexTypeBindingInfo>()) { if (binding.Name.IsEmpty) { binding.Name = naming.GetTypeName(binding.Type); } foreach (ComplexTypeFieldBindingInfo field in binding.Fields) { if (field.Name.IsEmpty) { field.Name = naming.GetMemberName( field.Member, MemberKind.Field); } } } }
/// <inheritdoc /> public virtual NameString GetTypeName(Type runtimeType) => _namingConventions.GetTypeName(runtimeType, TypeKind.Object) + _typePostFix;
/// <inheritdoc /> public virtual NameString GetTypeName(Type runtimeType) { if (runtimeType is null) { throw new ArgumentNullException(nameof(runtimeType)); } if (typeof(IEnumOperationFilterInputType).IsAssignableFrom(runtimeType) && runtimeType.GenericTypeArguments.Length == 1 && runtimeType.GetGenericTypeDefinition() == typeof(EnumOperationFilterInputType <>)) { NameString genericName = _namingConventions.GetTypeName(runtimeType.GenericTypeArguments[0]); return(genericName.Value + "OperationFilterInput"); } if (typeof(IComparableOperationFilterInputType).IsAssignableFrom(runtimeType) && runtimeType.GenericTypeArguments.Length == 1 && runtimeType.GetGenericTypeDefinition() == typeof(ComparableOperationFilterInputType <>)) { NameString genericName = _namingConventions.GetTypeName(runtimeType.GenericTypeArguments[0]); return($"Comparable{genericName.Value}OperationFilterInput"); } if (typeof(IListFilterInputType).IsAssignableFrom(runtimeType) && runtimeType.GenericTypeArguments.Length == 1 && runtimeType.GetGenericTypeDefinition() == typeof(ListFilterInputType <>)) { Type genericType = runtimeType.GenericTypeArguments[0]; NameString genericName; if (typeof(FilterInputType).IsAssignableFrom(genericType)) { genericName = GetTypeName(genericType); } else { genericName = _namingConventions.GetTypeName(genericType); } return("List" + genericName.Value); } string name = _namingConventions.GetTypeName(runtimeType); var isInputObjectType = typeof(FilterInputType).IsAssignableFrom(runtimeType); var isEndingInput = name.EndsWith(_inputPostFix, StringComparison.Ordinal); var isEndingInputType = name.EndsWith(_inputTypePostFix, StringComparison.Ordinal); if (isInputObjectType && isEndingInputType) { return(name.Substring(0, name.Length - 4)); } if (isInputObjectType && !isEndingInput && !isEndingInputType) { return(name + _inputPostFix); } if (!isInputObjectType && !isEndingInput) { return(name + _inputPostFix); } return(name); }