System.ComponentModel.ReferenceConverter.CanConvertFrom C# (CSharp) Method

CanConvertFrom() public method

Gets a value indicating whether this converter can convert an object in the given source type to a reference object using the specified context.

public CanConvertFrom ( ITypeDescriptorContext context, Type sourceType ) : bool
context ITypeDescriptorContext
sourceType System.Type
return bool
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            if (sourceType == typeof(string) && context != null)
            {
                return true;
            }
            return base.CanConvertFrom(context, sourceType);
        }

Usage Example

Example #1
0
		public void CanConvertFrom ()
		{
			ReferenceConverter converter = new ReferenceConverter (typeof(ITestInterface));
			// without context
			Assert.IsFalse (converter.CanConvertFrom (null, typeof(string)), "#1");
			// with context
			Assert.IsTrue (converter.CanConvertFrom (new TestTypeDescriptorContext (), typeof(string)), "#2");
		}