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
Tom Larsen10-Feb-04 7:04
Tom Larsen10-Feb-04 7:04 
GeneralRe: How can I detect when a client disconnects from a well known service? Pin
LongRange.Shooter10-Feb-04 9:08
LongRange.Shooter10-Feb-04 9:08 
GeneralRe: How can I detect when a client disconnects from a well known service? Pin
Tom Larsen11-Feb-04 3:53
Tom Larsen11-Feb-04 3:53 
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 
I'm lost. I searched everywhere and could find no articles on ICustomTypeDescriptor. I tried deploying my own TypeDescriptor but I'm getting lost in all of the methods I have to create and not really understanding when the attribute methods and property methods apply to my TypeConverter and when they apply to the property I am a part of.

My attempt, in general, is this:
C#
public class Secure : ICustomTypeDescriptor
{
     private bool isSecure;

     public Secure(bool state)
     {
         isSecure = state;
     }

     .. now I'm lost trying to deploy everything
}

I also cannot find PropertyDescriptor.ReadOnly or when I should use it or add it or whatever. I found an abstract conversation on one site and this is similar to what they showed. My attempt:

namespace myCompany.Attributes
{

	internal class Secured  : ICustomTypeDescriptor 
	{
		private bool secured;
		private bool readonlyState;


		/// <summary>
		/// Create an attribute Secured(true/false)
		/// </summary>
		/// <param name="state"></param>
		public Secured(bool state) 
		{
			secured = state;
		}


		/// <summary>
		/// Returns attribute ReadOnly(true) if user is not in any security group.
		/// Returns attribute ReadOnly(true) if Secured(true) and user is editor.
		/// Always returns attribute ReadOnly(false) if user is developer.
		/// </summary>
		/// <returns></returns>
		System.ComponentModel.PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(System.Attribute[]
			attributes)
		{


			PropertyInfo[] propInfos =
				this.classType.GetProperties(BindingFlags.Public | BindingFlags.Static);

			ArrayList props = new ArrayList(propInfos.Length);

			foreach(PropertyInfo propInfo in propInfos)
			{
				props.Add( new ReflectPropertyDescriptor(propInfo) );
			}
			if (CheckReadOnlyState())
				props.Add(new ReflectProperty(???));
			return new PropertyDescriptorCollection(
				(PropertyDescriptor[])props.ToArray(typeof(PropertyDescriptor)) );

		}
		System.ComponentModel.PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
		{
			ArrayList props = new ArrayList();
			if (CheckReadOnlyState())
				props.Add(new ReflectPropertyDescriptor(PropertyDescriptor.ReadOnly));
                        return new PropertyDescriptorCollection((PropertyDescriptor[])props.ToArray(typeof(PropertyDescriptor)));
		}
			

		TypeConverter ICustomTypeDescriptor.GetConverter()
		{
			return TypeDescriptor.GetConverter(this, true);
		}

		AttributeCollection ICustomTypeDescriptor.GetAttributes()
		{
			return TypeDescriptor.GetAttributes(this.secured, true);
		}


		/// <summary>
		/// Tell PropertyGrid that GetProperties is supported.
		/// </summary>
		/// <param name="context"></param>
		/// <returns></returns>
		public  bool GetPropertiesSupported(ITypeDescriptorContext context) 
		{
			return true;
		}
		object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
		{

		}
	}

        public class bool CheckReadOnlyState()
        {
            readonlyState = true;
	    SecurityManager sec = new SecurityManager();

	    if (sec.CheckUserGroup("D-U-TCAEDIT") && !this.secured)
	    {
		readonlyState = false;
	    }
	    if (sec.CheckUserGroup("D-U-TCA"))
	    {
		readonlyState = false;
	    }
            return readonlyState;
        }
	public class PropertyDescriptor ReflectPropertyDescriptor : PropertyDescriptor
	{
		private PropertyInfo propInfo;

		public ReflectPropertyDescriptor(PropertyInfo propInfo) :
			base(propInfo.Name, null)
		{
			this.propInfo = propInfo;
		}
	}


I'm just not understanding what this is doing and how I define the ReadOnly(true/false) attribute.

_____________________________________________
Of all the senses I could possibly lose,
It is most often the one called 'common' that gets lost.

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 
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 

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.