Creating a ClassFactory but still have to perform explicit cast onreturn

D

Dan Holmes

I am trying to simplify my object creation code so i created a class
factory.

public class IAFClassFactory
{
public Object Create<T>()
{
Type t = typeof(T);
return (T)Activator.GetObject(t, "tcp://kit-dev:9988/" +
t.ToString());
}
}

This is the caller

ISystemMessage sm = (ISystemMessage)cf.Create<ISystemMessage>();

I would like to remove the explicit cast but i don't know how to create
the class factory create method so that i can return something other
than object.

I would like this

ISystemMessage sm = cf.Create<ISystemMessage>();

but if i leave it like that i get and error about needing an explicit cast.

dan
 
Y

Yury

public class IAFClassFactory
{
public T Create<T>()
{
Type t = typeof(T);
return (T)Activator.GetObject(t, "tcp://kit-dev:9988/" +
t.ToString());
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top