I have two subclasses of SpriteModel (1) LocalSprite (2)Sprite
Both implement a method called .ToXml() which returns an XmlDocument. But
they are different.
I instances of these objects stored in a Hashtable. Extracting them from the
Hashtable means that I get a object that is tentatively an instance of Class
Object (or Type Object to use the correct C# word).
I can HARD cast the object to a SpriteModel, and then invoke the .ToXml()
method, but if either of these sublcasses overrides or NEWs the default
method in SpriteModel. I can't get to it.
What I want to do is dynamically cast the object extracting from the
Hashtable to it's .GetType
realType = spriteList.Valu e.GetType()
and then do something like a dynamic cast (realType)sprit eList.Value
Obviously, this is very wrong syntacically, but there most be something that
is kosher that does the same effect? right? I don't have to resort to
Reflection and P/Invoke do I?
public override string ToString()
{
StringBuilder response = new StringBuilder() ;
lock (this.spriteTab le) {
IDictionaryEnum erator spriteList = this.spriteTabl e.GetEnumerator ();
while (spriteList.Mov eNext())
{
SpriteModel sprite = (SpriteModel)sp riteList.Value;
response.Append (Tools.PrettyPr int(sprite.ToXm l().DocumentEle ment));
response.Append ("\r\n");
}
}
return response.ToStri ng();
}
Nov 15 '05
10 5768
[This followup was posted to microsoft.publi c.dotnet.framew ork and a
copy was sent to the cited author.]
In article <OC************ **@TK2MSFTNGP11 .phx.gbl>, sg********@hotm ail.com says... To put this in TCL/TK or Smalltalk way of speaking I am looking for the equivelent of
(random object).perform Method("named method")
I.e. I want to invoke methods dynamically at run-time
Assume I already did the checking that this method is implemented by the object, so that I don't get a run-time error
[Yes, I am not a fan of 100% rigidly hard-typed systems, since there are times where one needs to get around this]
In my opinion Frank Oquendo's response is in the correct track. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sebastian Faust |
last post by:
Hi,
I am thinking now for a while about a design decision. I would be glad if
you can give me some advices which is maybe the better way for solving my
problem.
I wanna do something like described in the Bridge-Pattern. Therefore I have
the following classes:
Instrument
InstrumentImpl
InstrumentData
|
by: Leslaw Bieniasz |
last post by:
Cracow, 20.10.2004
Hello,
As far as I understand, the generic programming basically consists
in using templates for achieving a static polymorphism of the
various code fragments, and their reuse for various template
parameters. I wonder if there exist techniques for achieving
a dynamic polymorphism using the generic programming. Is this
possible? If yes, can anyone show me simple examples in C++
|
by: Denon |
last post by:
My system has some network interconnecting data, like node 1 <-> node 2
How to dynamic build a circuit diagram in from of (pdf,visio, or other
graphical format)by ASP.NET?
Thanks for your advice!
Den
|
by: rwf_20 |
last post by:
I just wanted to throw this up here in case anyone smarter than me has
a suggestion/workaround:
Problem:
I have a classic producer/consumer system which accepts 'commands' from
a socket and 'executes' them. Obviously, each different command (there
are ~20 currently) has its own needed functionality. The dream goal
here would be to remove all knowledge of the nature of the command at
runtime. That is, I don't want ANY switch/cases...
|
by: Krivenok Dmitry |
last post by:
Hello all!
Perhaps the most important feature of dynamic polymorphism is
ability to handle heterogeneous collections of objects.
("C++ Templates: The Complete Guide" by David Vandevoorde
and Nicolai M. Josuttis. Chapter 14.)
How to implement analogue of this technique via static polymorphism?
Perhaps there is special design pattern for this purpose...
| |
by: Risen |
last post by:
Hi, How to Dynamic adjust Button's Font property? Thx.
|
by: =?Utf-8?B?Sm9l?= |
last post by:
how to dynamic assign two dimensions array size
say
Dim myArray(x, y) as Integer
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |