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

**URL:** <https://discuss.elastic.co/t/how-to-clone-nest-string-ignore-attribute-for-my-own-method/70952>\
**Category:** Elasticsearch\
**Created:** [January 9, 2017, 2:49pm UTC](https://discuss.elastic.co/t/how-to-clone-nest-string-ignore-attribute-for-my-own-method/70952 "2017-01-09T14:49:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hhkx](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hhkx](https://discuss.elastic.co/u/hhkx)\
**Post date:** [January 9, 2017, 2:49pm UTC](https://discuss.elastic.co/t/how-to-clone-nest-string-ignore-attribute-for-my-own-method/70952/1 "2017-01-09T14:49:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hhkx](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hhkx](https://discuss.elastic.co/u/hhkx)\
**Post date:** [January 12, 2017, 7:14am UTC](https://discuss.elastic.co/t/how-to-clone-nest-string-ignore-attribute-for-my-own-method/70952/2 "2017-01-12T07:14:20Z")

</div>

Any help?

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [January 16, 2017, 11:31pm UTC](https://discuss.elastic.co/t/how-to-clone-nest-string-ignore-attribute-for-my-own-method/70952/3 "2017-01-16T23:31:28Z")

</div>

I commented on the [same question on StackOverflow](http://stackoverflow.com/questions/41550658/how-to-clone-nests-stringignore-attribute-for-my-own-method):

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](https://www.elastic.co/guide/en/elasticsearch/client/net-api/2.x/auto-map.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 13, 2017, 11:31pm UTC](https://discuss.elastic.co/t/how-to-clone-nest-string-ignore-attribute-for-my-own-method/70952/4 "2017-02-13T23:31:33Z")

</div>

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