I understand that this is an unusual problem, but:
I created a custom TypeDescriptionProvider that can store and return different TypeDescriptors
based on the requested object type. However, I noticed that regardless of the TypeDescriptionProvider
associated with the type (be-it custom or default), TypeDescriptor.GetProvider()
always returns an object (inner class) System.ComponentModel.TypeDescriptor.TypeDescriptionNode
(some wrapper around the actual TypeDescriptionProvider
). In turn, calling GetTypeDescriptor()
on this object always returns a System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor
object (another shell), and the stranger still does not call the TypeDescriptionProvider
method TypeDescriptionProvider
actual GetTypeDescriptor()
.
Does this mean that there really is no way to return the actual TypeDescriptionProvider
or its TypeDescriptor
from its provider? Methods for returning class name, properties, etc. They still work as expected on the DefaultTypeDescriptor
, but I cannot compare or find out if the two objects are using the same TypeDescriptor
(which I currently need).
Does anyone know how to get the actual TypeDescriptionProvider
, or get the actual TypeDescriptor from a wrapped provider?
Thanks in advance.
Example:
public class TestTypeDescriptionProvider : TypeDescriptionProvider { private static Dictionary<Type, ICustomTypeDescriptor> _descriptors = new Dictionary<Type, ICustomTypeDescriptor>(); ...static method to add to the cache... public override ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { if (objectType == null) return _descriptors[instance.GetType()]; return _descriptors[objectType]; } } ... TypeDescriptionProvider p = TypeDescriptor.GetProvider(obj.GetType());
source share