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.
- Inheritance
-
Converter
- Inherited Members
Methods
Deserialize(string, Type)
Deserializes a json string to an object instance.
Parameters
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.
Parameters
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.
Parameters
data
stringJson 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.
Parameters
data
stringJson 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.
Returns
- Guid
A guid object.
GetGuidString()
Gets the string representation of a new guid object. The string does not contain dashes.
Returns
- string
System.String.
GetGuidString(Guid?)
Gets the string representation of the given guid object. The string does not contain dashes.
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.
Returns
- string
System.String.
GetGuidStringWithDashes(Guid)
Gets the string representation of the given guid object. The string contains dashes.
Parameters
value
GuidThe guid to get the string representation of.
Returns
- string
System.String.
IsGuid(object?)
Determines whether the specified value is a guid.
Parameters
value
objectThe value.
Returns
- bool
true
if the specified value is a guid; otherwise,false
.
Serialize(object?, Type)
Serializes an object instance to a json string.
Parameters
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.
Parameters
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.
Parameters
obj
TObject 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.
Parameters
obj
TObject 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.
Parameters
value
objectBoolean object to determine validity for.
Returns
- bool
The value of a valid boolean object (
value
). In all other casesfalse
.
ToBoolean(string?)
Checks the input string for a true/false statement and returns it as a Boolean.
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.
Parameters
value
long?The object to parse.
Returns
- Date
Time 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.
Parameters
value
objectThe object to parse.
Returns
- Date
Time 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.
Parameters
value
objectThe object to parse.
defaultValue
DateTime The default value for when the conversion fails
Returns
- Date
Time 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.
Parameters
value
objectThe 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.
Parameters
value
objectThe 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.
Parameters
value
objectThe value.
Returns
ToInt32(object?)
Parses the given object into an integer if possible.
Parameters
value
objectThe 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.
Parameters
value
objectThe 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.
Parameters
value
objectBoolean object to determine validity for.
Returns
- bool?
The value of a valid boolean object (
value
). In all other casesfalse
.
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.
Parameters
value
objectThe object to parse.
defaultValue
DateTime ?The default value for when the conversion fails
Returns
- Date
Time ? 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.
Parameters
value
objectThe 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.
Parameters
value
objectThe 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.
Parameters
value
objectThe 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.
Parameters
value
objectThe 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.
Parameters
value
objectThe 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.
Parameters
value
intEnum value
result
TResulting 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.
Parameters
value
stringEnum value
result
TResulting enum
Returns
- bool
isValidEnumValue
Type Parameters
T