Inheritance: ICustomTypeDescriptor
コード例 #1
0
 public void GetClassNameShouldReturnTypeArgumentName()
 {
     var expected = TypeDescriptor.GetClassName( typeof( object ) );
     var target = new CustomTypeDescriptor<object>();
     var actual = target.GetClassName();
     Assert.Equal( expected, actual );
 }
コード例 #2
0
 public ComponentImporter(Type type, ICustomTypeDescriptor typeDescriptor) :
     base(type)
 {
     if (typeDescriptor == null)
         typeDescriptor = new CustomTypeDescriptor(type);
     
     _properties = typeDescriptor.GetProperties();
 }
コード例 #3
0
 public void GetPropertyOwnerShouldReturnExpectedValue()
 {
     var parent = TypeDescriptor.GetProvider( typeof( string ) ).GetTypeDescriptor( typeof( string ) );
     var target = new CustomTypeDescriptor<string>( parent );
     var property = target.GetProperties().Cast<PropertyDescriptor>().First();
     var owner = target.GetPropertyOwner( property );
     Assert.Equal( target, owner );
 }
コード例 #4
0
        public void AddExtensionPropertyShouldNotAllowNullAccessor()
        {
            var target = new CustomTypeDescriptor<object>();
            var ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( "Name", (Func<object,string>) null ) );
            Assert.Equal( "accessor", ex.ParamName );

            ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( "Name", (Func<object, string>) null, ObjectExtensions.SetName ) );
            Assert.Equal( "accessor", ex.ParamName );
        }
コード例 #5
0
        public void GetPropertiesShouldIncludeExtensionProperties()
        {
            var parent = TypeDescriptor.GetProvider( typeof( string ) ).GetTypeDescriptor( typeof( string ) );
            var target = new CustomTypeDescriptor<string>( parent );

            target.AddExtensionProperty( "Name", ObjectExtensions.GetName );

            var properties = target.GetProperties();

            Assert.Equal( 2, properties.Count );
            Assert.Equal( "Name", properties[1].Name );
        }
コード例 #6
0
        public void AddExtensionPropertyShouldNotAllowNullOrEmptyPropertyName()
        {
            var target = new CustomTypeDescriptor<object>();
            var ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( null, ObjectExtensions.GetName ) );
            Assert.Equal( "propertyName", ex.ParamName );

            ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( "", ObjectExtensions.GetName ) );
            Assert.Equal( "propertyName", ex.ParamName );

            ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( null, ObjectExtensions.GetName, ObjectExtensions.SetName ) );
            Assert.Equal( "propertyName", ex.ParamName );

            ex = Assert.Throws<ArgumentNullException>( () => target.AddExtensionProperty( "", ObjectExtensions.GetName, ObjectExtensions.SetName ) );
            Assert.Equal( "propertyName", ex.ParamName );
        }
コード例 #7
0
 /// <summary>This method returns the object that should be used during invocation of members.</summary>
 /// <returns>The <see cref="T:System.Object" /> that should be used during invocation of members.</returns>
 /// <param name="type">The <see cref="T:System.Type" /> of the invocation target.</param>
 /// <param name="instance">The potential invocation target.</param>
 protected override object GetInvocationTarget(Type type, object instance)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     if (instance == null)
     {
         throw new ArgumentNullException("instance");
     }
     if (instance is CustomTypeDescriptor)
     {
         CustomTypeDescriptor customTypeDescriptor = (CustomTypeDescriptor)instance;
         return(customTypeDescriptor.GetPropertyOwner(this));
     }
     return(base.GetInvocationTarget(type, instance));
 }
コード例 #8
0
        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 );
        }
コード例 #9
0
        public void GetPropertiesWithFilterShouldIncludeExtensionProperties()
        {
            var target = new CustomTypeDescriptor<string>();

            target.AddExtensionProperty( "Name", ObjectExtensions.GetName, ObjectExtensions.SetName );

            var properties = target.GetProperties( null );

            Assert.Equal( 1, properties.Count );
            Assert.Equal( "Name", properties[0].Name );
        }