Created
March 13, 2014 09:27
-
-
Save vishalkdotcom/9525059 to your computer and use it in GitHub Desktop.
Convert Microsoft.VisualBasic.Collection to Dictionary [C# Extension Method]
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 Dictionary<string, object> ToDictionary(this Collection source) | |
| { | |
| Dictionary<string, object> dic = new Dictionary<string, object>(); | |
| if (source != null) | |
| { | |
| BindingFlags flg = BindingFlags.Instance | BindingFlags.NonPublic; | |
| object InternalList = source.GetType().GetMethod("InternalItemsList", flg).Invoke(source, null); | |
| for (int qq = 0; qq <= source.Count - 1; qq++) | |
| { | |
| object item = InternalList.GetType().GetProperty("Item", flg).GetValue(InternalList, new object[] { qq }); | |
| string key = item.GetType().GetField("m_Key", flg).GetValue(item).ToString(); | |
| object value = item.GetType().GetField("m_Value", flg).GetValue(item); | |
| dic.Add(key, value); | |
| } | |
| } | |
| return dic; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment