How to use local variable as a type? Compiler says "it is a variable but is used like a type"
You were very close, you were just missing a call to MakeGenericType
.
I believe your code would look like the following:
Type t1 = v1.GetType().GetProperty("Value").PropertyType;
var shellPropertyType = typeof(ShellProperty<>);
var specificShellPropertyType = shellPropertyType.MakeGenericType(t1);
dynamic v2 = specificShellPropertyType.GetProperty("Value").GetValue(v1, null);
Edit: As @PetSerAl pointed out I added some layers of indirection that were unnecessary. Sorry OP, you probably want a one liner like:
dynamic v2 = v1.GetType().GetProperty("Value").GetValue(v1, null);
For generics, you have to create them dynamically.
MethodInfo method = typeof(Sample).GetMethod("GenericMethod");
MethodInfo generic = method.MakeGenericMethod(myType);
generic.Invoke(this, null);
To create a generic object, you can
var type = typeof(ShellProperty<>).MakeGenericType(typeof(SomeObject));
var v2 = Activator.CreateInstance(type);
Please refer to Initializing a Generic variable from a C# Type Variable