Extensions

Ecng.ComponentModel

Provides a collection of extension methods for components, attributes, and debugging.

Методы

Attrs``2
private static IEnumerable<TAttribute> Attrs<TEntity, TAttribute>(TEntity entity)
result = Extensions.Attrs(entity)

Retrieves all attributes of the specified type from the entity.

CanAutoLogin
public static bool CanAutoLogin(ServerCredentials credentials)
result = Extensions.CanAutoLogin(credentials)

Determines if the server credentials contain sufficient data for auto login.

credentials
The server credentials.

Возвращает: True if auto login is possible; otherwise, false.

GetBasicProperties
public static IEnumerable<ValueTuple<PropertyDescriptor, string>> GetBasicProperties(object instance, int maxDepth)
result = Extensions.GetBasicProperties(instance, maxDepth)

Retrieves basic properties (marked with BasicSettingAttribute) for the given instance, optionally retrieving nested properties recursively.

instance
The object instance.
maxDepth
The maximum recursion depth.

Возвращает: An enumerable of tuples containing the property descriptor and its path.

GetCategory
public static string GetCategory(ICustomAttributeProvider provider, string defaultValue)
result = Extensions.GetCategory(provider, defaultValue)

Retrieves the category name for the given attribute provider using DisplayAttribute or CategoryAttribute.

provider
The custom attribute provider.
defaultValue
The default category if none is found.

Возвращает: The category name.

GetDescription
public static string GetDescription(ICustomAttributeProvider provider, string defaultValue)
result = Extensions.GetDescription(provider, defaultValue)

Retrieves the description for the given attribute provider using DisplayAttribute or DescriptionAttribute.

provider
The custom attribute provider.
defaultValue
The default description if none is found.

Возвращает: The description string.

GetDescription``1
public static string GetDescription<TEntity>(TEntity entity)
result = Extensions.GetDescription(entity)

Retrieves the description for the entity from its DisplayAttribute.

entity
The attribute entity.

Возвращает: The description if set; otherwise, null.

GetDisplayName
public static string GetDisplayName(ICustomAttributeProvider provider, string defaultValue)
result = Extensions.GetDisplayName(provider, defaultValue)

Retrieves the display name for the given attribute provider using DisplayAttribute or DisplayNameAttribute.

provider
The custom attribute provider.
defaultValue
The default value if no display name is found.

Возвращает: The display name.

GetDisplayName
public static string GetDisplayName(PropertyDescriptor pd, string defaultValue)
result = Extensions.GetDisplayName(pd, defaultValue)

Retrieves the display name for the specified property descriptor using DisplayAttribute or DisplayNameAttribute.

pd
The property descriptor.
defaultValue
The default value if no display name is found.

Возвращает: The display name.

GetDisplayName
public static string GetDisplayName(object value)
result = Extensions.GetDisplayName(value)

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.

value
The object for which to get the display name.

Возвращает: The display name.

GetDisplayName``1
public static string GetDisplayName<TEntity>(TEntity entity)
result = Extensions.GetDisplayName(entity)

Retrieves the display name for the entity from its DisplayAttribute.

entity
The attribute entity.

Возвращает: The display name if set; otherwise, null.

GetDisplay``1
public static DisplayAttribute GetDisplay<TEntity>(TEntity entity)
result = Extensions.GetDisplay(entity)

Retrieves the DisplayAttribute from the entity.

entity
The attribute entity.

Возвращает: The DisplayAttribute if exists; otherwise, null.

GetDocUrl
public static string GetDocUrl(Type type)
result = Extensions.GetDocUrl(type)

Retrieves the documentation URL for a type based on its DocAttribute.

type
The type to retrieve the doc URL for.

Возвращает: The documentation URL if available; otherwise, null.

GetFieldDescription
public static string GetFieldDescription(object field)
result = Extensions.GetFieldDescription(field)

Retrieves the description for an enum field using the DisplayAttribute or DescriptionAttribute.

field
The enum field.

Возвращает: The field's description or an empty string if none is provided.

GetFieldDisplayName
public static string GetFieldDisplayName(object field)
result = Extensions.GetFieldDisplayName(field)

Retrieves the display name for an enum field using its custom attributes.

field
The enum field.

Возвращает: The display name associated with the field.

GetFieldIcon
public static Uri GetFieldIcon(object field)
result = Extensions.GetFieldIcon(field)

Retrieves the icon URI for an enum field based on its IconAttribute.

field
The enum field.

Возвращает: The icon URI if available; otherwise, null.

GetFilteredProperties
public static PropertyDescriptorCollection GetFilteredProperties(ICustomTypeDescriptor descriptor, Attribute[] attributes)
result = Extensions.GetFilteredProperties(descriptor, attributes)

Retrieves the filtered property descriptors from a custom type descriptor based on the provided attributes.

descriptor
The custom type descriptor.
attributes
The attributes to filter properties.

Возвращает: A filtered PropertyDescriptorCollection.

GetGroupName``1
public static string GetGroupName<TEntity>(TEntity entity)
result = Extensions.GetGroupName(entity)

Retrieves the group name for the entity from its DisplayAttribute.

entity
The attribute entity.

Возвращает: The group name if set; otherwise, null.

GetIconUrl
public static Uri GetIconUrl(Type type)
result = Extensions.GetIconUrl(type)

Retrieves the icon URL for a type based on its IconAttribute.

type
The type to retrieve the icon URL for.

Возвращает: The icon URI if available; otherwise, null.

GetResourceUrl
private static Uri GetResourceUrl(Assembly assembly, string resName)
result = Extensions.GetResourceUrl(assembly, resName)

Internal helper to build a resource URL for a given assembly and resource name.

assembly
The assembly containing the resource.
resName
The name of the resource.

Возвращает: The constructed resource URI.

GetResourceUrl
public static Uri GetResourceUrl(string resName, Type type)
result = Extensions.GetResourceUrl(resName, type)

Retrieves the resource URL for the given resource name using the specified type's assembly.

resName
The resource name.
type
The type whose assembly is used to obtain the resource.

Возвращает: The resource URI.

GetResourceUrl
public static Uri GetResourceUrl(string resName)
result = Extensions.GetResourceUrl(resName)

Retrieves the resource URL for the given resource name using the entry assembly.

resName
The resource name.

Возвращает: The resource URI.

GetTypeName
private static string GetTypeName(ICustomAttributeProvider provider)
result = Extensions.GetTypeName(provider)

Retrieves the type name from the member information of the custom attribute provider.

provider
The custom attribute provider.

Возвращает: The name of the type.

GetValues
public static IEnumerable<IItemsSourceItem> GetValues(ItemsSourceAttribute attr)
result = Extensions.GetValues(attr)

Retrieves the items source items from an ItemsSourceAttribute instance.

attr
The items source attribute.

Возвращает: An enumerable of IItemsSourceItem.

Get``1
private static TValue Get<TValue>(object field, Func<FieldInfo, TValue> func, Func<object, TValue> getDefault, Func<TValue, TValue, TValue> aggregate, bool canSplit)
result = Extensions.Get(field, func, getDefault, aggregate, canSplit)

Internal helper method to get a value from an enum field using the provided functions.

IsAll``2
private static bool IsAll<TEntity, TAttribute>(TEntity entity, Func<TAttribute, bool> condition)
result = Extensions.IsAll(entity, condition)

Helper method to determine if all attributes of type on the entity satisfy the condition.

IsAny``2
private static bool IsAny<TEntity, TAttribute>(TEntity entity, Func<TAttribute, bool> condition)
result = Extensions.IsAny(entity, condition)

Helper method to determine if any attribute of type on the entity satisfies the condition.

IsBasic``1
public static bool IsBasic<TEntity>(TEntity entity)
result = Extensions.IsBasic(entity)

Checks if the entity has a BasicSettingAttribute.

entity
The attribute entity.

Возвращает: True if the entity is marked as basic; otherwise, false.

IsBrowsable``1
public static bool IsBrowsable<TEntity>(TEntity entity)
result = Extensions.IsBrowsable(entity)

Checks if all BrowsableAttributes on the entity indicate it is browsable.

entity
The attribute entity.

Возвращает: True if the entity is browsable; otherwise, false.

IsReadOnly``1
public static bool IsReadOnly<TEntity>(TEntity entity)
result = Extensions.IsReadOnly(entity)

Checks if the entity is marked as read-only via a ReadOnlyAttribute.

entity
The attribute entity.

Возвращает: True if the entity is read-only; otherwise, false.

IsValid``1
public static bool IsValid<TEntity>(TEntity entity, object value)
result = Extensions.IsValid(entity, value)

Validates the given value against all ValidationAttribute validators on the entity.

entity
The attribute entity.
value
The value to validate.

Возвращает: True if all validators deem the value valid; otherwise, false.

IsWaiting
public static bool IsWaiting(IDebugger debugger)
result = Extensions.IsWaiting(debugger)

Determines whether the debugger is currently waiting for input or output.

debugger
The debugger instance.

Возвращает: True if the debugger is waiting; otherwise, false.

ModifyAttributes``1
public static TEntity ModifyAttributes<TEntity>(TEntity entity, bool add, Attribute attribute)
result = Extensions.ModifyAttributes(entity, add, attribute)

Adds or removes the specified instance (by its runtime type).

entity
Target entity.
add
True to add; false to remove existing with same runtime type.
attribute
Attribute instance to add (ignored when remove).

Возвращает: The same entity instance for chaining.

ModifyAttributes``1
public static TEntity ModifyAttributes<TEntity>(TEntity entity, bool add, Type attrType, Func<Attribute> create)
result = Extensions.ModifyAttributes(entity, add, attrType, create)

Adds or removes attributes of a specific type.

entity
Target entity.
add
True to add; false to remove existing.
attrType
Attribute type to operate on.
create
Factory creating attribute when adding.

Возвращает: The same entity instance for chaining.

ModifyAttributes``2
public static TEntity ModifyAttributes<TEntity, TAttr>(TEntity entity, bool add, Func<TAttr> create)
result = Extensions.ModifyAttributes(entity, add, create)

Adds or removes an attribute created by of type .

entity
Target entity.
add
True to add attribute; false to remove existing ones.
create
Factory for attribute instance (used only when adding).

Возвращает: The same entity instance for chaining.

SetAttribute``2
public static TEntity SetAttribute<TEntity, TAttribute>(TEntity entity, bool value, Func<TAttribute> create)
result = Extensions.SetAttribute(entity, value, create)

Sets or removes an attribute of type for the entity based on the provided value.

entity
The attribute entity.
value
True to add the attribute; false to remove it.
create
A function to create the attribute instance.

Возвращает: The updated attribute entity.

SetBasic``1
public static TEntity SetBasic<TEntity>(TEntity entity, bool isBasic)
result = Extensions.SetBasic(entity, isBasic)

Sets the BasicSettingAttribute for the entity.

entity
The attribute entity.
isBasic
True to mark as basic; otherwise, false.

Возвращает: The updated attribute entity.

SetDisplay``1
public static TEntity SetDisplay<TEntity>(TEntity entity, string groupName, string displayName, string description, int order)
result = Extensions.SetDisplay(entity, groupName, displayName, description, order)

Sets the DisplayAttribute for the entity with specified group, display name, description, and order.

entity
The attribute entity.
groupName
The group/category name.
displayName
The display name.
description
The description text.
order
The display order.

Возвращает: The updated attribute entity.

SetEditor``1
public static TEntity SetEditor<TEntity>(TEntity entity, Attribute editor)
result = Extensions.SetEditor(entity, editor)

Sets a custom editor attribute for the entity.

entity
The attribute entity.
editor
The editor attribute to set.

Возвращает: The updated attribute entity.

SetExpandable``1
public static TEntity SetExpandable<TEntity>(TEntity entity, bool expandable)
result = Extensions.SetExpandable(entity, expandable)

Sets the ExpandableObjectConverter attribute for the entity.

entity
The attribute entity.
expandable
True to set as expandable; otherwise, false.

Возвращает: The updated attribute entity.

SetNonBrowsable``1
public static TEntity SetNonBrowsable<TEntity>(TEntity entity, bool nonBrowsable)
result = Extensions.SetNonBrowsable(entity, nonBrowsable)

Sets the BrowsableAttribute (non-browsable) for the entity.

entity
The attribute entity.
nonBrowsable
True to mark as non-browsable; otherwise, false.

Возвращает: The updated attribute entity.

SetReadOnly``1
public static TEntity SetReadOnly<TEntity>(TEntity entity, bool readOnly)
result = Extensions.SetReadOnly(entity, readOnly)

Sets the ReadOnlyAttribute for the entity.

entity
The attribute entity.
readOnly
True to mark as read-only; otherwise, false.

Возвращает: The updated attribute entity.

SetRequired``1
public static TEntity SetRequired<TEntity>(TEntity entity)
result = Extensions.SetRequired(entity)

Sets a RequiredAttribute as a validator for the entity.

entity
The attribute entity.

Возвращает: The updated attribute entity.

ToN
public static string ToN(Guid id)
result = Extensions.ToN(id)

Converts the Guid to its 32-digit hexadecimal ("N") format.

id
The Guid value.

Возвращает: The "N" formatted string.

TryGetDefault
public static PropertyDescriptor TryGetDefault(PropertyDescriptorCollection properties, Type type)
result = Extensions.TryGetDefault(properties, type)

Attempts to retrieve the default property descriptor from a collection based on the DefaultPropertyAttribute.

properties
The property descriptor collection.
type
The type to check for default property.

Возвращает: The default PropertyDescriptor if found; otherwise, null.

TryGetDefault
public static EventDescriptor TryGetDefault(EventDescriptorCollection events, Type type)
result = Extensions.TryGetDefault(events, type)

Attempts to retrieve the default event descriptor from a collection based on the DefaultEventAttribute.

events
The event descriptor collection.
type
The type to check for default event.

Возвращает: The default EventDescriptor if found; otherwise, null.

TryGetGuid
public static Guid? TryGetGuid(Type controlType)
result = Extensions.TryGetGuid(controlType)

Attempts to retrieve the GUID associated with the specified control type using its GuidAttribute.

controlType
The control type.

Возвращает: The GUID if available; otherwise, null.

Typed
public static IEnumerable<PropertyDescriptor> Typed(PropertyDescriptorCollection col)
result = Extensions.Typed(col)

Casts a PropertyDescriptorCollection to an enumerable of PropertyDescriptor.

col
The collection of property descriptors.

Возвращает: An enumerable of PropertyDescriptor.