コード例 #1
0
 internal static object DecodeObject(object obj, Type type)
 {
     if (obj == null)
     {
         return(obj);
     }
     if (type == typeof(PSObject))
     {
         return(DecodePSObject(obj));
     }
     if (type == typeof(System.Management.Automation.Runspaces.Runspace))
     {
         return(RemoteRunspace.FromPSObjectForRemoting(PSObject.AsPSObject(obj)));
     }
     if (type == typeof(ProgressRecord))
     {
         return(ProgressRecord.FromPSObjectForRemoting(PSObject.AsPSObject(obj)));
     }
     if (IsKnownType(type))
     {
         return(obj);
     }
     if (obj is SecureString)
     {
         return(obj);
     }
     if (obj is PSCredential)
     {
         return(obj);
     }
     if ((obj is PSObject) && (type == typeof(PSCredential)))
     {
         PSObject obj2 = (PSObject)obj;
         try
         {
             return(new PSCredential((string)obj2.Properties["UserName"].Value, (SecureString)obj2.Properties["Password"].Value));
         }
         catch (GetValueException)
         {
             return(null);
         }
     }
     if ((obj is int) && type.IsEnum)
     {
         return(Enum.ToObject(type, (int)obj));
     }
     if ((obj is string) && (type == typeof(CultureInfo)))
     {
         return(new CultureInfo((string)obj));
     }
     if ((obj is PSObject) && (type == typeof(Exception)))
     {
         return(DecodeException((PSObject)obj));
     }
     if ((obj is PSObject) && (type == typeof(object[])))
     {
         return(DecodeObjectArray((PSObject)obj));
     }
     if ((obj is PSObject) && type.IsArray)
     {
         return(DecodeArray((PSObject)obj, type));
     }
     if ((obj is PSObject) && IsCollection(type))
     {
         return(DecodeCollection((PSObject)obj, type));
     }
     if ((obj is PSObject) && IsDictionary(type))
     {
         return(DecodeDictionary((PSObject)obj, type));
     }
     if ((obj is PSObject) && IsEncodingAllowedForClassOrStruct(type))
     {
         return(DecodeClassOrStruct((PSObject)obj, type));
     }
     if ((obj is PSObject) && IsGenericIEnumerableOfInt(type))
     {
         return(DecodeCollection((PSObject)obj, typeof(Collection <int>)));
     }
     if ((obj is PSObject) && (type == typeof(RemoteHostCall)))
     {
         return(RemoteHostCall.Decode((PSObject)obj));
     }
     if (!(obj is PSObject) || (type != typeof(RemoteHostResponse)))
     {
         throw RemoteHostExceptions.NewRemoteHostDataDecodingNotSupportedException(type);
     }
     return(RemoteHostResponse.Decode((PSObject)obj));
 }