PC Review


Reply
Thread Tools Rate Thread

Could a delegate point to a constructor?

 
 
=?Utf-8?B?VGhlUGlua1BhbnRoZXI=?=
Guest
Posts: n/a
 
      9th Feb 2006
Hi.
I'm looking for a way to make a delegate point to a constructor.
I'm not too sure i'm explaining it right,so here's a sample code to
demonstrate.

-----
using System.Windows.Forms;
class xyz
{
public delegate Form MyDelegate (string input);
public static void func (MyDelegate x)
{
Form y = x("p");
}
}
class abc : Form
{
public abc (string title) {...}
....
}
-----

Now i would want to make the xyz.func() create a new "abc".
both the "MyDelegate" and the "abc" constructor have the same return value
and the same parameters,so theoretically there should be a way.

Hopefully i'm clear enough for someone...
Thank you
 
Reply With Quote
 
 
 
 
Peter Rilling
Guest
Posts: n/a
 
      9th Feb 2006
No. But, you could create a factory method or class that can create an
instance of the Form for you using something like
Activator.CreateInstance(...). Then have the delegate point to the factory.

"ThePinkPanther" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi.
> I'm looking for a way to make a delegate point to a constructor.
> I'm not too sure i'm explaining it right,so here's a sample code to
> demonstrate.
>
> -----
> using System.Windows.Forms;
> class xyz
> {
> public delegate Form MyDelegate (string input);
> public static void func (MyDelegate x)
> {
> Form y = x("p");
> }
> }
> class abc : Form
> {
> public abc (string title) {...}
> ...
> }
> -----
>
> Now i would want to make the xyz.func() create a new "abc".
> both the "MyDelegate" and the "abc" constructor have the same return value
> and the same parameters,so theoretically there should be a way.
>
> Hopefully i'm clear enough for someone...
> Thank you



 
Reply With Quote
 
 
 
 
Mattias Sjögren
Guest
Posts: n/a
 
      9th Feb 2006
>Now i would want to make the xyz.func() create a new "abc".

In addition to what the others said, it's worth pointing out that a
constructor doesn't have a return value so

>both the "MyDelegate" and the "abc" constructor have the same return value
>and the same parameters,so theoretically there should be a way.


is incorrect. A constructor doesn't return a new object, it
initializes a newly allocated one.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Emulating Delegate.Target and Delegate.Method rodrigobamboo@gmail.com Microsoft Dot NET Compact Framework 1 14th Nov 2005 02:19 PM
Does delegate instantiate an instance of Delegate or MultiCastDele =?Utf-8?B?TmltYQ==?= Microsoft C# .NET 2 30th Sep 2005 08:00 PM
Delegate Gurus: Can I create a delegate for a property (as opposed to a method)? Bill Davidson Microsoft C# .NET 6 3rd Aug 2005 04:19 PM
Multicast delegate checking for particular delegate Edward Diener Microsoft Dot NET 3 5th Oct 2004 06:28 PM
Delegate who's not a delegate? Doreen Microsoft Outlook Calendar 0 19th Apr 2004 04:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 PM.