views:

30

answers:

1

My error code:

string model = "Content";
Type stype = Type.GetType("mvc.Models." + model);
ViewPage<stype> vp = new ViewPage<stype>();

Of course it error when compiling, but it clearly show what i'm thinking. Can i do this?

+2  A: 

That function GetType needs an assembly-qualified name, not just the namespace as you have provided.

cottsak
I don't think so, because i can do this without errorModels.Content c = (Models.Content)Type.GetType("mvc.Models.RSSContent").InvokeMember("", BindingFlags.CreateInstance, null, null, null);RSSContent inherit from Content
complez
I'm not certain but what you are trying to do may be outside the scope of the language constructs. It seems that when you code literally the Type, whether as a type dec or a explicit cast, it seems to work. I suspect the compiler does not like defining an explicit Type from a runtime evaluated type variable and that is why you get the build message.
cottsak