facebook-csharp-sdk / simple-json

JSON library for .NET 2.0+/SL4+/WP7/WindowsStore with optional support for dynamic and DataContract
MIT License
382 stars 143 forks source link

iterate over TypeInfo hierarchy to find all properties #49

Closed shiftkey closed 10 years ago

shiftkey commented 10 years ago

Tried to update Octokit.net from 0.30 to 0.34 and found this regression.

Here's the simplest fix that gets me back to a happy place...

prabirshrestha commented 10 years ago

Have you looked at https://github.com/facebook-csharp-sdk/simple-json/pull/47

Recursion was one of my first thought and to later move it to iteration. But I did find GetRuntimeProperties that does the same.

prabirshrestha commented 10 years ago

Also in the meantime can u send a pr to reflection-utils.

shiftkey commented 10 years ago

@prabirshrestha If I've got no good reason to use GetRuntimeProperties I'll push a PR to reflection-utils in the morning

shiftkey commented 10 years ago

Oh, and would you prefer this PR or what's currently in #47?

prabirshrestha commented 10 years ago

@shiftkey @haacked this fix should be available in v0.36.0 now. I already updated the reflection-utils project too to include this fix.

Never got a reply on this tweet, so will stick to the recursive solution. https://twitter.com/PrabirShrestha/status/439190680213409792

haacked commented 10 years ago

Hmm, too bad David didn't answer on Twitter. Maybe we can mention him here. Hey @davkean, any thoughts? The other person to try on Twitter is @terrajobst

terrajobst commented 10 years ago

The best person to talk to is @nguerrera. He's da reflection man.

Sorry for the delay. type.GetRuntimeProperties() is the equivalent of calling

type.GetProperties(BindingFlags.Instance |
                   BindingFlags.Static |
                   BindingFlags.Public |
                   BindingFlags.NonPublic)

in the old world.

Does this answer your question?

shiftkey commented 10 years ago

@terrajobst

@prabirshrestha leave those PRs with me

prabirshrestha commented 10 years ago
public static IEnumerable<PropertyInfo> GetProperties(Type type)
{
#if SIMPLE_JSON_TYPEINFO
    return type.GetRuntimeProperties();
#else
    return type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
#endif
}

@terrajobst seems exactly what we need. Thanks.

@shiftkey also would need to do the same for GetFields()

shiftkey commented 10 years ago

@prabirshrestha done, review away!

prabirshrestha commented 10 years ago

@Haacked @shiftkey v0.38.0 is now available on nuget which makes use of GetRuntimeProperties()