Created
August 29, 2015 08:23
-
-
Save dmannock/16955da7bcb5013cb3dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class DynamicHelpers | |
| { | |
| public static Dictionary<TKey, TValue> ToDictionary<TKey, TValue>(dynamic dyn) | |
| { | |
| Dictionary<TKey, TValue> output = new Dictionary<TKey, TValue>(); | |
| foreach (var kvp in dyn as IDictionary<TKey, object>) | |
| { | |
| output.Add( | |
| (TKey)Convert.ChangeType(kvp.Key, typeof(TKey)), | |
| (TValue)Convert.ChangeType(kvp.Value, typeof(TValue)) | |
| ); | |
| } | |
| return output; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment