Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable deserialization for OAuthPrompt Dialog With TypeHandling.None #3294

Merged
merged 5 commits into from
Jan 25, 2020

Conversation

kvbreddy
Copy link
Member

This PR is to provide an option to use safe deserialization (TypeHandling.None) of OAuthPrompt dialog instead of requiring to use TypeHandling.All.

Partially fixes this issue #2437.

Added an extensions method on object which can be used in other places so that other Dialogs can also this for safe deserialization.

   public static T CastTo<T>(this object obj)
    {
        if (obj is T asT)
        {
            return asT;
        }
        else if (obj is JObject asJobject)
        {
            // If types are not used by storage serialization, and Newtonsoft is the serializer
            // the item found can be a JObject.
            return asJobject.ToObject<T>();
        }
        else if (obj is JArray asJarray)
        {
            // If types are not used by storage serialization, and Newtonsoft is the serializer
            // the item found can be a JArray.
            return asJarray.ToObject<T>();
        }
        else if (obj == null)
        {
            return default(T);
        }
        else
        {
            throw new InvalidOperationException("Data is not in the correct format for casting.");
        }

@coveralls
Copy link
Collaborator

coveralls commented Jan 24, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants