コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        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
                    });
                }
            }
        }
コード例 #3
0
        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);
                    }
                }
            }
        }
コード例 #4
0
        private void AddImplicitResolverBindings(
            ITypeInspector inspector,
            INamingConventions naming,
            ResolverTypeBindingInfo binding)
        {
            var names = new HashSet <NameString>(
                binding.Fields.Select(t => t.FieldName));

            foreach (MemberInfo member in inspector.GetMembers(binding.ResolverType))
            {
                NameString fieldName =
                    naming.GetMemberName(member, MemberKind.ObjectField);
                if (names.Add(fieldName))
                {
                    var builder = ResolverFieldBindingBuilder.New();
                    builder.SetResolver(member);
                    builder.SetField(fieldName);
                    binding.Fields = binding.Fields.Add(builder.Create());
                }
            }
        }
コード例 #5
0
 /// <inheritdoc />
 public virtual NameString GetFieldName(MemberInfo member) =>
 _namingConventions.GetMemberName(member, MemberKind.InputObjectField);