Extensions
Provides a collection of extension methods for components, attributes, and debugging.
方法
private static IEnumerable<TAttribute> Attrs<TEntity, TAttribute>(TEntity entity)
result = Extensions.Attrs(entity)
Retrieves all attributes of the specified type from the entity.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.