Click here to Skip to main content
15,886,873 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I detect when a client disconnects from a well known service? Pin
HAHAHA_NEXT9-Feb-04 11:01
HAHAHA_NEXT9-Feb-04 11:01 
QuestionHow to get/set printer paper media type Pin
trythat9-Feb-04 5:55
trythat9-Feb-04 5:55 
QuestionDynamic attributes for propertyGrid??? Pin
LongRange.Shooter9-Feb-04 3:11
LongRange.Shooter9-Feb-04 3:11 
AnswerRe: Dynamic attributes for propertyGrid??? Pin
Heath Stewart9-Feb-04 4:17
protectorHeath Stewart9-Feb-04 4:17 
GeneralRe: Dynamic attributes for propertyGrid??? Pin
LongRange.Shooter9-Feb-04 8:09
LongRange.Shooter9-Feb-04 8:09 
GeneralRe: Dynamic attributes for propertyGrid??? Pin
Heath Stewart9-Feb-04 9:33
protectorHeath Stewart9-Feb-04 9:33 
GeneralRe: Dynamic attributes for propertyGrid??? Pin
LongRange.Shooter9-Feb-04 10:38
LongRange.Shooter9-Feb-04 10:38 
GeneralRe: Dynamic attributes for propertyGrid??? Pin
Heath Stewart9-Feb-04 14:02
protectorHeath Stewart9-Feb-04 14:02 
You don't have to attribute you class with anything to make use of the ICustomTypeDescriptor. Any object that uses the TypeDescriptor to get information - like the PropertyGrid - will automatically benefit from the ICustomTypeDescriptor implementation.

As far as the attribute goes, I would do something like this:
public class RequiredGroupsAttribute : Attribute
{
  private string[] groups;
  public RequiredGroupsAttribute(params string[] groups)
  {
    this.groups = groups;
  }
  public string[] Groups
  {
    get { return this.groups; }
  }
  public bool IsInGroup(string group)
  {
    if (this.groups == null) return false;
    foreach (string s in this.groups)
      if (string.Compare(s, group, true) == 0) return true;
    return false;
  }
}
In your derived PropertyDescriptor, you can get the attributes of the property like so:
public override bool IsReadOnly
{
  get
  {
    RequiredGroupsAttribute attr = (RequiredGroupsAttribute)
      this.Attributes[typeof(RequiredGroupsAttribute)];
    if (attr == null) return true;
    return !attr.IsInGroup("Developers"); // Change to be dynamic
  }
}
This is just a very simple example, though. You could most likely improve upon it.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Dynamic attributes for propertyGrid??? Pin
LongRange.Shooter10-Feb-04 8:58
LongRange.Shooter10-Feb-04 8:58 
GeneralRe: Dynamic attributes for propertyGrid??? Pin
Heath Stewart10-Feb-04 11:18
protectorHeath Stewart10-Feb-04 11:18 
GeneralRe: Dynamic attributes for propertyGrid??? Pin
LongRange.Shooter11-Feb-04 7:49
LongRange.Shooter11-Feb-04 7:49 
GeneralRe: Dynamic attributes for propertyGrid??? Pin
Heath Stewart11-Feb-04 9:14
protectorHeath Stewart11-Feb-04 9:14 
GeneralRe: Dynamic attributes for propertyGrid??? Pin
LongRange.Shooter11-Feb-04 10:45
LongRange.Shooter11-Feb-04 10:45 
GeneralRe: Dynamic attributes for propertyGrid??? Pin
Heath Stewart11-Feb-04 11:53
protectorHeath Stewart11-Feb-04 11:53 
GeneralCommand Line Pin
GetOn&GetGoing8-Feb-04 23:43
GetOn&GetGoing8-Feb-04 23:43 
GeneralRe: Command Line Pin
Heath Stewart9-Feb-04 1:30
protectorHeath Stewart9-Feb-04 1:30 
QuestionHow to execute a file Pin
Jonathan Slenders_8-Feb-04 22:41
sussJonathan Slenders_8-Feb-04 22:41 
AnswerRe: How to execute a file Pin
Mazdak8-Feb-04 23:20
Mazdak8-Feb-04 23:20 
GeneralRe: How to execute a file Pin
Jonathan Slenders9-Feb-04 0:22
Jonathan Slenders9-Feb-04 0:22 
GeneralRe: How to execute a file Pin
Heath Stewart9-Feb-04 1:28
protectorHeath Stewart9-Feb-04 1:28 
AnswerRe: How to execute a file Pin
Mike Clark9-Feb-04 12:13
Mike Clark9-Feb-04 12:13 
QuestionHow to reduce size? Pin
GetOn&GetGoing8-Feb-04 20:22
GetOn&GetGoing8-Feb-04 20:22 
AnswerRe: How to reduce size? Pin
Mazdak8-Feb-04 21:31
Mazdak8-Feb-04 21:31 
GeneralRe: How to reduce size? Pin
GetOn&GetGoing8-Feb-04 21:35
GetOn&GetGoing8-Feb-04 21:35 
GeneralRe: How to reduce size? Pin
Colin Angus Mackay8-Feb-04 23:12
Colin Angus Mackay8-Feb-04 23:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.