Table of Contents

Class Converter

Namespace
Dynamicweb.Core
Assembly
Dynamicweb.Core.dll

The Converter class provides methods for converting objects into other types. All methods are guaranteed to return a valid default type.

public static class Converter
Inheritance
Converter
Inherited Members

Methods

Deserialize(string, Type)

Deserializes a json string to an object instance.

public static object? Deserialize(string data, Type type)

Parameters

data string

Json string.

type Type

Type of object which should be deserialized.

Returns

object

An object instance, if the provided json string could be deserialized to the given type; otherwise, null.

DeserializeCompact(string, Type)

Deserializes a json string to an object instance.

public static object? DeserializeCompact(string data, Type type)

Parameters

data string

Json string.

type Type

Type of object which should be deserialized.

Returns

object

An object instance, if the provided json string could be deserialized to the given type; otherwise, null.

DeserializeCompact<T>(string)

Deserializes a json string to an object instance.

public static T? DeserializeCompact<T>(string data)

Parameters

data string

Json string.

Returns

T

An object instance, if the provided json string could be deserialized to the given type; otherwise, null.

Type Parameters

T

Type of object which should be deserialized.

Deserialize<T>(string)

Deserializes a json string to an object instance.

public static T? Deserialize<T>(string data)

Parameters

data string

Json string.

Returns

T

An object instance, if the provided json string could be deserialized to the given type; otherwise, null.

Type Parameters

T

Type of object which should be deserialized.

GetGuid()

Gets a new guid object that is not Empty.

public static Guid GetGuid()

Returns

Guid

A guid object.

GetGuidString()

Gets the string representation of a new guid object. The string does not contain dashes.

public static string GetGuidString()

Returns

string

System.String.

GetGuidString(Guid?)

Gets the string representation of the given guid object. The string does not contain dashes.

public static string GetGuidString(Guid? value)

Parameters

value Guid?

The guid to get the string representation of.

Returns

string

System.String.

GetGuidStringWithDashes()

Gets the string representation of a new guid object. The string contains dashes.

public static string GetGuidStringWithDashes()

Returns

string

System.String.

GetGuidStringWithDashes(Guid)

Gets the string representation of the given guid object. The string contains dashes.

public static string GetGuidStringWithDashes(Guid value)

Parameters

value Guid

The guid to get the string representation of.

Returns

string

System.String.

IsGuid(object?)

Determines whether the specified value is a guid.

public static bool IsGuid(object? value)

Parameters

value object

The value.

Returns

bool

true if the specified value is a guid; otherwise, false.

Serialize(object?, Type)

Serializes an object instance to a json string.

public static string Serialize(object? obj, Type type)

Parameters

obj object

Object instance.

type Type

Type of object which should be serialized.

Returns

string

A json string, if the object could be serialized to json; otherwise, an empty string.

SerializeCompact(object?, Type)

Serializes an object instance to a json string - without indentation.

public static string SerializeCompact(object? obj, Type type)

Parameters

obj object

Object instance.

type Type

Type of object which should be serialized.

Returns

string

A json string, if the object could be serialized to json; otherwise, an empty string.

SerializeCompact<T>(T?)

Serializes an object instance to a json string - without indentation.

public static string SerializeCompact<T>(T? obj)

Parameters

obj T

Object instance.

Returns

string

A json string, if the object could be serialized to json; otherwise, an empty string.

Type Parameters

T

Type of object which should be serialized.

Serialize<T>(T?)

Serializes an object instance to a json string.

public static string Serialize<T>(T? obj)

Parameters

obj T

Object instance.

Returns

string

A json string, if the object could be serialized to json; otherwise, an empty string.

Type Parameters

T

Type of object which should be serialized.

ToBoolean(object?)

Tries to parse/convert the object to a boolean and return the value of this result. If this isn't possible, false is returned instead.

public static bool ToBoolean(object? value)

Parameters

value object

Boolean object to determine validity for.

Returns

bool

The value of a valid boolean object (value). In all other cases false.

ToBoolean(string?)

Checks the input string for a true/false statement and returns it as a Boolean.

public static bool ToBoolean(string? value)

Parameters

value string

Returns

bool

Returns a Boolean parsed from the input string.

Remarks

Method is case-insensitive. If the input string is set to an empty string, null, "false", "0", "off" or "no" it returns false. Otherwise true is returned.

ToDateTime(long?)

Parses an object to a DateTime if it represents a DateTime. The default value is returned if the object does not represent a DateTime.

public static DateTime ToDateTime(long? value)

Parameters

value long?

The object to parse.

Returns

DateTime

The DateTime represented by the given object; default(DateTime) if the object cannot be parsed.

ToDateTime(object?)

Parses an object to a DateTime if it represents a DateTime. The default value is returned if the object does not represent a DateTime.

public static DateTime ToDateTime(object? value)

Parameters

value object

The object to parse.

Returns

DateTime

The DateTime represented by the given object; default(DateTime) if the object cannot be parsed.

ToDateTime(object?, DateTime)

Parses an object to a DateTime if it represents a DateTime. The default value is returned if the object does not represent a DateTime.

public static DateTime ToDateTime(object? value, DateTime defaultValue)

Parameters

value object

The object to parse.

defaultValue DateTime

The default value for when the conversion fails

Returns

DateTime

The DateTime represented by the given object; the default value if the object cannot be parsed.

ToDecimal(object?)

Parses the given object into a decimal if possible.

public static decimal ToDecimal(object? value)

Parameters

value object

The object to parse.

Returns

decimal

The decimal represented by the given object; the default value is returned if the value cannot be parsed.

ToDouble(object?)

Parses the given object into a double if possible.

public static double ToDouble(object? value)

Parameters

value object

The object to parse.

Returns

double

The double represented by the given object; the default value is returned if the value cannot be parsed.

ToGuid(object?)

Parses the object into a guid if possible.

public static Guid ToGuid(object? value)

Parameters

value object

The value.

Returns

Guid

The guid that represents the given value if it can be parsed; otherwise Empty.

ToInt32(object?)

Parses the given object into an integer if possible.

public static int ToInt32(object? value)

Parameters

value object

The object to parse.

Returns

int

The integer represented by the given object; the default value is returned if the value cannot be parsed.

ToInt64(object?)

Parses the given object into a long if possible.

public static long ToInt64(object? value)

Parameters

value object

The object to parse.

Returns

long

The long represented by the given object; the default value is returned if the value cannot be parsed.

ToNullableBoolean(object?)

Tries to parse/convert the object to a boolean and return the value of this result. If this isn't possible, null is returned instead.

public static bool? ToNullableBoolean(object? value)

Parameters

value object

Boolean object to determine validity for.

Returns

bool?

The value of a valid boolean object (value). In all other cases false.

ToNullableDateTime(object?, DateTime?)

Parses an object to a DateTime if it represents a DateTime. The default value is returned if the object does not represent a DateTime.

public static DateTime? ToNullableDateTime(object? value, DateTime? defaultValue)

Parameters

value object

The object to parse.

defaultValue DateTime?

The default value for when the conversion fails

Returns

DateTime?

The DateTime represented by the given object; the default value if the object cannot be parsed.

ToNullableDecimal(object?)

Parses the given object into a decimal if possible.

public static decimal? ToNullableDecimal(object? value)

Parameters

value object

The object to parse.

Returns

decimal?

The decimal represented by the given object; the null is returned if the value cannot be parsed.

ToNullableDouble(object?)

Parses the given object into a double if possible.

public static double? ToNullableDouble(object? value)

Parameters

value object

The object to parse.

Returns

double?

The double represented by the given object; the null is returned if the value cannot be parsed.

ToNullableInt32(object?)

Parses the given object into an integer if possible.

public static int? ToNullableInt32(object? value)

Parameters

value object

The object to parse.

Returns

int?

The integer represented by the given object; the null is returned if the value cannot be parsed.

ToNullableInt64(object?)

Parses the given object into a long if possible.

public static long? ToNullableInt64(object? value)

Parameters

value object

The object to parse.

Returns

long?

The long represented by the given object; the null is returned if the value cannot be parsed.

ToString(object?)

Parses an object into a the string that it represents. If null is passed, the empty string is returned.

public static string ToString(object? value)

Parameters

value object

The object to pass to a string.

Returns

string

Returns the string representation of the given object; the empty string if the given object is null.

TryParseEnum<T>(int, out T)

Converts the value to a enum value. Defaults to default value of enum, or first defined enum, if '0' is not a valid enum value.

public static bool TryParseEnum<T>(int value, out T result) where T : struct

Parameters

value int

Enum value

result T

Resulting enum

Returns

bool

isValidEnumValue

Type Parameters

T

TryParseEnum<T>(string, out T)

Converts the value to a enum value. Defaults to default value of enum, or first defined enum, if '0' is not a valid enum value.

public static bool TryParseEnum<T>(string value, out T result) where T : struct

Parameters

value string

Enum value

result T

Resulting enum

Returns

bool

isValidEnumValue

Type Parameters

T
To top