add smartpart using variable

Topics: CAB & Smart Client Software Factory
Nov 14, 2007 at 1:52 PM
string strView="mycustomview";

WorkItem.SmartParts.AddNew<strView>;

can achieve this?

regards
hemant

Nov 14, 2007 at 6:46 PM
Hi

It can be achieved, but remember that the AddNew method is a Generic method, what you put between ‘<’ and ‘>’ is a type. You may try to reflect the type and then call the AddNew method passing the Type as a parameter.

The code should look like this:
Type myType = System.Type.GetType("SmartPartOnStringRequest.Module1.View1");
 
if (myType != null)
    WorkItem.SmartParts.AddNew(myType);
Note: The GetType method takes the class’ full name as a parameter.

Please let me know if this helps.

Ignacio Baumann Fonay
http://staff.southworks.net/blogs/ibaumann/
Nov 15, 2007 at 10:00 AM
Hi,

Thanks for reply.
But the statement Type myType = System.Type.GetType("SmartClientApp.AdminModule.MenuView");
always returns NULL.

regards
Hemant


ibaumann wrote:
Hi

It can be achieved, but remember that the AddNew method is a Generic method, what you put between ‘<’ and ‘>’ is a type. You may try to reflect the type and then call the AddNew method passing the Type as a parameter.

The code should look like this:
Type myType = System.Type.GetType("SmartPartOnStringRequest.Module1.View1");
 
if (myType != null)
    WorkItem.SmartParts.AddNew(myType);
Note: The GetType method takes the class’ full name as a parameter.

Please let me know if this helps.

Ignacio Baumann Fonay
http://staff.southworks.net/blogs/ibaumann/

Nov 15, 2007 at 4:06 PM
Hi, Hemant

Try replacing the FullName with the AssemblyQualifiedName. Now, that line should look like this:

Type myType = System.Type.GetType("SmartPartOnStringRequest.Module1.View1, Module1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
Please let me know if this helps.

Ignacio Baumann Fonay
http://staff.southworks.net/blogs/ibaumann/