473,406 Members | 2,343 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,406 software developers and data experts.

about delagate signature and parameters

Hello,

I come here to expose my use of delegate.
I hope there is a better fashion, because in that form, parameters could not be
verified at compilation time.

<code>
delegate void TheMethodDelegate( param1, param2 );
void TheMethod( param1, param2 )
{
}

void AnotherMethod()
{
this.BeginInvoke(
new TheMethodDelegate(TheMethod),
new object[] { "foo" }
);
}
</code>

You can see that one parameter is missing ...
And the compiler do not say anything.

Is there another method that be safe for method signature verification at
compilation time ?

Thanks for you lights,
cyrille.
Mar 1 '06 #1
3 1406
# Cyrille37 # wrote:
I come here to expose my use of delegate.
I hope there is a better fashion, because in that form, parameters could not be
verified at compilation time.
<snip>
You can see that one parameter is missing ...
And the compiler do not say anything.

Is there another method that be safe for method signature verification at
compilation time ?


Not if you need to provide the parameters separately. Now, you could
keep the potential for problems down by having a static method which
took a TheMethodDelegate and the two parameters (and maybe what to call
BeginInvoke on). That way you'd only need one call to BeginInvoke, so
only one place where things could go wrong - and that's easy to verify
in terms of correctness, because you've been given all the parameters
you need and *only* the parameters you need.

Of course, you'd need a method like that for each delegate type you
wanted to use...

Jon

Mar 1 '06 #2
Jon Skeet [C# MVP] a écrit :
# Cyrille37 # wrote:
I come here to expose my use of delegate.
I hope there is a better fashion, because in that form, parameters could not be
verified at compilation time.


<snip>
You can see that one parameter is missing ...
And the compiler do not say anything.

Is there another method that be safe for method signature verificationat
compilation time ?


Not if you need to provide the parameters separately. Now, you could
keep the potential for problems down by having a static method which
took a TheMethodDelegate and the two parameters (and maybe what to call
BeginInvoke on). That way you'd only need one call to BeginInvoke, so
only one place where things could go wrong - and that's easy to verify
in terms of correctness, because you've been given all the parameters
you need and *only* the parameters you need.

Of course, you'd need a method like that for each delegate type you
wanted to use...

Jon


Thanks Jon.

Is that also true for .Net 2.0 ?
Is there, or not, some new practices on that subject ?

cyrille.
Mar 1 '06 #3
# Cyrille37 # wrote:
Is that also true for .Net 2.0 ?
Is there, or not, some new practices on that subject ?


Yes, it's still true for .NET 2.0, and has to be - if you're calling
BeginInvoke, you've got to provide the parameters as an array of
objects. There's no way round that, and there's no way the compiler can
detect whether or not that array is appropriate for the delegate you're
passing.

Jon

Mar 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Kim | last post by:
I have a .NET service sending mails using CDOEX. These mails I need to sign. I got a tip that I should use CAPICOM. That worked fine sending a mail with signature. BUT the problem is that I...
2
by: Mad Scientist Jr | last post by:
Is it possible to write a method with a signature for x parameters (so you get intellisense when you call it), but from within the method, be able to access the parameter names and values in a...
4
by: news.microsoft.com | last post by:
In one of my books called "Mastering C#" there is a statement that reads "All event handler delegates must return void and accept two parameters. The first parameter is an object, and it represents...
3
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
38
by: Arjang | last post by:
http://www.codeproject.com/useritems/CSharpVersusVB.asp
0
by: MalamisuraE | last post by:
I need to write a class that will process a qued list of items, each item could take a long or short time based on the items. I want to use Asynchronous Callback Methods to do this instead of...
20
by: raylopez99 | last post by:
Dvorak is always interesting, albeit speculative. What hidden gem has he found in Vista that helps developers? It can't be .NET/CLI, that's been out forever. RL Vista rollout hides reality...
14
by: =?Utf-8?B?QUEyZTcyRQ==?= | last post by:
Am I correct in thinking that the <signatureof a function is its <syntax> i.e. the arguments and the order in which they are specified when calling the function?
5
by: =?Utf-8?B?Y2FsZGVyYXJh?= | last post by:
Dear all, I have a strange behaviour on the use of delagate. I will try to explain. I have an assembly (Lets call it AssmDB) which contains database function operation like Insert, Delete,...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
jinu1996
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...
0
tracyyun
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...
0
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...

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.