Class Extensions
- Namespace
- Ecng.ComponentModel
- Assembly
- Ecng.ComponentModel.dll
Provides a collection of extension methods for components, attributes, and debugging.
public static class Extensions
- Inheritance
-
Extensions
- Inherited Members
Methods
CanAutoLogin(ServerCredentials)
Determines if the server credentials contain sufficient data for auto login.
public static bool CanAutoLogin(this ServerCredentials credentials)
Parameters
credentialsServerCredentialsThe server credentials.
Returns
- bool
True if auto login is possible; otherwise, false.
GetBasicProperties(object, int)
Retrieves basic properties (marked with BasicSettingAttribute) for the given instance, optionally retrieving nested properties recursively.
public static IEnumerable<(PropertyDescriptor prop, string path)> GetBasicProperties(this object instance, int maxDepth = 0)
Parameters
Returns
- IEnumerable<(PropertyDescriptor prop, string path)>
An enumerable of tuples containing the property descriptor and its path.
GetCategory(ICustomAttributeProvider, string)
Retrieves the category name for the given attribute provider using DisplayAttribute or CategoryAttribute.
public static string GetCategory(this ICustomAttributeProvider provider, string defaultValue = null)
Parameters
providerICustomAttributeProviderThe custom attribute provider.
defaultValuestringThe default category if none is found.
Returns
- string
The category name.
GetDescription(ICustomAttributeProvider, string)
Retrieves the description for the given attribute provider using DisplayAttribute or DescriptionAttribute.
public static string GetDescription(this ICustomAttributeProvider provider, string defaultValue = null)
Parameters
providerICustomAttributeProviderThe custom attribute provider.
defaultValuestringThe default description if none is found.
Returns
- string
The description string.
GetDescription<TEntity>(TEntity)
Retrieves the description for the entity from its DisplayAttribute.
public static string GetDescription<TEntity>(this TEntity entity) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
Returns
- string
The description if set; otherwise, null.
Type Parameters
TEntityThe type of the attribute entity.
GetDisplayName(PropertyDescriptor, string)
Retrieves the display name for the specified property descriptor using DisplayAttribute or DisplayNameAttribute.
public static string GetDisplayName(this PropertyDescriptor pd, string defaultValue = null)
Parameters
pdPropertyDescriptorThe property descriptor.
defaultValuestringThe default value if no display name is found.
Returns
- string
The display name.
GetDisplayName(object)
Retrieves the display name of the given object. If the object is an Enum, its field display name is returned; otherwise, it uses custom attribute providers or type name.
public static string GetDisplayName(this object value)
Parameters
valueobjectThe object for which to get the display name.
Returns
- string
The display name.
GetDisplayName(ICustomAttributeProvider, string)
Retrieves the display name for the given attribute provider using DisplayAttribute or DisplayNameAttribute.
public static string GetDisplayName(this ICustomAttributeProvider provider, string defaultValue = null)
Parameters
providerICustomAttributeProviderThe custom attribute provider.
defaultValuestringThe default value if no display name is found.
Returns
- string
The display name.
GetDisplayName<TEntity>(TEntity)
Retrieves the display name for the entity from its DisplayAttribute.
public static string GetDisplayName<TEntity>(this TEntity entity) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
Returns
- string
The display name if set; otherwise, null.
Type Parameters
TEntityThe type of the attribute entity.
GetDisplay<TEntity>(TEntity)
Retrieves the DisplayAttribute from the entity.
public static DisplayAttribute GetDisplay<TEntity>(this TEntity entity) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
Returns
- DisplayAttribute
The DisplayAttribute if exists; otherwise, null.
Type Parameters
TEntityThe type of the attribute entity.
GetDocUrl(Type)
Retrieves the documentation URL for a type based on its DocAttribute.
public static string GetDocUrl(this Type type)
Parameters
typeTypeThe type to retrieve the doc URL for.
Returns
- string
The documentation URL if available; otherwise, null.
GetFieldDescription(object)
Retrieves the description for an enum field using the DisplayAttribute or DescriptionAttribute.
public static string GetFieldDescription(this object field)
Parameters
fieldobjectThe enum field.
Returns
- string
The field's description or an empty string if none is provided.
GetFieldDisplayName(object)
Retrieves the display name for an enum field using its custom attributes.
public static string GetFieldDisplayName(this object field)
Parameters
fieldobjectThe enum field.
Returns
- string
The display name associated with the field.
GetFieldIcon(object)
Retrieves the icon URI for an enum field based on its IconAttribute.
public static Uri GetFieldIcon(this object field)
Parameters
fieldobjectThe enum field.
Returns
- Uri
The icon URI if available; otherwise, null.
GetFilteredProperties(ICustomTypeDescriptor, Attribute[])
Retrieves the filtered property descriptors from a custom type descriptor based on the provided attributes.
public static PropertyDescriptorCollection GetFilteredProperties(this ICustomTypeDescriptor descriptor, Attribute[] attributes)
Parameters
descriptorICustomTypeDescriptorThe custom type descriptor.
attributesAttribute[]The attributes to filter properties.
Returns
- PropertyDescriptorCollection
A filtered PropertyDescriptorCollection.
GetGroupName<TEntity>(TEntity)
Retrieves the group name for the entity from its DisplayAttribute.
public static string GetGroupName<TEntity>(this TEntity entity) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
Returns
- string
The group name if set; otherwise, null.
Type Parameters
TEntityThe type of the attribute entity.
GetIconUrl(Type)
Retrieves the icon URL for a type based on its IconAttribute.
public static Uri GetIconUrl(this Type type)
Parameters
typeTypeThe type to retrieve the icon URL for.
Returns
- Uri
The icon URI if available; otherwise, null.
GetResourceUrl(string)
Retrieves the resource URL for the given resource name using the entry assembly.
public static Uri GetResourceUrl(this string resName)
Parameters
resNamestringThe resource name.
Returns
- Uri
The resource URI.
GetResourceUrl(string, Type)
Retrieves the resource URL for the given resource name using the specified type's assembly.
public static Uri GetResourceUrl(this string resName, Type type)
Parameters
Returns
- Uri
The resource URI.
GetValues(ItemsSourceAttribute)
Retrieves the items source items from an ItemsSourceAttribute instance.
public static IEnumerable<IItemsSourceItem> GetValues(this ItemsSourceAttribute attr)
Parameters
attrItemsSourceAttributeThe items source attribute.
Returns
- IEnumerable<IItemsSourceItem>
An enumerable of IItemsSourceItem.
IsBasic<TEntity>(TEntity)
Checks if the entity has a BasicSettingAttribute.
public static bool IsBasic<TEntity>(this TEntity entity) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
Returns
- bool
True if the entity is marked as basic; otherwise, false.
Type Parameters
TEntityThe type of the attribute entity.
IsBrowsable<TEntity>(TEntity)
Checks if all BrowsableAttributes on the entity indicate it is browsable.
public static bool IsBrowsable<TEntity>(this TEntity entity) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
Returns
- bool
True if the entity is browsable; otherwise, false.
Type Parameters
TEntityThe type of the attribute entity.
IsReadOnly<TEntity>(TEntity)
Checks if the entity is marked as read-only via a ReadOnlyAttribute.
public static bool IsReadOnly<TEntity>(this TEntity entity) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
Returns
- bool
True if the entity is read-only; otherwise, false.
Type Parameters
TEntityThe type of the attribute entity.
IsValid<TEntity>(TEntity, object)
Validates the given value against all ValidationAttribute validators on the entity.
public static bool IsValid<TEntity>(this TEntity entity, object value) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
valueobjectThe value to validate.
Returns
- bool
True if all validators deem the value valid; otherwise, false.
Type Parameters
TEntityThe type of the attribute entity.
IsWaiting(IDebugger)
Determines whether the debugger is currently waiting for input or output.
public static bool IsWaiting(this IDebugger debugger)
Parameters
debuggerIDebuggerThe debugger instance.
Returns
- bool
True if the debugger is waiting; otherwise, false.
SetAttribute<TEntity, TAttribute>(TEntity, bool, Func<TAttribute>)
Sets or removes an attribute of type TAttribute for the entity based on the provided value.
public static TEntity SetAttribute<TEntity, TAttribute>(this TEntity entity, bool value, Func<TAttribute> create) where TEntity : IAttributesEntity where TAttribute : Attribute
Parameters
entityTEntityThe attribute entity.
valueboolTrue to add the attribute; false to remove it.
createFunc<TAttribute>A function to create the attribute instance.
Returns
- TEntity
The updated attribute entity.
Type Parameters
TEntityThe type of the attribute entity.
TAttributeThe type of attribute to set.
SetBasic<TEntity>(TEntity, bool)
Sets the BasicSettingAttribute for the entity.
public static TEntity SetBasic<TEntity>(this TEntity entity, bool isBasic = true) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
isBasicboolTrue to mark as basic; otherwise, false.
Returns
- TEntity
The updated attribute entity.
Type Parameters
TEntityThe type of the attribute entity.
SetDisplay<TEntity>(TEntity, string, string, string, int)
Sets the DisplayAttribute for the entity with specified group, display name, description, and order.
public static TEntity SetDisplay<TEntity>(this TEntity entity, string groupName, string displayName, string description, int order) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
groupNamestringThe group/category name.
displayNamestringThe display name.
descriptionstringThe description text.
orderintThe display order.
Returns
- TEntity
The updated attribute entity.
Type Parameters
TEntityThe type of the attribute entity.
SetEditor<TEntity>(TEntity, Attribute)
Sets a custom editor attribute for the entity.
public static TEntity SetEditor<TEntity>(this TEntity entity, Attribute editor) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
editorAttributeThe editor attribute to set.
Returns
- TEntity
The updated attribute entity.
Type Parameters
TEntityThe type of the attribute entity.
SetExpandable<TEntity>(TEntity, bool)
Sets the ExpandableObjectConverter attribute for the entity.
public static TEntity SetExpandable<TEntity>(this TEntity entity, bool expandable) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
expandableboolTrue to set as expandable; otherwise, false.
Returns
- TEntity
The updated attribute entity.
Type Parameters
TEntityThe type of the attribute entity.
SetNonBrowsable<TEntity>(TEntity, bool)
Sets the BrowsableAttribute (non-browsable) for the entity.
public static TEntity SetNonBrowsable<TEntity>(this TEntity entity, bool nonBrowsable = true) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
nonBrowsableboolTrue to mark as non-browsable; otherwise, false.
Returns
- TEntity
The updated attribute entity.
Type Parameters
TEntityThe type of the attribute entity.
SetReadOnly<TEntity>(TEntity, bool)
Sets the ReadOnlyAttribute for the entity.
public static TEntity SetReadOnly<TEntity>(this TEntity entity, bool readOnly = true) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
readOnlyboolTrue to mark as read-only; otherwise, false.
Returns
- TEntity
The updated attribute entity.
Type Parameters
TEntityThe type of the attribute entity.
SetRequired<TEntity>(TEntity)
Sets a RequiredAttribute as a validator for the entity.
public static TEntity SetRequired<TEntity>(this TEntity entity) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
Returns
- TEntity
The updated attribute entity.
Type Parameters
TEntityThe type of the attribute entity.
SetValidator<TEntity>(TEntity, ValidationAttribute)
Adds a custom validation attribute as a validator for the entity.
public static TEntity SetValidator<TEntity>(this TEntity entity, ValidationAttribute validator) where TEntity : IAttributesEntity
Parameters
entityTEntityThe attribute entity.
validatorValidationAttributeThe validation attribute to add.
Returns
- TEntity
The updated attribute entity.
Type Parameters
TEntityThe type of the attribute entity.
ToN(Guid)
Converts the Guid to its 32-digit hexadecimal ("N") format.
public static string ToN(this Guid id)
Parameters
idGuidThe Guid value.
Returns
- string
The "N" formatted string.
TryGetDefault(EventDescriptorCollection, Type)
Attempts to retrieve the default event descriptor from a collection based on the DefaultEventAttribute.
public static EventDescriptor TryGetDefault(this EventDescriptorCollection events, Type type)
Parameters
eventsEventDescriptorCollectionThe event descriptor collection.
typeTypeThe type to check for default event.
Returns
- EventDescriptor
The default EventDescriptor if found; otherwise, null.
TryGetDefault(PropertyDescriptorCollection, Type)
Attempts to retrieve the default property descriptor from a collection based on the DefaultPropertyAttribute.
public static PropertyDescriptor TryGetDefault(this PropertyDescriptorCollection properties, Type type)
Parameters
propertiesPropertyDescriptorCollectionThe property descriptor collection.
typeTypeThe type to check for default property.
Returns
- PropertyDescriptor
The default PropertyDescriptor if found; otherwise, null.
TryGetGuid(Type)
Attempts to retrieve the GUID associated with the specified control type using its GuidAttribute.
public static Guid? TryGetGuid(this Type controlType)
Parameters
controlTypeTypeThe control type.
Returns
- Guid?
The GUID if available; otherwise, null.
Typed(PropertyDescriptorCollection)
Casts a PropertyDescriptorCollection to an enumerable of PropertyDescriptor.
public static IEnumerable<PropertyDescriptor> Typed(this PropertyDescriptorCollection col)
Parameters
colPropertyDescriptorCollectionThe collection of property descriptors.
Returns
- IEnumerable<PropertyDescriptor>
An enumerable of PropertyDescriptor.