/// <summary> /// Gets a value indicating whether this converter can convert an object in the /// given source type to a Uri. /// </summary> public override bool CanConvertFrom(ITypeDescriptorContext?context, Type sourceType) { return(sourceType == typeof(string) || sourceType == typeof(Uri) || base.CanConvertFrom(context, sourceType)); }
public override bool GetStandardValuesExclusive(ITypeDescriptorContext?context) => false;
public override bool CanConvertFrom(ITypeDescriptorContext?context, Type sourceType) => sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
/// <summary> /// Converts the given string to the converter's native type using the invariant culture. /// </summary> public object?ConvertFromInvariantString(ITypeDescriptorContext?context, string text) { return(ConvertFromString(context, CultureInfo.InvariantCulture, text)); }
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext?context) => new(Icon.KnownMimeTypes);
/// <summary> /// Gets a collection of standard values for the data type this type converter is designed for. /// </summary> public virtual StandardValuesCollection?GetStandardValues(ITypeDescriptorContext?context) => null;
/// <summary> /// Gets a value indicating whether this object supports a standard set of values that can be picked /// from a list using the specified context. /// </summary> public virtual bool GetStandardValuesSupported(ITypeDescriptorContext?context) => false;
public override bool CanConvertTo(ITypeDescriptorContext?context, Type?destinationType) => destinationType == typeof(string);
public override object?ConvertFrom(ITypeDescriptorContext?context, CultureInfo?culture, object value) => value switch {
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext?context, object?value, Attribute[]?attributes) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(Rectangle), attributes); return(props.Sort(s_propertySort)); }
public override bool CanConvertTo(ITypeDescriptorContext?context, [NotNullWhen(true)] Type?destinationType) { return(destinationType == typeof(InstanceDescriptor) || base.CanConvertTo(context, destinationType)); }
public override bool GetCreateInstanceSupported(ITypeDescriptorContext?context) => true;
/// <summary> /// Converts the given value object to /// the specified destination type using the specified context and arguments. /// </summary> public override object ConvertTo(ITypeDescriptorContext?context, CultureInfo?culture, object?value, Type destinationType !!) { if (value is Uri uri)
/// <summary> /// Gets a value indicating whether this converter can /// convert an object to the given destination type using the context. /// </summary> public override bool CanConvertTo(ITypeDescriptorContext?context, Type?destinationType) { return(destinationType == typeof(Uri) || destinationType == typeof(InstanceDescriptor) || base.CanConvertTo(context, destinationType)); }
/// <summary> /// Gets a value indicating whether this object supports properties using the specified context. /// </summary> public virtual bool GetPropertiesSupported(ITypeDescriptorContext?context) => false;
public override object?ConvertTo(ITypeDescriptorContext?context, CultureInfo?culture, object?value, Type destinationType) => value switch {
/// <summary> /// Gets a value indicating whether this converter can convert an object in the given /// source type to the native type of the converter using the context. /// </summary> public virtual bool CanConvertFrom(ITypeDescriptorContext?context, Type sourceType) => sourceType == typeof(InstanceDescriptor);
/// <summary> /// Converts the specified value to a culture-invariant string representation. /// </summary> public string?ConvertToInvariantString(ITypeDescriptorContext?context, object?value) { return(ConvertToString(context, CultureInfo.InvariantCulture, value)); }
/// <summary> /// Gets a value indicating whether the collection of standard values returned from /// <see cref='System.ComponentModel.TypeConverter.GetStandardValues()'/> is an exclusive /// list of possible values, using the specified context. /// </summary> public virtual bool GetStandardValuesExclusive(ITypeDescriptorContext?context) => false;
/// <summary> /// Converts the specified value to a string representation. /// </summary> public string?ConvertToString(ITypeDescriptorContext?context, CultureInfo?culture, object?value) { return((string?)ConvertTo(context, culture, value, typeof(string))); }
/// <summary> /// Gets a value indicating whether this converter can convert an object to the given /// destination type using the context. /// </summary> public virtual bool CanConvertTo(ITypeDescriptorContext?context, [NotNullWhen(true)] Type?destinationType) { return(destinationType == typeof(string)); }
/// <summary> /// Re-creates an <see cref='object'/> given a set of property values for the object. /// </summary> public virtual object?CreateInstance(ITypeDescriptorContext?context, IDictionary propertyValues) => null;
/// <summary> /// Converts the specified text into an object. /// </summary> public object?ConvertFromString(ITypeDescriptorContext?context, CultureInfo?culture, string text) { return(ConvertFrom(context, culture, text)); }
/// <summary> /// /// Gets a value indicating whether changing a value on this object requires a call to /// <see cref='System.ComponentModel.TypeConverter.CreateInstance(IDictionary)'/> to create a new value, /// using the specified context. /// /// </summary> public virtual bool GetCreateInstanceSupported(ITypeDescriptorContext?context) => false;
public override bool GetStandardValuesSupported(ITypeDescriptorContext?context) => true;
public PropertyDescriptorCollection?GetProperties(ITypeDescriptorContext?context, object value) { return(GetProperties(context, value, new Attribute[] { BrowsableAttribute.Yes })); }
/// <summary> /// Retrieves a collection containing a set of standard values for the data type this validator is designed for. /// </summary> /// <param name="context"> /// An object that provides a format context, which can be used to extract additional /// information about the environment this type converter is being invoked from. /// This parameter or its properties can be <see langword="null" />. /// </param> /// <returns> /// A collection that holds a standard set of valid index values.If no image list is found, /// this collection contains a single object with a value of -1. This method returns<see langword="null" /> /// if the data type doesn't support a standard set of values. /// </returns> public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext?context) { if (context is not null && context.Instance is not null) { object instance = context.Instance; ImageList?imageList = null; PropertyDescriptorCollection listViewItemProps = TypeDescriptor.GetProperties(instance); PropertyDescriptor? listViewProp = listViewItemProps["ListView"]; if (listViewProp is not null) { // Grab the ListView property off of the TreeNode. object?listViewInstance = listViewProp.GetValue(instance); if (listViewInstance is not null) { // Get the ImageList property from the ListView and set it to be the currentImageList. PropertyDescriptorCollection listViewProps = TypeDescriptor.GetProperties(listViewInstance); PropertyDescriptor? listViewImageListProperty = listViewProps["StateImageList"]; if (listViewImageListProperty is not null) { imageList = (ImageList?)listViewImageListProperty.GetValue(listViewInstance); } } } if (imageList is not null) { // Create array to contain standard values object[] values; int nImages = imageList.Images.Count; if (IncludeNoneAsStandardValue) { values = new object[nImages + 1]; values[nImages] = ImageList.Indexer.DefaultIndex; } else { values = new object[nImages]; } // Fill in the array for (int i = 0; i < nImages; i++) { values[i] = i; } return(new StandardValuesCollection(values)); } } if (IncludeNoneAsStandardValue) { return(new StandardValuesCollection(new object[] { ImageList.Indexer.DefaultIndex })); } else { return(new StandardValuesCollection(Array.Empty <object>())); } }
public virtual PropertyDescriptorCollection?GetProperties(ITypeDescriptorContext?context, object value, Attribute[]?attributes) { return(null); }
public override bool GetPropertiesSupported(ITypeDescriptorContext?context) => false;
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext?context, object value, Attribute[]?attributes) { PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(Padding), attributes); return(props.Sort(new string[] { nameof(Padding.All), nameof(Padding.Left), nameof(Padding.Top), nameof(Padding.Right), nameof(Padding.Bottom) })); }