Ejemplo n.º 1
0
        public static object TranslateCmdletProxyParameter(object paramValue, ExchangeRunspaceConfigurationSettings.ProxyMethod proxyMethod)
        {
            if (paramValue == null)
            {
                return(null);
            }
            Type type = paramValue.GetType();

            if (type.IsPrimitive)
            {
                return(paramValue);
            }
            if (paramValue is IDictionary)
            {
                return(ProxyHelper.TranslateCmdletProxyDictionaryParameter(paramValue, proxyMethod));
            }
            if (paramValue is ICollection)
            {
                return(ProxyHelper.TranslateCmdletProxyCollectionParameter(paramValue, proxyMethod));
            }
            if (type == typeof(IIdentityParameter))
            {
                return(paramValue.ToString());
            }
            if (type == typeof(SwitchParameter))
            {
                return(((SwitchParameter)paramValue).IsPresent);
            }
            return(paramValue.ToString());
        }
Ejemplo n.º 2
0
        internal static void BuildCommandFromParameter(string parameterName, object parameterValue, StringBuilder commandBuilder)
        {
            if (parameterValue == null)
            {
                commandBuilder.AppendFormat(" -{0}:{1}", parameterName, ProxyHelper.nullString);
                return;
            }
            Type type = parameterValue.GetType();

            if (type == typeof(bool))
            {
                commandBuilder.AppendFormat(" -{0}:${1}", parameterName, parameterValue);
                return;
            }
            if (type == typeof(SwitchParameter))
            {
                commandBuilder.AppendFormat(" -{0}:${1}", parameterName, ((SwitchParameter)parameterValue).IsPresent);
                return;
            }
            string stringContent;

            if (parameterValue is IDictionary)
            {
                stringContent = ProxyHelper.TranslateCmdletProxyDictionaryParameter(parameterValue, ExchangeRunspaceConfigurationSettings.ProxyMethod.PSWS).ToString();
            }
            else
            {
                if (parameterValue is ICollection)
                {
                    string arg = ProxyHelper.TranslateCmdletProxyCollectionParameter(parameterValue, ExchangeRunspaceConfigurationSettings.ProxyMethod.PSWS).ToString();
                    commandBuilder.AppendFormat(" -{0}:{1}", parameterName, arg);
                    return;
                }
                stringContent = parameterValue.ToString();
            }
            commandBuilder.AppendFormat(" -{0}:'{1}'", parameterName, ProxyHelper.EscapeSingleQuotedString(stringContent));
        }