473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 4929
=?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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Jason Tesser | last post by:
I work for at a college where I am one of 2 full-time developers and we are looking to program a new software package fro the campus. This is a huge project as it will include everything from...
5
by: Radde | last post by:
HI, Are ther any pitfalls for dynamic cast in type safe downcasting..
2
by: Zac | last post by:
Alright anyone who has 2c throw it in... I am working through a custom xml serializer and have come upon a conundrum, given our class design. The interface implemented on the base class (base...
2
by: Martin Hart - Memory Soft, S.L. | last post by:
Hi all: I still very new to the .NET world and don't know if what I am asking is due to an over-imaginative imagination or the fact that I have read too many fiction books!! Let me show you a...
6
by: Philipp Schumann | last post by:
Hi, I have a need for "dynamic type casting": in other words, in a "MyConvert" method I get passed an Object "value" and a Type "type" and the method should attempt to convert value into type. ...
4
by: Zark3 | last post by:
Hi all, I was wondering if anybody could enlighten me on the possibility of dynamic casting. Or, well, whether or not I'm actually trying to do this the right way. What I have is a base class...
2
by: Mike Stevenson | last post by:
Hi. I'm in the process of re-learning all the C++ I forgot from college, and I'm starting to get into some virgin (or at least only a couple times) territory. I have some questions about casting...
6
by: DaTurk | last post by:
Hi, I have three interfaces lets call them parent, child-A, and child-B. I want to have one variable, that can be either child-A, or child-B at run time. I just can't seem to figure out how to...
28
by: hlubenow | last post by:
Hello, I really like Perl and Python for their flexible lists like @a (Perl) and a (Python), where you can easily store lots of strings or even a whole text-file. Now I'm not a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.