471,315 Members | 2,241 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

Creating a ClassFactory but still have to perform explicit cast onreturn

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
Feb 22 '06 #1
1 1063
public class IAFClassFactory
{
public T Create<T>()
{
Type t = typeof(T);
return (T)Activator.GetObject(t, "tcp://kit-dev:9988/" +
t.ToString());
}

}

Feb 22 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stub | last post: by
9 posts views Thread by Tanmoy Bhattacharya | last post: by
reply views Thread by Reece Hart | last post: by
687 posts views Thread by cody | last post: by
31 posts views Thread by Michael C | last post: by
17 posts views Thread by arnuld | last post: by
3 posts views Thread by daokfella | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.