Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generic property
Message
De
15/06/2007 11:17:41
 
 
À
13/06/2007 10:52:09
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01232604
Message ID:
01233499
Vues:
9
John,

Generics might be the perfect solution to your problem. Here's an example of how to use Generics in a method (not tested, just off the top of my head):
public T GetButton<T> where T : ToolBarButton, ToolStripButton, new()
{
    T Mybutton = new T();
    // etc.etc.etc.
}
When writing a Generic method, something one of our developers discovered while learning this, is to not use "T" as you see in just about every example you ever find online, but use something more descriptive so it's more obvious what kind of object type you might be expecting in the method, something like this:
public BUTTONTYPE GetButton<BUTTONTYPE > where BUTTONTYPE : ToolBarButton, ToolStripButton, new()
{
    BUTTONTYPE Mybutton = new BUTTONTYPE();
    // etc.etc.etc.
}
To be honest, I'm not sure how many properties ToolBarButton and ToolStripButton share, so I don't know whether this will do the trick for you or not, but it is a good example of some things you can do with Generics.


~~Bonnie



>Hi,
>I am using DevExpress ribbon control as my form toolbar. I want to implement the behavour like maintenance toolstrip to it. In order to reuse my code in casde i want to use other control as my maintenance toolbar in the future, I planned to write an controller/behavour class to control the logic.
>
>My current problem is, I need some way to access those button (ribbon control bar item/maintenance toolstrip button) in order to disable/enable them. I was thinking to have property to store object reference of each button accordingly. I used "control" as my property type. However, I might not able to access certain property that exist in toolbar button such as tooltiptext if I do so.
>
>Anyway I can "set" tyoe to property during runtime? I tried to take a look at generic, but I only see it work for List. Is it?
>
>Ady ideas?
>
>Thank you
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform