public static IDictionary<string, object> ObjectToDictionary(object value)
{
var dictionary = value as IDictionary<string, object>;
if (dictionary != null)
{
return new Dictionary<string, object>(dictionary, StringComparer.OrdinalIgnoreCase);
}
dictionary = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
if (value != null)
{
foreach (var helper in GetProperties(value.GetType()))
{
dictionary[helper.Name] = helper.GetValue(value);
}
}
return dictionary;
}
VB:
Option Compare Text
Option Explicit On
Option Infer Off
Option Strict On
Public Shared Function ObjectToDictionary(value As Object) As IDictionary(Of String, Object)
Dim dictionary = TryCast(value, IDictionary(Of String, Object))
If dictionary IsNot Nothing Then
Return New Dictionary_Renamed(Of String, Object)(dictionary, StringComparer.OrdinalIgnoreCase)
End If
dictionary = New Dictionary_Renamed(Of String, Object)(StringComparer.OrdinalIgnoreCase)
If value IsNot Nothing Then
For Each helper In GetProperties(value.GetType())
dictionary(helper.Name) = helper.GetValue(value)
Next
End If
Return dictionary
End Function
Dictionary is a type. You cant rename types. If it's necessary to rename something, it should be a local var. Any other types with New keyword or followed by . can't be renamed unless you find their local declaration in the scope.
C#
VB:
Dictionary is a type. You cant rename types. If it's necessary to rename something, it should be a local var. Any other types with New keyword or followed by . can't be renamed unless you find their local declaration in the scope.