TypeHelper
Provides helper methods for working with types and related operations.
Propriedades
public static string ApplicationName { get; }
value = TypeHelper.ApplicationName
Gets the name of the application.
public static string ApplicationNameWithVersion { get; }
value = TypeHelper.ApplicationNameWithVersion
Gets the name of the application with version.
Métodos
public static T CheckOnNull<T>(T value, string paramName)
result = TypeHelper.CheckOnNull(value, paramName)
Checks if a value is null and throws an exception if it is.
- value
- The value to check for null.
- paramName
- The name of the parameter.
Retorna: Returns the provided value if not null.
public static object CreateInstance(Type type, object[] args)
result = TypeHelper.CreateInstance(type, args)
Creates an instance of the specified type using the given arguments.
- type
- The type to instantiate.
- args
- The constructor arguments.
Retorna: Returns the created instance as an object.
public static T CreateInstance<T>(Type type, object[] args)
result = TypeHelper.CreateInstance(type, args)
Creates an instance of a specified type T using the given arguments.
- type
- The type to instantiate.
- args
- The constructor arguments.
Retorna: Returns the created instance as T.
public static void DoDispose<TSource>(TSource source)
TypeHelper.DoDispose(source)
Disposes the source if it implements IDisposable.
- source
- The instance to dispose.
public static void EnsureRunClass(Type type)
TypeHelper.EnsureRunClass(type)
Ensures the static constructor for a type is run.
- type
- The type to use.
public static Scope EnterScope(ISynchronizable sync)
result = TypeHelper.EnterScope(sync)
Enters a synchronized scope for thread-safe operations on the ISynchronizable.
- sync
- ISynchronizable
Retorna: A Scope that represents the synchronized scope.
public static byte[] GenerateSalt(int saltSize)
result = TypeHelper.GenerateSalt(saltSize)
Generates a salt byte array of the specified size.
- saltSize
- The size of the salt array to create.
Retorna: Returns a byte array representing the salt.
public static object GetDefaultValue(Type type)
result = TypeHelper.GetDefaultValue(type)
Gets the default value for the specified type.
- type
- The type to get the default value for.
Retorna: Returns the default value as an object.
public static Platforms GetPlatform(Type type)
result = TypeHelper.GetPlatform(type)
Retrieves the platform attribute for the specified type.
- type
- The type to inspect.
Retorna: Returns the platform value defined by TargetPlatformAttribute or AnyCPU.
public static string GetTypeAsString(Type type, bool isAssemblyQualifiedName)
result = TypeHelper.GetTypeAsString(type, isAssemblyQualifiedName)
Retrieves the type name as a string either in assembly-qualified form or not.
- type
- The type to convert.
- isAssemblyQualifiedName
- True to return the assembly-qualified name.
Retorna: Returns the string representation of the type.
public static string GetTypeName(Type type, bool isAssemblyQualifiedName)
result = TypeHelper.GetTypeName(type, isAssemblyQualifiedName)
Gets the fully qualified name of a type or its assembly-qualified name.
- type
- The type to convert.
- isAssemblyQualifiedName
- Whether to return the assembly-qualified name.
Retorna: Returns the string representation of the type name.
public static bool HasProperty(object settings, string name)
result = TypeHelper.HasProperty(settings, name)
Checks if a dynamic or regular object has a property with the specified name.
- settings
- The object to inspect.
- name
- The property name.
Retorna: Returns true if the property exists.
public static int HiWord(int iValue)
result = TypeHelper.HiWord(iValue)
Extracts the high word from the integer.
- iValue
- The integer value.
Retorna: Returns the high word.
public static bool Is(Type type, Type baseType, bool canSame)
result = TypeHelper.Is(type, baseType, canSame)
Indicates whether a type is the specified base type or derives from it.
- type
- The type to compare.
- baseType
- The base type.
- canSame
- Allows checking if the types are the same.
Retorna: Returns true if type is or derives from the base type.
public static bool IsAttribute(Type type)
result = TypeHelper.IsAttribute(type)
Determines whether the specified type is an attribute.
- type
- The type to check.
Retorna: Returns true if the type is an attribute.
public static bool IsAutoGenerated(Type type)
result = TypeHelper.IsAutoGenerated(type)
Determines if the specified type is generated by a compiler.
- type
- The type to check.
Retorna: Returns true if the type has a CompilerGeneratedAttribute.
public static bool IsDelegate(Type type)
result = TypeHelper.IsDelegate(type)
Determines whether the specified type is a delegate.
- type
- The type to check.
Retorna: Returns true if the type is a delegate.
public static bool IsEnum(Type type)
result = TypeHelper.IsEnum(type)
Determines whether the specified type is an enum.
- type
- The type to check.
Retorna: Returns true if the type is an enum.
public static bool IsNumeric(Type type)
result = TypeHelper.IsNumeric(type)
Determines if a type is numeric, including floating-point and decimal types.
- type
- The type to check.
Retorna: Returns true if the type is numeric.
public static bool IsNumericInteger(Type type)
result = TypeHelper.IsNumericInteger(type)
Determines if a type is an integer numeric type.
- type
- The type to check.
Retorna: Returns true if the type is an integer numeric type.
public static bool IsPrimitive(Type type)
result = TypeHelper.IsPrimitive(type)
Determines whether a type is considered primitive, including common system types.
- type
- The type to check.
Retorna: Returns true if the type is primitive or commonly handled as a primitive.
public static bool IsStruct(Type type)
result = TypeHelper.IsStruct(type)
Determines whether the specified type is a struct.
- type
- The type to check.
Retorna: Returns true if the type is a struct.
public static bool IsValidWebLink(string link)
result = TypeHelper.IsValidWebLink(link)
Checks if a string is a valid web link.
- link
- The link to check.
Retorna: Returns true if the link is a valid absolute URI.
public static bool IsWebLink(Uri uri)
result = TypeHelper.IsWebLink(uri)
Checks if a URI is a web-based link (http, https, or ftp).
- uri
- The URI to check.
Retorna: Returns true if the URI is web-based.
public static bool Is<TBase>(Type type, bool canSame)
result = TypeHelper.Is(type, canSame)
Indicates whether a type is the specified base type or derives from it.
- type
- The type to compare.
- canSame
- Allows checking if the types are the same.
Retorna: Returns true if type is or derives from the base type.
public static int LoWord(int iValue)
result = TypeHelper.LoWord(iValue)
Extracts the low word from the integer.
- iValue
- The integer value.
Retorna: Returns the low word.
public static Type Make(Type type, Type[] args)
result = TypeHelper.Make(type, args)
Makes a generic type using the provided type arguments.
- type
- The generic type definition.
- args
- The type arguments.
Retorna: Returns the constructed generic type.
public static Type Make(Type type, IEnumerable<Type> args)
result = TypeHelper.Make(type, args)
Makes a generic type using a list of provided type arguments.
- type
- The generic type definition.
- args
- The type arguments as an IEnumerable.
Retorna: Returns the constructed generic type.
public static Exception SingleOrAggr(IList<Exception> errors)
result = TypeHelper.SingleOrAggr(errors)
Returns either a single exception or an aggregate if there are multiple exceptions.
- errors
- A collection of exceptions.
Retorna: Returns one exception or an AggregateException.
public static int SizeOf(Type type)
result = TypeHelper.SizeOf(type)
Returns the size in bytes of the specified unmanaged type.
- type
- The type whose size is to be computed.
Retorna: The size in bytes of the specified type.
public static int SizeOf<T>()
result = TypeHelper.SizeOf()
Returns the size in bytes of an unmanaged type T.
Retorna: The size in bytes of the specified type.
public static Scope<T> ToScope<T>(T value, bool ownInstance)
result = TypeHelper.ToScope(value, ownInstance)
Creates a scope for the specified value with optional ownership.
- value
- The resource to be scoped.
- ownInstance
- Whether the scope owns the instance.
Retorna: Returns the newly created Scope.