Skip to content

Conversation

@erictuvesson
Copy link
Member

Input:

namespace Mallos.Searchable.Test
{
    using Mallos.Searchable.Attributes;
    using System;

    [FilterGenerator("MyGeneratedSearchable")]
    public class TestObject
    {
        [FilterKey("v"), FilterStringMatch(FilterMatchType.Match)]
        [FilterKey("value"), FilterStringMatch(FilterMatchType.Contains, StringComparison.OrdinalIgnoreCase)]
        public string Value { get; set; }

        [FilterKey("key"), FilterStringMatch()]
        public string Key { get; set; }

        public TestObject(string value)
        {
            this.Value = value;
        }
    }
}

Generated Output:

using Mallos.Searchable;
using Mallos.Searchable.Attributes;
using System;
using System.Collections.Generic;
using Mallos.Searchable.Test;

public class MyGeneratedSearchableFilter_FilterStringMatch_v : SimpleFilter<TestObject> 
{
    public override string Key => "v";

    protected override bool Check(TestObject item, string value)
    {
        return Mallos.Searchable.Attributes.FilterStringMatchAttribute.Execute(
            item.Value,
            value,
            FilterMatchType.Match
        );
    }
}

public class MyGeneratedSearchableFilter_FilterStringMatch_value : SimpleFilter<TestObject> 
{
    public override string Key => "value";

    protected override bool Check(TestObject item, string value)
    {
        return Mallos.Searchable.Attributes.FilterStringMatchAttribute.Execute(
            item.Value,
            value,
            FilterMatchType.Contains,
            StringComparison.OrdinalIgnoreCase
        );
    }
}

public class MyGeneratedSearchableFilter_FilterStringMatch_key : SimpleFilter<TestObject> 
{
    public override string Key => "key";

    protected override bool Check(TestObject item, string value)
    {
        return Mallos.Searchable.Attributes.FilterStringMatchAttribute.Execute(
            item.Key,
            value
        );
    }
}

public class MyGeneratedSearchable : Searchable<TestObject> 
{
    public MyGeneratedSearchable()
    {
        Filters.Add(new MyGeneratedSearchableFilter_FilterStringMatch_v());
        Filters.Add(new MyGeneratedSearchableFilter_FilterStringMatch_value());
        Filters.Add(new MyGeneratedSearchableFilter_FilterStringMatch_key());
    }

    protected override IEnumerable<TestObject> FreeTextFilter(
        IEnumerable<TestObject> values, bool negative, string text)
    {
        return base.FreeTextFilter(values, negative, text);
    }
}


<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
Copy link
Member Author

@erictuvesson erictuvesson Apr 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to solve the issue where the Mallos.Searchable.CodeAnalyzer project can reference this by only netstandard2.0.

I would like to add .NET 5 support here too, to be able to work with records.


public SearchableSyntaxReceiver()
{
this.filterAttributes = ReflectionHelper.AllOfType<FilterBaseAttribute>().ToList();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to be able to remove this, then we don't have to depend on Mallos.Searchable project.

But how can it work without using Reflection if we don't know more about the syntax?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants