Пример #1
0
        public UnionType()
        {
            UnionTypeDescriptor descriptor = new UnionTypeDescriptor(GetType());

            Configure(descriptor);

            if (string.IsNullOrEmpty(descriptor.Name))
            {
                throw new ArgumentException(
                          "A union type name must not be null or empty.");
            }

            if (descriptor.Types == null)
            {
                throw new ArgumentException(
                          "A union type must have a set of types.");
            }

            _typesFactory = r => descriptor.Types
                            .Select(t => t.TypeFactory(r))
                            .Cast <ObjectType>();
            _typeInfos    = descriptor.Types;
            _typeResolver = descriptor.ResolveAbstractType;

            Name        = descriptor.Name;
            Description = descriptor.Description;
        }
Пример #2
0
        protected override UnionTypeDefinition CreateDefinition(
            IInitializationContext context)
        {
            var descriptor = UnionTypeDescriptor.New(
                context.DescriptorContext);

            _configure(descriptor);
            return(descriptor.CreateDefinition());
        }
Пример #3
0
        protected override UnionTypeDefinition CreateDefinition(ITypeDiscoveryContext context)
        {
            var descriptor = UnionTypeDescriptor.New(
                context.DescriptorContext,
                typeof(T));

            _configure(descriptor);
            return(descriptor.CreateDefinition());
        }
Пример #4
0
        protected override UnionTypeDefinition CreateDefinition(
            ITypeDiscoveryContext context)
        {
            var descriptor = UnionTypeDescriptor.FromSchemaType(
                context.DescriptorContext,
                GetType());

            _configure(descriptor);
            return(descriptor.CreateDefinition());
        }
Пример #5
0
        private void Initialize(Action <IUnionTypeDescriptor> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            UnionTypeDescriptor descriptor = new UnionTypeDescriptor(GetType());

            configure(descriptor);
            Initialize(descriptor);
        }
Пример #6
0
        private void Initialize(Action <IUnionTypeDescriptor> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var descriptor = new UnionTypeDescriptor(GetType());

            configure(descriptor);

            UnionTypeDescription description = descriptor.CreateDescription();

            _types = description.Types;
            _resolveAbstractType = description.ResolveAbstractType;
            Name        = description.Name;
            Description = description.Description;
        }
Пример #7
0
        private void Initialize(UnionTypeDescriptor descriptor)
        {
            if (descriptor == null)
            {
                throw new ArgumentNullException(nameof(descriptor));
            }

            if (string.IsNullOrEmpty(descriptor.Name))
            {
                throw new ArgumentException(
                          "A union type name must not be null or empty.");
            }

            _types = descriptor.Types;
            _resolveAbstractType = descriptor.ResolveAbstractType;

            Name        = descriptor.Name;
            Description = descriptor.Description;
        }
Пример #8
0
        private void Initialize(Action <IUnionTypeDescriptor> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var descriptor = new UnionTypeDescriptor(GetType());

            configure(descriptor);

            UnionTypeDescription description = descriptor.CreateDescription();

            _types = description.Types;
            _resolveAbstractType = description.ResolveAbstractType;

            Initialize(description.Name, description.Description,
                       new DirectiveCollection(this,
                                               DirectiveLocation.Union,
                                               description.Directives));
        }