# Get field name attribute from C# Nest POCO property

**URL:** <https://discuss.elastic.co/t/get-field-name-attribute-from-c-nest-poco-property/85287>\
**Category:** Elasticsearch\
**Created:** [May 10, 2017, 5:01pm UTC](https://discuss.elastic.co/t/get-field-name-attribute-from-c-nest-poco-property/85287 "2017-05-10T17:01:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Treher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/justin_treher/32/45243_2.png) [@Justin\_Treher](https://discuss.elastic.co/u/Justin_Treher)\
**Post date:** [May 10, 2017, 5:01pm UTC](https://discuss.elastic.co/t/get-field-name-attribute-from-c-nest-poco-property/85287/1 "2017-05-10T17:01:24Z")

</div>

I'm writing a unit tests to verify filters are or are not present in the query based on various conditional logic. To test that my logic is working, I'm getting the request JSON from a mocked up in memory client. All this is working just fine.

What I'm stumbling on is that I don't want to hard code the name of the field that must be present in the JSON, I want to use the strongly typed attribute that is assigned to POCOs. However, I can't figure out a way to access the attribute outside of a query.

In sum, I want to be able to to something like this where I'm getting something from the field inference that I can use in the assertion.

```
Infer.Field<Product>(f => f.ColorIsNeutral);// how can I access the json name attribute from the field?

 Assert.Contains("color_is_neutral", requestJson); // I don't want this "magic string" in the assertion
```

---

<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:** [June 7, 2017, 5:06pm UTC](https://discuss.elastic.co/t/get-field-name-attribute-from-c-nest-poco-property/85287/2 "2017-06-07T17:06:49Z")

</div>

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