paul1956 / CSharpToVB

New version of CSharpToVB converter
MIT License
26 stars 9 forks source link

New Dictionary_Renamed #40

Closed VBAndCs closed 4 years ago

VBAndCs commented 4 years ago

C#

        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.

paul1956 commented 4 years ago

Will be fixed in 4.2.11.0, Converter 3.3.0.0