private static PSObject EncodeDictionary(IDictionary dictionary) { if (RemoteHostEncoder.IsObjectDictionaryType(dictionary.GetType())) { return(RemoteHostEncoder.EncodeObjectDictionary(dictionary)); } Hashtable hashtable = new Hashtable(); foreach (object key in (IEnumerable)dictionary.Keys) { hashtable.Add(RemoteHostEncoder.EncodeObject(key), RemoteHostEncoder.EncodeObject(dictionary[key])); } return(new PSObject((object)hashtable)); }
private static IDictionary DecodeDictionary(PSObject psObject, Type dictionaryType) { if (RemoteHostEncoder.IsObjectDictionaryType(dictionaryType)) { return(RemoteHostEncoder.DecodeObjectDictionary(psObject, dictionaryType)); } Type[] genericArguments = dictionaryType.GetGenericArguments(); Type type1 = genericArguments[0]; Type type2 = genericArguments[1]; Hashtable baseObject = RemoteHostEncoder.SafelyGetBaseObject <Hashtable>(psObject); IDictionary instance = (IDictionary)Activator.CreateInstance(dictionaryType); foreach (object key in (IEnumerable)baseObject.Keys) { instance.Add(RemoteHostEncoder.DecodeObject(key, type1), RemoteHostEncoder.DecodeObject(baseObject[key], type2)); } return(instance); }