Converter

Ecng.Common

The converter class.

Propriedades

EnumFallback
public static Func<Type, string, object> EnumFallback { get; set; }
value = Converter.EnumFallback
Converter.EnumFallback = value

Fallback handler for Enum conversion from string when value is not found. Returns the resolved enum value, or null to throw exception.

TypeFallback
public static Func<string, Type> TypeFallback { get; set; }
value = Converter.TypeFallback
Converter.TypeFallback = value

Fallback handler for Type conversion from string when type is not found. Returns the resolved type, or null to throw exception.

Métodos

AddCSharpAlias
public static void AddCSharpAlias(Type type, string alias)
Converter.AddCSharpAlias(type, alias)

Adds a C# language alias for a type.

type
The type to add an alias for.
alias
The C# alias to associate with the type.
AddTypedConverter
public static void AddTypedConverter(ValueTuple<Type, Type> key, Func<object, object> converter)
Converter.AddTypedConverter(key, converter)

Adds a typed converter function for converting between specified types.

key
Tuple containing source and destination types.
converter
The converter function to add.
AddTypedConverter``2
public static void AddTypedConverter<TFrom, TTo>(Func<TFrom, TTo> converter)
Converter.AddTypedConverter(converter)

Adds a typed converter function for converting from TFrom to TTo type.

converter
The converter function to add.
AsInvariant
public static Action AsInvariant(Action action)
result = Converter.AsInvariant(action)

Wraps an action to execute using the invariant culture.

action
The action to wrap.

Retorna: An action that executes using the invariant culture.

AsInvariant``1
public static Func<T> AsInvariant<T>(Func<T> func)
result = Converter.AsInvariant(func)

Wraps a function to execute using the invariant culture.

func
The function to wrap.

Retorna: A function that executes using the invariant culture.

ChangeOrder
public static byte[] ChangeOrder(byte[] bytes, int length, bool isLittleEndian, int pos)
result = Converter.ChangeOrder(bytes, length, isLittleEndian, pos)

Reverses the byte order if the specified endianness differs from the system endianness.

bytes
The byte array to modify.
length
The number of bytes to consider.
isLittleEndian
Specifies the desired endianness.
pos
The starting position within the array.

Retorna: The modified byte array.

DoInCulture
public static void DoInCulture(CultureInfo cultureInfo, Action action)
Converter.DoInCulture(cultureInfo, action)

Executes an action using the specified culture.

cultureInfo
The culture to use during execution.
action
The action to execute.
DoInCulture``1
public static T DoInCulture<T>(CultureInfo cultureInfo, Func<T> func)
result = Converter.DoInCulture(cultureInfo, func)

Executes a function using the specified culture.

cultureInfo
The culture to use during execution.
func
The function to execute.

Retorna: The result of the function execution.

GetHost
public static string GetHost(EndPoint endPoint)
result = Converter.GetHost(endPoint)

Retrieves the host from the specified endpoint.

endPoint
The endpoint to extract the host from.

Retorna: The host string.

GetPort
public static int GetPort(EndPoint endPoint)
result = Converter.GetPort(endPoint)

Retrieves the port number from the specified endpoint.

endPoint
The endpoint to extract the port from.

Retorna: The port number.

GetTypedConverter
public static Func<object, object> GetTypedConverter(Type from, Type to)
result = Converter.GetTypedConverter(from, to)

Gets the typed converter function for converting between specified types.

from
The source type to convert from.
to
The destination type to convert to.

Retorna: A converter function for the specified types.

GetTypedConverter``2
public static Func<TFrom, TTo> GetTypedConverter<TFrom, TTo>()
result = Converter.GetTypedConverter()

Gets the typed converter function for converting between specified types.

Retorna: A converter function for the specified types.

SetHost
public static EndPoint SetHost(EndPoint endPoint, string host)
result = Converter.SetHost(endPoint, host)

Sets the host on the specified endpoint.

endPoint
The endpoint to modify.
host
The new host name or IP address.

Retorna: The modified endpoint.

SetPort
public static EndPoint SetPort(EndPoint endPoint, int port)
result = Converter.SetPort(endPoint, port)

Sets the port number on the specified endpoint.

endPoint
The endpoint to modify.
port
The new port number.

Retorna: The modified endpoint.

To
public static object To(object value, Type destinationType)
result = Converter.To(value, destinationType)

Convert value into a instance of .

value
The value.
destinationType
Type of the destination.

Retorna: Converted object.

ToRadix
public static string ToRadix(long decimalNumber, int radix)
result = Converter.ToRadix(decimalNumber, radix)

Converts the given decimal number to the numeral system with the specified radix (in the range [2, 36]).

decimalNumber
The number to convert.
radix
The radix of the destination numeral system (in the range [2, 36]).
To``1
public static T To<T>(object value)
result = Converter.To(value)

Convert value into a instance of destinationType.

value
The value.

Retorna: Converted object.

TryGetCSharpAlias
public static string TryGetCSharpAlias(Type type)
result = Converter.TryGetCSharpAlias(type)

Attempts to get the C# language alias for a type.

type
The type to get the alias for.

Retorna: The C# alias if found; otherwise null.

TryGetTypeByCSharpAlias
public static Type TryGetTypeByCSharpAlias(string alias)
result = Converter.TryGetTypeByCSharpAlias(alias)

Attempts to get a type by its C# language alias.

alias
The C# alias to look up.

Retorna: The corresponding type if found; otherwise null.

TypedTo``2
public static TTo TypedTo<TFrom, TTo>(TFrom from)
result = Converter.TypedTo(from)

Converts the value from source type to destination type using registered type converters.

from
The value to convert.

Retorna: The converted value.