typedescriptor

Binding IList<IMyInterfaceType> doesn't display members of Interfaces that IMyInterface inherits

I'm binding IList to a GridView. IMyInterface looks like public interface IMyInterface: IHasTotalHours, IHasLines { DateTime GoalStartDate { get; set; } DateTime GoalEndDate { get; set; } } I bind an instance to a Grid like this: IList<IMyInterface> instance= GetMyData(); myGrid.DataSource = instance; myGrid.DataBind(); Wh...

TypeDescriptor.GetProperties(thisType) to return properties, which are write-only

Hi, I'm trying to get all properties from a type, but using TypeDescriptor.GetProperties(thisType) will only supply me with properties, that has both setter and a getter. I have write-only properties. Are there a way to retrieve a PropertyDescriptorCollection including those? /Asger ...

Add a category attribute to a PropertyDescriptor

I have a set of custom PropertyDescriptor that I want to add categories too so they display in a more organized fashion in a PropertyGrid. I want each type of PropertyDescriptor to go into a specific Category. I've tried using TypeDescriptor.AddAttributes() to add attributes to an existing PropertyDescriptor, but the category attribute ...

TypeDescriptor.CreateProperty doesn't add a property

I am trying to add a property to a type using TypeDescriptor.CreateProperty in order to display an additional property in a property grid, however this new property is not added and when I call TypeDescriptor.GetProperties on that type to inspect the properties, this property does not exist. It there something I might be missing or over...

How to remove a TypeConverter Attribute from a Type in .NET?

I'm restating this problem to summarise what I've already found: I have a test TypeConverter, (MyConverter), that for a ConvertToString will output "Converted To String", no matter what the input. To ensure this is picked up by GetConverter for Int32, I add the following line: (1) Dim tcp As TypeDescriptionProvider = TypeDescriptor.Ad...

Add property-level attributes dynamically using TypeDescriptor for PropertyGrid

Hi All, I want to add attributes (like Browsable(false)) dynamically while displaying in the grid. Scenario is that I have a custom class with some public properties. However, I dont want all of the public properties to be displayed in the UI. Is there a way out? I tried using TypeDescriptor. However, it works only at the type level an...

TypeDescriptor.GetProperties() vs Type.GetProperties()

Consider the following code. Object obj; PropertyDescriptorCollection A = TypeDescriptor.GetProperties(obj); PropertyInfo[] B = obj.GetType().GetProperties(); // EDIT* I'm trying to understand the difference between A and B. From what I understand TypeDescriptor.GetProperties() will return custom TypeDescriptor properties, where a...

Filter properties returned by TypeDescriptor.GetProperties() depending on the class they are declared in

Hey guys. I have the following situation. I want to use a TypeDescriptor to get the properties of a certain type. The type's depth in the inheritance hierarchy may vary. I only want to get the properties declared in the type itself and not in its parents (base). The problem is that when I call TypeDescriptor.GetProperties() it would ret...

TypeDescriptionProvider.GetTypeDescriptor() instance parameter is null?

I'm trying to enable user of my application to add their own custom properties to objects. Classes which the user can add properties too implement the interface IUserPropertyHost, which is shown below. UserPropertyHostType is an enumeration that identifies a specific group of custom properties to apply to the object. public interface IU...

How can I avoid having a separate custom TypeDescriptorProvider for each of my classes?

I've added functionality to my project that allows the users to add their own custom properties to objects. I've created my own custom TypeDescriptor, PropertyDescriptor and TypeDescriptorProviders etc.. etc.. to do this. Here's my problem. Right now I have it all working, but had to create a separate TypeDescriptionProvider for each o...

C#: What's the Difference Between TypeDescriptor.GetAttributes() and GetType() .GetCustomAttributes?

Take these two code things: instance.GetType() .GetCustomAttributes(true) .Where(item => item is ValidationAttribute); And TypeDescriptor.GetAttributes(instance) .OfType<ValidationAttribute>(); If the class looks like: [RequiredIfOtherPropertyIsNotEmpty("State", "City", ErrorMessage = ErrorDescription.CreateAccount_CityRequired...

TypeDescriptionProvider / HyperDescriptor implementation

I am currently populating my WPF grid using a data collection that implements ITypedList, with the contained entities implementing ICustomTypeDescriptor. All the properties are determined at runtime. I'm wanting to implement HyperDescriptor to help speed up performance, but the example on that page more refers to known types rather tha...

Programmatically add an attribute to a method or parameter

I can use TypeDescriptor.AddAttributes to add an attribute to a type in runtime. How do I do the same for a method and parameter? (maybe 2 separate questions...) ...

set value of a property of an anonymous type using reflection / TypeDescriptor is it possible ?

I tried using TypeDescriptor and the value is not changing, and via reflection I get an error that there is no setter for that property ...

Using the ComponentModel.TypeDescriptor for binding AND custom serialization

Hi guys, I'm trying to use a class both for databinding and for serializing using some custom serialization code. The problem is that the class has a System.ComponentModel.TypeDescriptionProviderAttribute applied to it: [SomeSerializingAttribute] [System.ComponentModel.TypeDescriptionProvider(typeof(RowTypeDescriptionProvider))] publi...

VB.NET Dynamic CustomTypeDescriptor

I'm playing around with an idea(never played with TypeDescriptors before), and managed to get it to work nicely. But I'm concerned about some "best practice" decisions I made during my little experiment. I use a CustomTypeDescriptor, that receives an event from its PropertyDescriptors indicating that the values are changing or being que...

InvalidCastException casting object to its own type

I'm currently completely baffled by the problem I'm having. I'm writing a plug-in for another application that provides a public .NET API. I've created a class named Room and I am using a PropertyGrid to allow users to see and edit the properties of the Room instances. A few properties are restricted to a set of standard values. Thus I a...

Is it possible to conditionally hide properties at compile time in .Net?

Depending on a preprocessor directive, I want to set all properties in a class to EditorBrowsableAttribute.Never. I thought about creating a custom attribute, derived from EditorBrowsableAttribute, but unfortunately that class is sealed. I've had a look at ICustomTypeDescriptor, but in the GetProperties method, I can get hold of ea...

TypeDescriptor.AddAttributes() replaces the current attribute insead of adding it

I have this portion of code: var hasAttribute = TypeDescriptor.GetAttributes(property.DeclaringType).OfType<CrmTypeAttribute>() .Any((attr) => ((CrmTypeAttribute)attr).Name == property.Name); if (!hasAttribute) { var crmTypeAttribute = new CrmTypeAttribute(proper...

TypeDescriptor doesn't return members from inherited interfaces

my problem is that TypeDescriptor doesn't return members from inherited interfaces, is this how it is supposed to be working ? or is it a bug ? [TestFixture] public class DescriptorTests { [Test] public void Test() { // count = 1 ...