473,569 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ti B.GetTypeName() )
DynamicProxy proxy = new DynamicProxy(t, orderedParams[i], tiA)
correctParams[i] = /*TODO: CAST into type t*/ proxy.GetTransp arentProxy()
I would like to cast the result of proxy.GetTransp arentProxy() into the type t. Is it possible

Thanks a lo
Valéry Bezençon
Nov 15 '05 #1
4 4947
=?Utf-8?B?VmFs?= <an*******@disc ussions.microso ft.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(ti B.GetTypeName() );
DynamicProxy proxy = new DynamicProxy(t, orderedParams[i], tiA);
correctParams[i] = /*TODO: CAST into type t*/ proxy.GetTransp arentProxy();
}

I would like to cast the result of proxy.GetTransp arentProxy()
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.co m>
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*******@disc ussions.microso ft.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(ti B.GetTypeName() )
DynamicProxy proxy = new DynamicProxy(t, orderedParams[i], tiA)
correctParams[i] = /*TODO: CAST into type t*/ proxy.GetTransp arentProxy()
I would like to cast the result of proxy.GetTransp arentProxy()

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*******@disc ussions.microso ft.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.co m>
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*******@disc ussions.microso ft.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
2158
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 registration to business office. We are considering useing Java or Python. I for one don't like Java because I feel the GUI is clunky. I also think...
5
8004
by: Radde | last post by:
HI, Are ther any pitfalls for dynamic cast in type safe downcasting..
2
2558
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 for all business entities) dictates that the implementing class expose a Dirty property (for state). The base class (that actually manages state,...
2
673
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 very basic scenario: using System;
6
6385
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. Of course it first tries to obtain the appropriate TypeConverter. However, for some types there are no applicable type converters. Consider a...
4
2194
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 that several classes inherit from. From time to time I need to add new inherited types so I want something that is as versatile as possible,...
2
461
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 a pointer from a base class to a derived class. For example: class Base{ public: Base() {} virtual ~Base() {} void func1(int);
6
4084
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 do it. They both inherit from parent, and I tried holding a parent variable, and then casting it down to either of the children, but I can't see...
28
6016
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 C-professional, just a hobby-programmer trying to teach it myself. I found C rather difficult without those lists (and corresponding string-functions). Slowly...
0
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.