I have a generalized delegate,
Public Delegate Function DataRetreivingD elegate() as Object
with an associated property in a certain class. Almost never will I actually
be wanting to set the property of this delegate type to a method that
returns an Object - rather I want to point it to methods that will be
returning strings, integers, decimals, whatever.
So I tried this -
Public Shared Function GetSomething() as String
End Function
DirectCast(Addr essOf GetSomething, DataRetreivingD elegate)
Only this doesn't work. Why doesn't the Framework allow method signature
return types to be up-casted?
Anyway, what's the best way around this without having to physically code
additional methods that return Objects? I know I can just use a raw
MethodInfo, but I don't want to complicate this any more than I have to
since performance will be a consideration.
TIA,
Paul 1 1090
Hi,
If you are using vb 2005 try this.
Public Delegate Function DataRetreivingD elegate(Of T)() As T
Public Function GetSomething() As String
Return "test"
End Function
Dim d As New DataRetreivingD elegate(Of String)(Address Of
GetSomething)
Label1.Text = d.Invoke()
Ken
---------------------
"PJ6" <no***@nowhere. net> wrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. .. I have a generalized delegate,
Public Delegate Function DataRetreivingD elegate() as Object
with an associated property in a certain class. Almost never will I actually be wanting to set the property of this delegate type to a method that returns an Object - rather I want to point it to methods that will be returning strings, integers, decimals, whatever.
So I tried this -
Public Shared Function GetSomething() as String
End Function
DirectCast(Addr essOf GetSomething, DataRetreivingD elegate)
Only this doesn't work. Why doesn't the Framework allow method signature return types to be up-casted?
Anyway, what's the best way around this without having to physically code additional methods that return Objects? I know I can just use a raw MethodInfo, but I don't want to complicate this any more than I have to since performance will be a consideration.
TIA, Paul This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tim Werth |
last post by:
I am trying to use reflection to add an event handler for the RowUpdated
event of the OracleDataAdapter object (ODP.NET), but the same thing can be
said for SqlDataAdapter if you only use reflection. The code I supplied is
based on the SqlDataAdapter with reflection.
The error occurs when trying to create the delegate that will be passed in
to EventInfo.AddEventHandler. I get the following error:
An unhandled exception of type...
|
by: Ondrej Sevecek |
last post by:
Hello,
what is the difference between "event" and the only use of delegate? Why
one should note events with "event" keyword when the functionality seems the
same as with pure delegates?
When I call some delegate, in which thread this delegate gets called -
callers = synchronous, or some other thread = asynchronous? And in what
thread is this done with "event"?
Ondra.
|
by: Phill |
last post by:
All the event handlers seem to pass an Object and an EventArgs object.
If the event doesn't need this info why pass them anyway? It is inefficient.
|
by: Eric Chaves |
last post by:
Hi folks,
Im writing a small GUI application to deploy objects that allows a
user to create my objects, set it's properties, serialize it into a
binary package for futher load into production enviroment.
Among those "properties", the GUI allows a user to create delegates
at runtime and bind it to the object's events.
Hoever I'could see a way to check which methdos from some class
adhere to same delegate declaration with the EventInfo...
|
by: Greg Wilkerson |
last post by:
I hope I can explain this in a way that can be understood.
I have a custom control, I'll call it navigator, used to navigate
"things". I has, among other controls, two standard buttons, previous
and next. This control is implemented by other custom controls that
displays "things" in different ways. What happens when the previous
or next buttons are clicked depends on the type of parent control. To
me, this seems like a classic...
| |
by: Joanna Carter [TeamB] |
last post by:
Hi folks
I think I have asked something similar before, but here goes again...
I have to call a method that varies depending on the type of one of its
parameters.
The object that I have to pass is of a base class.
I do not want to have an "if (...) else" construct if I can avoid it.
|
by: Quimbly |
last post by:
I'm having some problems comparing delegates. In all sample projects I
create, I can't get the problem to occur, but there is definitely a problem
with my production code.
I can't give all the code, as there's simply too much, but here's the
general gist:
I have a connection object which connects to a custom back-end server of one
type or another. Clients of this connection object send requests via a
method (e.g....
|
by: Dave |
last post by:
I've got these declarations:
public delegate void FormDisplayResultsDelegate<Type>(Type
displayResultsValue);
public FormDisplayResultsDelegate<stringdisplayMsgDelegate;
instantiation:
displayMsgDelegate = DisplayStatusMessage;
implementation:
public void DisplayStatusMessage(string statusMessage)
|
by: vcquestions |
last post by:
Hi.
Is there way to have a function pointer to a delegate in c++/cli that
would allow me to pass delegates with the same signatures as
parameters to a method?
I'm working with managed code. Let's say we have 2 delegates:
public delegate void FirstDelegate( int i );
public delegate void SecondDelegate( int i );
|
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: 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: 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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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.
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |