mercredi 14 juin 2017

Change Custom Attribute Value On Property Of Instantiated C# Class

I have the following class

public class IndexData
{
    [CustomAttribute(Constants.SomeStringName)]
    public string Title { get; set; }

    [CustomAttribute(Constants.AnotherStringName)]
    public string Description { get; set; }
}

I want to be able to change the values (The string value) of [CustomAttribute(string)] in an instantiated version of the class. A simplified version of what I am trying to acheive would be.

var indexData = new IndexData();

if(SomeCriteria){

  // Need to change the attribute value here
  // indexData.Title.CustomAttribute.Value = "SomethingElse"
}

// Continue with data mapping
indexData.Title = "Something"

I can't change the attribute as it's a custom attribute from another API (Azure Search). So I need a way of changing the values of the attributes after I have instantiated the class.

As there may be several different criteria. Hope that makes sense? And any help/guidance would be appreciated.





Aucun commentaire:

Enregistrer un commentaire