Class DataHelper
This class contains methods for validating, converting and manipulating data types commonly used in applications.
Inherited Members
Namespace: DataWeb.Data
Assembly: DataWeb.Core.dll
Syntax
public static class DataHelper
Methods
ConvertStringToValue(string, string)
Converts the specified string representation to the specified data type.
Declaration
public static object ConvertStringToValue(string stringValue, string dataType)
Parameters
| Type | Name | Description |
|---|---|---|
| string | stringValue | The string representation of the value to convert. |
| string | dataType | The data type to convert the string value to. Valid values are "Boolean", "Integer", "Decimal", "Date", "DateTime", "DateTimeOffset" and "String". |
Returns
| Type | Description |
|---|---|
| object | The converted value. |
ConvertValueToString(object, string)
Converts the specified value to a string representation of the specified data type.
Declaration
public static string ConvertValueToString(object value, string dataType)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The value to convert. |
| string | dataType | The data type of the value to convert. Valid values are "Boolean", "Integer", "Decimal", "Date", "DateTime", "DateTimeOffset" and "String". |
Returns
| Type | Description |
|---|---|
| string | A string representation of the specified value. |
IsValidValue(object, string)
Determines whether the specified value can be converted to the specified data type.
Declaration
public static bool IsValidValue(object value, string dataType)
Parameters
| Type | Name | Description |
|---|---|---|
| object | value | The value to validate. |
| string | dataType | The data type to validate the value against. Valid values are "Boolean", "Integer", "Decimal", "Date", "DateTime", "DateTimeOffset" and "String". |
Returns
| Type | Description |
|---|---|
| bool | True if the value can be converted to the specified data type, false otherwise. |
MergeDictionaries<TKey, TValue>(Dictionary<TKey, TValue>, Dictionary<TKey, TValue>)
Merges two dictionaries into a single dictionary.
In case of duplicate keys, the values from existingValues take precedence.
Declaration
public static Dictionary<TKey, TValue> MergeDictionaries<TKey, TValue>(Dictionary<TKey, TValue> existingValues, Dictionary<TKey, TValue> providedValues)
Parameters
| Type | Name | Description |
|---|---|---|
| Dictionary<TKey, TValue> | existingValues | The base dictionary whose values take precedence in case of key conflicts. Can be null. |
| Dictionary<TKey, TValue> | providedValues | The dictionary to merge with the base dictionary. Can be null. |
Returns
| Type | Description |
|---|---|
| Dictionary<TKey, TValue> | A new dictionary containing the merged key-value pairs. The order of elements is not guaranteed. |
Type Parameters
| Name | Description |
|---|---|
| TKey | The type of keys in the dictionaries. |
| TValue | The type of values in the dictionaries. |
MergeStringValues(List<string>, List<string>)
Merges two lists of strings into a single list without duplicates.
Declaration
public static List<string> MergeStringValues(List<string> existingValues, List<string> providedValues)
Parameters
| Type | Name | Description |
|---|---|---|
| List<string> | existingValues | The first list of string values. Can be null. |
| List<string> | providedValues | The second list of string values to merge. Can be null. |
Returns
| Type | Description |
|---|---|
| List<string> | A list containing all unique string values from both input lists. The order of elements is not guaranteed. |
RemoveMilliseconds(DateTime)
Removes the milliseconds component of a DateTime value.
Declaration
public static DateTime RemoveMilliseconds(DateTime date)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTime | date | The DateTime value to remove the milliseconds from. |
Returns
| Type | Description |
|---|---|
| DateTime | A new DateTime value without the milliseconds component. |
RemoveMilliseconds(DateTimeOffset)
Removes the milliseconds component of a DateTimeOffset value.
Declaration
public static DateTimeOffset RemoveMilliseconds(DateTimeOffset date)
Parameters
| Type | Name | Description |
|---|---|---|
| DateTimeOffset | date | The DateTimeOffset value to remove the milliseconds from. |
Returns
| Type | Description |
|---|---|
| DateTimeOffset | A new DateTimeOffset value without the milliseconds component. |