C# Reflection Notes
Below are some useful code snippets when using reflection in c#
How to pass in Parameters into an Activator
(T)Activator.CreateInstance(typeof(T), param1, param2);
Get a property value from a string
- Snippet from Stack Overflow
- Another example from Stack Overflow
var value = (string)GetType().GetProperty("SomeProperty").GetValue(this, null);
Get all types that are in a namespace
- From Stack Overflow
var q = from t in Assembly.GetExecutingAssembly().GetTypes()
where t.IsClass && t.Namespace == @"my.namespace"
select t;
q.ToList().ForEach(t => Console.WriteLine(t.Name));
how-to-dynamically-create-generic-c-sharp-object-using-reflection
Dynamically created a generic c# object
- From Stack Overflow
var d1 = typeof(Task<>);
Type[] typeArgs = { typeof(Item) };
var makeme = d1.MakeGenericType(typeArgs);
object o = Activator.CreateInstance(makeme);