B
bowser
Hello,
I'm new to C# but so far I didn't find big problems, except for
Reflection. I coudn't find any good material in internet where to study
it. If anyone knows about some documents, blogs or stuff, please let me
know.
My problem is that I have to create a new instance of a class, given a
type and a name (object's id) as parameters. The constructor of such
type has no parameters.
Type t;
string id;
ConstructorInfo ci = t.GetConstructor(new Type[] { });
ci.Invoke(null); // this creates the instance but how to bind it to id?
// I know there's a class named Binder, but how do
I have to use it?
Obviously, trying:
t id = ci.Invoke(null);
is not correct for 2 reasons: t is used as a type, while it's a
variable; secondly id is a string, not an identifier.
I tried also Activator.CreateInstance(m_class): what's the different
between this and the previous way?
Finally I need to know if the id (that I have as string variable), is
already binding another object, so that I can change it to do my work.
Thank you in advance.
Alessandro
I'm new to C# but so far I didn't find big problems, except for
Reflection. I coudn't find any good material in internet where to study
it. If anyone knows about some documents, blogs or stuff, please let me
know.
My problem is that I have to create a new instance of a class, given a
type and a name (object's id) as parameters. The constructor of such
type has no parameters.
Type t;
string id;
ConstructorInfo ci = t.GetConstructor(new Type[] { });
ci.Invoke(null); // this creates the instance but how to bind it to id?
// I know there's a class named Binder, but how do
I have to use it?
Obviously, trying:
t id = ci.Invoke(null);
is not correct for 2 reasons: t is used as a type, while it's a
variable; secondly id is a string, not an identifier.
I tried also Activator.CreateInstance(m_class): what's the different
between this and the previous way?
Finally I need to know if the id (that I have as string variable), is
already binding another object, so that I can change it to do my work.
Thank you in advance.
Alessandro