473,804 Members | 3,549 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to define and use a property of delegate type,"=" or "+="?

Hi.
I tried to design a custom web control which can flexibly and
dynamicly let the control user ,for example the web page developer, customize
its layout codes.This control derives from System.Web.UI.C ontrol,and for my
purpose,I define a delegate property in the control's class definition, so
control user can define his(or her) method out of the class definition and
add his(or her) method to the delegate chain. I also override the Render
method of System.Web.UI.C ontrol to call this delegate,so in the Rendering
stage, customized rendering logics can be implemented.
This is the question. Since I define the delegate as property(also
accompanid with a private field with the same name except the first letter
lowcasing,accor ding to the Camel style) ,how can I deal with the "+=" and
"="? I mean maybe I have two choices:
1.Use "=" in the "set" block in property definition and tell control
users to use "+=" when they use the property in their web pages.
In class definition-->property definition:
set{
delegateName = value;
}
In web page before "Rendering" stage:
controlName.Del egateName += CustomRendering Method;

2.Use "+=" in the "set" block and "=" in web pages.
In class definition-->property definition:
set{
delegateName += value;
}
In web page before "Rendering" stage:
controlName.Del egateName = CustomRendering Method;

By the way,I think both "=" or both "+=" is either not reasonable. I
wonder what is the correct way.

Appretiate for any help.

Dec 2 '05 #1
5 4241
han,

I don't understand why you are not exposing the delegate as an event.
Either that, or define an interface, the implementation of which will return
the information you are looking for, and then assign a single instance to
your class.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"han zhiyang" <ha********@dis cussions.micros oft.com> wrote in message
news:B5******** *************** ***********@mic rosoft.com...
Hi.
I tried to design a custom web control which can flexibly and
dynamicly let the control user ,for example the web page developer,
customize
its layout codes.This control derives from System.Web.UI.C ontrol,and for
my
purpose,I define a delegate property in the control's class definition, so
control user can define his(or her) method out of the class definition and
add his(or her) method to the delegate chain. I also override the Render
method of System.Web.UI.C ontrol to call this delegate,so in the Rendering
stage, customized rendering logics can be implemented.
This is the question. Since I define the delegate as property(also
accompanid with a private field with the same name except the first letter
lowcasing,accor ding to the Camel style) ,how can I deal with the "+=" and
"="? I mean maybe I have two choices:
1.Use "=" in the "set" block in property definition and tell control
users to use "+=" when they use the property in their web pages.
In class definition-->property definition:
set{
delegateName = value;
}
In web page before "Rendering" stage:
controlName.Del egateName += CustomRendering Method;

2.Use "+=" in the "set" block and "=" in web pages.
In class definition-->property definition:
set{
delegateName += value;
}
In web page before "Rendering" stage:
controlName.Del egateName = CustomRendering Method;

By the way,I think both "=" or both "+=" is either not reasonable. I
wonder what is the correct way.

Appretiate for any help.

Dec 2 '05 #2
delegates are multi-cast, meaning that multiple methods CAN be assigned to
the same delegate. This does not mean that multiple methods SHOULD ALWAYS be
assigned to the same delegate. If you want multiple methods to be able to be
assigned to the same delegate, use "+=" - otherwise not.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"han zhiyang" <ha********@dis cussions.micros oft.com> wrote in message
news:B5******** *************** ***********@mic rosoft.com...
Hi.
I tried to design a custom web control which can flexibly and
dynamicly let the control user ,for example the web page developer,
customize
its layout codes.This control derives from System.Web.UI.C ontrol,and for
my
purpose,I define a delegate property in the control's class definition, so
control user can define his(or her) method out of the class definition and
add his(or her) method to the delegate chain. I also override the Render
method of System.Web.UI.C ontrol to call this delegate,so in the Rendering
stage, customized rendering logics can be implemented.
This is the question. Since I define the delegate as property(also
accompanid with a private field with the same name except the first letter
lowcasing,accor ding to the Camel style) ,how can I deal with the "+=" and
"="? I mean maybe I have two choices:
1.Use "=" in the "set" block in property definition and tell control
users to use "+=" when they use the property in their web pages.
In class definition-->property definition:
set{
delegateName = value;
}
In web page before "Rendering" stage:
controlName.Del egateName += CustomRendering Method;

2.Use "+=" in the "set" block and "=" in web pages.
In class definition-->property definition:
set{
delegateName += value;
}
In web page before "Rendering" stage:
controlName.Del egateName = CustomRendering Method;

By the way,I think both "=" or both "+=" is either not reasonable. I
wonder what is the correct way.

Appretiate for any help.

Dec 2 '05 #3
Dear Mr.Paldino, :)
Thank you very much for your suggestion,and yes,event is a more friendly
way to do this,though in my condition,an event is somewhat not pure. The main
problem is that the "timing" at which the event is triggered is not
independent,for the customed Rendering method must be called as a part of the
Control's Render method,and the latter cannot be called in user's code.I
think using event,the benefit is that EventHandler has implemented the
delegate chain's "addon" and "remove" operation,and out of my control's class
definition,user s can simply use "+=" to add their own Rendering method.Of
course this should be done at sometime before the "rendering" statge of this
control,for the OnEventName method must be called in
System.Web.UI.C ontrol.Render method.
MY question is from an accasional idea.Maybe this is a bad design,and
using css or XSTL is better.
Thank you again for your help.

Dec 4 '05 #4
Hi Kevin,
Thank you for your help.I think it is my poor English misleading
you,I'm sorry.:).
This problem occurs when my delegate is a chain that can accept
severval methods.
So the problem is the correct location of "+=" operator,in property
definition ,or in user's code? That is to say,choose one from the following
two.

1.Use "=" in the "set" block in property definition and tell control
users to use "+=" when they use the property in their web pages.
In class definition-->property definition:
set{
delegateName = value;
}
In web page before "Rendering" stage:
controlName.Del egateName += CustomRendering Method;

2.Use "+=" in the "set" block and "=" in web pages.
In class definition-->property definition:
set{
delegateName += value;
}
In web page before "Rendering" stage:
controlName.Del egateName = CustomRendering Method;

Thank you again for your help.

"Kevin Spencer" wrote:
delegates are multi-cast, meaning that multiple methods CAN be assigned to
the same delegate. This does not mean that multiple methods SHOULD ALWAYS be
assigned to the same delegate. If you want multiple methods to be able to be
assigned to the same delegate, use "+=" - otherwise not.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

Dec 4 '05 #5
han zhiyang <ha********@dis cussions.micros oft.com> wrote:
Hi Kevin,
Thank you for your help.I think it is my poor English misleading
you,I'm sorry.:).
This problem occurs when my delegate is a chain that can accept
severval methods.
So the problem is the correct location of "+=" operator,in property
definition ,or in user's code? That is to say,choose one from the following
two.

1.Use "=" in the "set" block in property definition and tell control
users to use "+=" when they use the property in their web pages.
In class definition-->property definition:
set{
delegateName = value;
}
In web page before "Rendering" stage:
controlName.Del egateName += CustomRendering Method;

2.Use "+=" in the "set" block and "=" in web pages.
In class definition-->property definition:
set{
delegateName += value;
}
In web page before "Rendering" stage:
controlName.Del egateName = CustomRendering Method;

Thank you again for your help.


The first option is much more intuitive - it would be odd to set a
property and it actually just *add* to the existing value.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 4 '05 #6

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

Similar topics

1
2939
by: Neil Zanella | last post by:
Hello, I would like to use CSS to apply a width of 100% to all <input> elements, but to only those that have an type attribute set to "text", without affecting check boxes, radio buttons, etc... How can this be accomplished with CSS? Thanks,
6
2204
by: Stephen Johns | last post by:
I want to have a Hashtable whose keys are strings and whose values are delegates. Well, ok, I have that: dels = new Hastable(); dels.Add( "key", new Foo1Delegate(MyFoo1) ); dels.Add( "key", new Foo2Delegate(MyFoo2) ); dels.Add( "key", new Foo3Delegate(MyFoo3) );
0
1887
by: LordHog | last post by:
Hello all, I would like to use the new SerialPort class in Visual C++ 2005 Express edition, but I am having problems adding my event handler to the DataReceived event. In the header file I have the method that will handle the event defined as private: void SerialPortReceive_EventHandler( System::Object ^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e );
5
1971
by: Rob | last post by:
In many articles related to VB.net the word "class" is used... How many meanings are there to this word ? "possible to derived a class from another" "forms are full-fledged classes" "base class"
6
3591
by: Kay | last post by:
Hi all, In vb6, I can define a custom type like this: Private Type uClient sName As String sMonday As Double sMondayHeadCnt As Integer End Type
8
78101
by: Jeff S. | last post by:
I was recently advised: << Use List<struct> and Find() using different Predicate delegates for your different search needs.>> What is "Predicate delegate" as used in the above recommendation? Thanks.
14
2366
by: Chen Shusheng | last post by:
CSS white here: Simply strange, I found "define" can not work with "malloc". Together my complier will say "parse error". Could anyone tell me why? ------------------------- #define MAX 10000 ....... int main(void){ .....
17
2428
by: Chen Shusheng | last post by:
Hi all, In fact, I want to let my memory run out. And see what will happen. My system is windowsXp. Memory is 256M.I think my cdes will apply more memory than I have. Codes are below: #include <stdlib.h> #include<stdio.h> #define MAX 1000000000
3
17259
by: Simon van Beek | last post by:
Dear reader, What can be wrong in my ComboBox, the property "Auto Expand" is set to Yes, but by typing in the ComboBox it doesn't expand. Is this because the source of the ComboBox is a query.
0
9706
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9582
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,...
1
10323
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,...
0
10082
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 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...
0
6854
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();...
0
5525
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...
0
5652
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4301
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
3
2993
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.