-4

I have class like this:

public class Class1
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

Now I have another string list from somewhere and want to load it dynamically to be the public properties of Class1 when my application launch, how can i do?

string list like:

  • Email
  • Telephone
  • Homepage

load them as public properties of Class1 in run time.

GBK
  • 375
  • 2
  • 4
  • 11
  • 1
    attempt to solve by the use of code.... – T McKeown Apr 29 '15 at 01:29
  • Take a look at dynamic objects or at reflection. You can use some external library for quick start. Like one decribed in this question: http://stackoverflow.com/questions/15819720/dynamically-add-c-sharp-properties-at-runtime – balbelias Apr 29 '15 at 01:32
  • What do you mean with "another string list" and how would you want to map what is in a list of strings to the properties of (an) instance(s) of `Class1` ? What are you trying to achieve. Please [edit] your question to add the relevant details. Currently your question is unclear. Please refer to [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) – Alex Apr 29 '15 at 01:36

1 Answers1

0

You can use ExpandoObject.

If you want to have this dynamic properties in addition to the non-dynamic properties, here is an article explaining how to create a dynamic object yourself.

motcke
  • 438
  • 6
  • 17