Exemple #1
0
        public override void OnBeforeCompleteName(ITypeCompletionContext context, DefinitionBase?definitionBase, IDictionary <string, object?> contextData)
        {
            if (definitionBase is not ObjectTypeDefinition definition)
            {
                return;
            }

            if (definition.RuntimeType.IsSubclassOf(typeof(BaseEntity)))
            {
                foreach (PropertyInfo property in definition.RuntimeType.GetProperties())
                {
                    if (property.PropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(property.PropertyType) && property.PropertyType != typeof(NpgsqlTsVector))
                    {
                        ObjectFieldDefinition fieldDefinition = definition.Fields.First(e => e.Name == context.DescriptorContext.Naming.GetMemberName(property, MemberKind.ObjectField));
                        ObjectFieldDescriptor fieldDescriptor = ObjectFieldDescriptor.From(context.DescriptorContext, fieldDefinition);

                        fieldDescriptor
                        .UseSorting()
                        .UseFiltering();

                        int index = definition.Fields.IndexOf(fieldDefinition);
                        definition.Fields.RemoveAt(index);
                        definition.Fields.Insert(index, fieldDescriptor.CreateDefinition());
                    }
                }
            }
        }
    protected ObjectTypeDescriptor(
        IDescriptorContext context,
        ObjectTypeDefinition definition)
        : base(context)
    {
        Definition = definition ?? throw new ArgumentNullException(nameof(definition));

        foreach (ObjectFieldDefinition field in definition.Fields)
        {
            Fields.Add(ObjectFieldDescriptor.From(Context, field));
        }
    }
Exemple #3
0
        public override void OnBeforeCompleteName(ITypeCompletionContext context, DefinitionBase?definitionBase, IDictionary <string, object?> contextData)
        {
            if (definitionBase is ObjectTypeDefinition objectTypeDefinition)
            {
                if (objectTypeDefinition.RuntimeType.IsSubclassOf(typeof(BaseEntity)))
                {
                    PropertyInfo idProperty = objectTypeDefinition.RuntimeType.GetProperty(nameof(BaseEntity.Id)) !;

                    ObjectFieldDefinition fieldDefinition = objectTypeDefinition.Fields.First(e => e.Name == context.DescriptorContext.Naming.GetMemberName(idProperty, MemberKind.ObjectField));
                    ObjectFieldDescriptor fieldDescriptor = ObjectFieldDescriptor.From(context.DescriptorContext, fieldDefinition);

                    fieldDescriptor
                    .IsProjected(true);

                    int index = objectTypeDefinition.Fields.IndexOf(fieldDefinition);
                    objectTypeDefinition.Fields.RemoveAt(index);
                    objectTypeDefinition.Fields.Insert(index, fieldDescriptor.CreateDefinition());
                }

                return;
            }
        }
 public static ObjectFieldDescriptor ToDescriptor(
     this ObjectFieldDefinition definition,
     IDescriptorContext context)
 => ObjectFieldDescriptor.From(context, definition);