I\'ve read few posts, and I\'m still having troubles with adding properties to a class in runtime. It should be simple, because I have a class like this:
pub
I don't think adding a property is the right thing to do here.
The attributes like "Email" or "Phone" are just some additional pairs of a key and a value. You could use a Dictionary
, but that would prevent you from using a key more than once (more than one email address for a contact for example). So you could just as well use a List
. Like that:
public class MyClass
{
String Template;
String Term;
public List> Attributes { get; private set; }
public MyClass() {
Attributes = new List();
}
public void AddAttribute(string key, string value) {
Attributes.Add(new KeyValuePair(key, value));
}
}
// to be used like this:
MyClass instance = new MyClass();
instance.AddAttribute("Email", "test@example.com");
instance.AddAttribute("Phone", "555-1234");