예제 #1
0
        internal static bool IsTypeInList(Collection <string> typeNames)
        {
            // NOTE: we do not use inheritance here, since we deal with
            // value types or with types where inheritance is not a factor for the selection
            string typeName = PSObjectHelper.PSObjectIsOfExactType(typeNames);

            if (string.IsNullOrEmpty(typeName))
            {
                return(false);
            }

            string originalTypeName = Deserializer.MaskDeserializationPrefix(typeName);

            if (string.IsNullOrEmpty(originalTypeName))
            {
                return(false);
            }

            // check if the type is derived from a System.Enum
            // e.g. in C#
            // enum Foo { Red, Black, Green}
            if (PSObjectHelper.PSObjectIsEnum(typeNames))
            {
                return(true);
            }

            return(s_defaultScalarTypesHash.Contains(originalTypeName));
        }
        private static int ComputeDefaultAlignment(PSObject so, PSPropertyExpression ex)
        {
            List <PSPropertyExpressionResult> rList = ex.GetValues(so);

            if ((rList.Count == 0) || (rList[0].Exception != null))
            {
                return(TextAlignment.Left);
            }

            object val = rList[0].Result;

            if (val == null)
            {
                return(TextAlignment.Left);
            }

            PSObject soVal     = PSObject.AsPSObject(val);
            var      typeNames = soVal.InternalTypeNames;

            if (string.Equals(PSObjectHelper.PSObjectIsOfExactType(typeNames),
                              "System.String", StringComparison.OrdinalIgnoreCase))
            {
                return(TextAlignment.Left);
            }

            if (DefaultScalarTypes.IsTypeInList(typeNames))
            {
                return(TextAlignment.Right);
            }

            return(TextAlignment.Left);
        }
예제 #3
0
        private CommandEntry GetActiveCommandEntry(PSObject so)
        {
            string typeName = PSObjectHelper.PSObjectIsOfExactType(so.InternalTypeNames);

            foreach (CommandEntry entry in this.commandEntryList)
            {
                if (entry.AppliesToType(typeName))
                {
                    return(entry);
                }
            }
            return(this.defaultCommandEntry);
        }
예제 #4
0
        /// <summary>
        /// it selects the applicable out command (it can be the default one)
        /// to process the current pipeline object
        /// </summary>
        /// <param name="so">pipeline object to be processed</param>
        /// <returns>applicable command entry</returns>
        private CommandEntry GetActiveCommandEntry(PSObject so)
        {
            string typeName = PSObjectHelper.PSObjectIsOfExactType(so.InternalTypeNames);

            foreach (CommandEntry ce in _commandEntryList)
            {
                if (ce.AppliesToType(typeName))
                {
                    return(ce);
                }
            }

            // failed any match: return the default handler
            return(_defaultCommandEntry);
        }
예제 #5
0
        internal static bool IsTypeInList(Collection <string> typeNames)
        {
            string str = PSObjectHelper.PSObjectIsOfExactType(typeNames);

            if (string.IsNullOrEmpty(str))
            {
                return(false);
            }
            string str2 = Deserializer.MaskDeserializationPrefix(str);

            if (string.IsNullOrEmpty(str2))
            {
                return(false);
            }
            return(PSObjectHelper.PSObjectIsEnum(typeNames) || defaultScalarTypesHash.Contains(str2));
        }
예제 #6
0
        private static int ComputeDefaultAlignment(PSObject so, MshExpression ex)
        {
            List <MshExpressionResult> values = ex.GetValues(so);

            if ((values.Count != 0) && (values[0].Exception == null))
            {
                object result = values[0].Result;
                if (result != null)
                {
                    ConsolidatedString internalTypeNames = PSObject.AsPSObject(result).InternalTypeNames;
                    if (string.Equals(PSObjectHelper.PSObjectIsOfExactType(internalTypeNames), "System.String", StringComparison.OrdinalIgnoreCase))
                    {
                        return(1);
                    }
                    if (DefaultScalarTypes.IsTypeInList(internalTypeNames))
                    {
                        return(3);
                    }
                }
            }
            return(1);
        }