Re: problems typecast,find by function/member name and getting "managed reference"
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Tue, 26 Sep 2006 07:35:47 +0100
SunnyDrake <sunnydrake@xxxxx> wrote:
Jon ???????:
The normal way to overcome this is to use an interface if possible.
and then use Runtime.InteropServices._Type.GetInterface Method (String)
?
No, and then call methods in the interface.
it's Net 2.0 :( and i need to add interface for each class and then add
functions to get variables :(. And interface will be a weak side of
design.
I guess it depends on the exact situation - but I would *generally*
rather see a "strongly called" interface member than futz around with
reflection. It does depend though.
Otherwise, you'll need to use reflection to get the appropriatethanks it's was a great help!.
MethodInfo and invoke it.
I *think* you're basically asking for reflection here, but I'm not
sure. Here's a sample program if you are:
static void CallMethod (Type type, object target,
string methodName)
{
MethodInfo method = type.GetMethod(methodName);
// The "null" here is because we're assuming
// the method has no parameters
method.Invoke (target, null);
}
now i only need find a way to get object by its name in string..
Objects don't have names. What exactly do you mean?
and still i'm not found a good solution to dynamicaly
typecast(unboxing) any *unknown type* to object at runtime.
Hang on - casting and unboxing are very different things. Casting at
runtime doesn't make sense because the point of casting is to give the
*compiler* more information, which clearly isn't relevant at runtime.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- References:
- problems typecast,find by function/member name and getting "managed reference"
- From: SunnyDrake
- Re: problems typecast,find by function/member name and getting "managed reference"
- From: Jon Skeet [C# MVP]
- Re: problems typecast,find by function/member name and getting "managed reference"
- From: SunnyDrake
- problems typecast,find by function/member name and getting "managed reference"
- Prev by Date: Re: Register a c# class
- Next by Date: Re: Truncating a Stream...
- Previous by thread: Re: problems typecast,find by function/member name and getting "managed reference"
- Next by thread: Re: problems typecast,find by function/member name and getting "managed reference"
- Index(es):
Relevant Pages
|
Loading