.Net: Is a good idea to use reflection on Android devices, while I'm getting only public fields?

Viewed 27

I'm building an app for android devices with the .net standard (Unity).

And I have used reflection to iterate throw all public properties in a model.

I have read some articles about reflection on Java and they didn't recommend using Reflection on JAVA, the reflection will get all the properties even private ones. But on C# is a bit different, we can specify which property to get based on visibility.

So does apply the same and for C#, is it a good idea to use it?

Sorry, I'm new to Reflection, and I couldn't find any information about this case. One benefit of using reflection in my case is that I have to type fewer lines of code.

Here is the code I'm using.

    public static KeyValuePair<string, DateTime> IncomingTimingOld(TimingOld timing)
    {
        Type type = typeof(TimingOld);
        Dictionary<string, DateTime> propValues = GetValuesOld(timing, type);
       //...
    }

    private static Dictionary<string, DateTime> GetValuesOld(TimingOld timing, Type type)
    {
        // Get the public properties.
        return type.GetProperties(BindingFlags.Public | BindingFlags.Instance)
            .OrderBy(t => t.GetValue(timing))
            .ToDictionary(t => t.Name, t => Convert.ToDateTime(t.GetValue(timing)));
    }
0 Answers
Related