/// <summary>Gets a custom type descriptor for the given type and object.</summary> /// <returns>An <see cref="T:System.ComponentModel.ICustomTypeDescriptor" /> that can provide metadata for the type.</returns> /// <param name="objectType">The type of object for which to retrieve the type descriptor.</param> /// <param name="instance">An instance of the type. Can be null if no instance was passed to the <see cref="T:System.ComponentModel.TypeDescriptor" />.</param> public virtual ICustomTypeDescriptor GetTypeDescriptor(Type objectType, object instance) { if (_parent != null) { return(_parent.GetTypeDescriptor(objectType, instance)); } if (_emptyCustomTypeDescriptor == null) { _emptyCustomTypeDescriptor = new EmptyCustomTypeDescriptor(); } return(_emptyCustomTypeDescriptor); }
public void GetTypeDescriptorShouldReturnExpectedValue() { // arrange Func<ICustomTypeDescriptor, ICustomTypeDescriptor> factory = parent => { var descriptor = new CustomTypeDescriptor<string>( parent ); descriptor.AddExtensionProperty( "Name", s => s.GetType().Name ); return descriptor; }; var target = new TypeDescriptionProvider<string>( factory ); // act var actual = target.GetTypeDescriptor( typeof( string ), "" ); // assert Assert.NotNull( actual ); Assert.IsType( typeof( CustomTypeDescriptor<string> ), actual ); }