473,241 Members | 1,912 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,241 software developers and data experts.

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.Control,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.Control 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,according 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.DelegateName += CustomRenderingMethod;

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.DelegateName = CustomRenderingMethod;

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 4210
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.com

"han zhiyang" <ha********@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.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.Control,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.Control 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,according 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.DelegateName += CustomRenderingMethod;

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.DelegateName = CustomRenderingMethod;

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********@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.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.Control,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.Control 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,according 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.DelegateName += CustomRenderingMethod;

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.DelegateName = CustomRenderingMethod;

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,users 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.Control.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.DelegateName += CustomRenderingMethod;

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.DelegateName = CustomRenderingMethod;

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********@discussions.microsoft.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.DelegateName += CustomRenderingMethod;

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.DelegateName = CustomRenderingMethod;

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.com>
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
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......
6
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",...
0
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...
5
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...
6
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
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? ...
14
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...
17
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: ...
3
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...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.