2
var mystring = "MyCompany.MyType.Localization.Strings.MyString"

In C#, is there a way I could fill it up such that

var abc = GetReflectedValue(mystring);

Is reflection the only way? (how?) Or any more efficient ways?

user477470
  • 33
  • 3
  • 1
    possible duplicate of [Is there an easy way to get Type object from C# type name](http://stackoverflow.com/questions/3929026/is-there-an-easy-way-to-get-type-object-from-c-type-name) – BrunoLM Oct 16 '10 at 02:11
  • what are you actually trying to do here? Load locale based strings? – Mitch Wheat Oct 16 '10 at 05:27
  • I have a string, "MyCompany.MyClass", it's static, it has a property on it called "Foo". I want to call "MyCompany.Class"'s "Foo" property. I have all of this provided as user input, not in code. – user477470 Oct 16 '10 at 05:46

1 Answers1

0

It's not 100% clear what you are trying to do. Do you mean create an instance of an object given only it's string type name? If so, use Activator.CreateInstance:

var item = Activator.CreateInstance(Type.GetType(mystring));
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • Type.GetType() keeps saying null, it seems like my shared dll may not be loaded. Does my assembly need to be loaded for this to work? – user477470 Oct 16 '10 at 04:54