How to clone Nest [String(Ignore)] attribute for my own method

Hi,

I am trying to clone [String(Ignore)] attribute of Nest for my own method that saves process logs. I have already done something but it doesn't work.

Basically, what I would like to do is, I'd like to create a custom attribute that will provide me to choose if to save property to the elasticsearch or not.

So, I have a SaveUserProcessLog method.
Then I create a custom attribute named as MyProcessLogDetailAttribute and inherited from nest's StringAttribute:

    [AttributeUsage(AttributeTargets.Property)]
public class MyUserProcessLogDetailAttribute : StringAttribute
{
    public MyUserProcessLogDetailAttribute(bool SaveProperty)
    {
        Ignore = !SaveProperty; //when true ignore is false
    }
}

And I am adding this attribute to the properties which I want to be saved in.

[MyUserProcessLogDetail(SaveProperty:false)]
public Guid UserCode { get; set; }

[MyUserProcessLogDetail(SaveProperty:false)]
public string FullName { get; set; }

Is inheriting from Nest's attribute approach right?

Why am I not using the original [String(Ignore=false/true)] attribute of Nest is because I may want to create a new attribute to save property for another method. For instance, don't save UserCode for UserProcessLog() method but save for SaveUserAmendments().

I hope I have been clear about this.

Thanks for your help in advance.

Any help?

I commented on the same question on StackOverflow:

I'm not seeing what this is buying you over simply using [String(Ignore=true)]? For your derived attribute, you still need to pass true/false so it semantically works the same as StringAttribute.

If you have two models with the same properties that must be mapped differently then I would use fluent mapping for them rather than attributes. Take a look at https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/auto-map.html

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.