469,626 Members | 889 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

Dynamic casting

Val
Hi

I am using a DynamicProxy (class that inherits from RealProxy). I don't know the type of my Transparant Proxy at compile time. Is there a possibility to have a dynamic casting

object[] correctParams = new object[x]
for(int i...

Type t = Type.GetType(tiB.GetTypeName())
DynamicProxy proxy = new DynamicProxy(t, orderedParams[i], tiA)
correctParams[i] = /*TODO: CAST into type t*/ proxy.GetTransparentProxy()
I would like to cast the result of proxy.GetTransparentProxy() into the type t. Is it possible

Thanks a lo
Valéry Bezençon
Nov 15 '05 #1
4 4710
=?Utf-8?B?VmFs?= <an*******@discussions.microsoft.com> wrote:
I am using a DynamicProxy (class that inherits from RealProxy).
I don't know the type of my Transparant Proxy at compile time.
Is there a possibility to have a dynamic casting?

object[] correctParams = new object[x];
for(int i...)
{
Type t = Type.GetType(tiB.GetTypeName());
DynamicProxy proxy = new DynamicProxy(t, orderedParams[i], tiA);
correctParams[i] = /*TODO: CAST into type t*/ proxy.GetTransparentProxy();
}

I would like to cast the result of proxy.GetTransparentProxy()
into the type t. Is it possible?


What difference would it make? correctParams is just an array of object
references - why would you need to cast the reference?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
val


----- Jon Skeet [C# MVP] wrote: ----

=?Utf-8?B?VmFs?= <an*******@discussions.microsoft.com> wrote
I am using a DynamicProxy (class that inherits from RealProxy).
I don't know the type of my Transparant Proxy at compile time.
Is there a possibility to have a dynamic casting
object[] correctParams = new object[x]

for(int i...

Type t = Type.GetType(tiB.GetTypeName())
DynamicProxy proxy = new DynamicProxy(t, orderedParams[i], tiA)
correctParams[i] = /*TODO: CAST into type t*/ proxy.GetTransparentProxy()
I would like to cast the result of proxy.GetTransparentProxy()

into the type t. Is it possible


What difference would it make? correctParams is just an array of object
references - why would you need to cast the reference

I need to use the methods contained in the Type t on the objects of correctParams in the rest of the code. If these object are just object, I will only be able to use the methods of the class object (GetType, GetHashCode, ...

Nov 15 '05 #3
[Please fix your newsreader to wrap text at about 72 columns - your
current long lines make it a pain to reply to you.]

=?Utf-8?B?dmFs?= <an*******@discussions.microsoft.com> wrote:
What difference would it make? correctParams is just an array
of object references - why would you need to cast the reference?

I need to use the methods contained in the Type t on the objects of
correctParams in the rest of the code. If these object are just
object, I will only be able to use the methods of the class object
(GetType, GetHashCode, ...)


But casting where you suggested casting wouldn't do you any good
anyway. Actually, it would check that the cast it valid, but that's
all.

If you don't know the type in advance, you won't be able to use the
methods in your code anyway, will you? If you know that the type will
have certain methods, then build an interface with those methods, make
the type implement those methods, and cast to the interface when you
need to.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
val


----- Jon Skeet [C# MVP] wrote: ----

[Please fix your newsreader to wrap text at about 72 columns - your
current long lines make it a pain to reply to you.

=?Utf-8?B?dmFs?= <an*******@discussions.microsoft.com> wrote
What difference would it make? correctParams is just an array
of object references - why would you need to cast the reference
I need to use the methods contained in the Type t on the objects of

correctParams in the rest of the code. If these object are jus
object, I will only be able to use the methods of the class object
(GetType, GetHashCode, ...


But casting where you suggested casting wouldn't do you any good
anyway. Actually, it would check that the cast it valid, but that's
all

If you don't know the type in advance, you won't be able to use the
methods in your code anyway, will you? If you know that the type will
have certain methods, then build an interface with those methods, make
the type implement those methods, and cast to the interface when you
need to

Yes, you are right, I was a little bit confused. Thanks for your hel
Valéry
Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Jason Tesser | last post: by
5 posts views Thread by Radde | last post: by
2 posts views Thread by Zac | last post: by
2 posts views Thread by Martin Hart - Memory Soft, S.L. | last post: by
6 posts views Thread by Philipp Schumann | last post: by
4 posts views Thread by Zark3 | last post: by
2 posts views Thread by Mike Stevenson | last post: by
6 posts views Thread by DaTurk | last post: by
28 posts views Thread by hlubenow | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.