Example #1
0
        public IInterfaceFieldDescriptor Field(NameString name)
        {
            var fieldDescriptor = new InterfaceFieldDescriptor(
                Context,
                name.EnsureNotEmpty(nameof(name)));

            Fields.Add(fieldDescriptor);
            return(fieldDescriptor);
        }
Example #2
0
        protected InterfaceTypeDescriptor(
            IDescriptorContext context,
            InterfaceTypeDefinition definition)
            : base(context)
        {
            Definition = definition ?? throw new ArgumentNullException(nameof(definition));

            foreach (InterfaceFieldDefinition field in definition.Fields)
            {
                Fields.Add(InterfaceFieldDescriptor.From(Context, field));
            }
        }
        public IInterfaceFieldDescriptor Field(
            Expression <Func <T, object> > propertyOrMethod)
        {
            if (propertyOrMethod is null)
            {
                throw new ArgumentNullException(nameof(propertyOrMethod));
            }

            MemberInfo member = propertyOrMethod.ExtractMember();

            if (member is PropertyInfo || member is MethodInfo)
            {
                InterfaceFieldDescriptor fieldDescriptor =
                    Fields.FirstOrDefault(t => t.Definition.Member == member);
                if (fieldDescriptor is { })
        public IInterfaceFieldDescriptor Field(NameString name)
        {
            InterfaceFieldDescriptor fieldDescriptor =
                Fields.FirstOrDefault(t => t.Definition.Name.Equals(name));

            if (fieldDescriptor is not null)
            {
                return(fieldDescriptor);
            }

            fieldDescriptor = InterfaceFieldDescriptor.New(
                Context,
                name.EnsureNotEmpty(nameof(name)));
            Fields.Add(fieldDescriptor);
            return(fieldDescriptor);
        }
        protected override void OnCompleteFields(
            IDictionary <NameString, InterfaceFieldDefinition> fields,
            ISet <MemberInfo> handledMembers)
        {
            if (Definition.Fields.IsImplicitBinding())
            {
                FieldDescriptorUtilities.AddImplicitFields(
                    this,
                    p => InterfaceFieldDescriptor
                    .New(Context, p)
                    .CreateDefinition(),
                    fields,
                    handledMembers);
            }

            base.OnCompleteFields(fields, handledMembers);
        }
        public IInterfaceFieldDescriptor Field(
            Expression <Func <T, object> > propertyOrMethod)
        {
            if (propertyOrMethod == null)
            {
                throw new ArgumentNullException(nameof(propertyOrMethod));
            }

            MemberInfo member = propertyOrMethod.ExtractMember();

            if (member is PropertyInfo || member is MethodInfo)
            {
                var fieldDescriptor = new InterfaceFieldDescriptor(
                    Context, member);
                Fields.Add(fieldDescriptor);
                return(fieldDescriptor);
            }

            throw new ArgumentException(
                      "A field of an entity can only be a property or a method.",
                      nameof(propertyOrMethod));
        }