示例#1
0
 internal ExceptionHandlerNode(Token token, TypeLiteral exceptionType, ParseTreeNode body)
     : this(token, exceptionType != null ? new ExceptionTypeList() : (ExceptionTypeList)null, body, false)
 {
     if (exceptionType == null)
     {
         return;
     }
     this._exceptionTypes.Add(exceptionType);
 }
        private object ExecuteConversion(object operand, Token op)
        {
            Type type = new TypeLiteral(op).Type;

            if (!type.Equals(typeof(void)))
            {
                return(Parser.ConvertTo(operand, type, op));
            }
            this.IsVoidable = true;
            return((object)AutomationNull.Value);
        }
 private void ApplyTypeConstraints(List <Token> preOperators)
 {
     if (!(this._expression is IAssignableParseTreeNode expression) || this._prefix != null || this._postfix != null)
     {
         return;
     }
     for (int index = preOperators.Count - 1; index >= 0 && preOperators[index].Is(TokenId.TypeToken); --index)
     {
         TypeLiteral typeLiteral = new TypeLiteral(preOperators[index]);
         expression.TypeConstraint.Add(typeLiteral);
         preOperators.RemoveAt(index);
     }
 }
示例#4
0
        internal RuntimeDefinedParameter GetRuntimeDefinedParameter(bool isCmdlet)
        {
            TypeLiteral            lastType   = ParameterNode.GetLastType(this._parameter.TypeConstraint);
            Collection <Attribute> attributes = new Collection <Attribute>();
            bool flag = false;

            foreach (AttributeNode attribute1 in this._attributes)
            {
                Attribute attribute2 = attribute1.GetAttribute();
                if (attribute2 != null)
                {
                    if (attribute2 is ParameterAttribute)
                    {
                        flag = true;
                    }
                    attributes.Add(attribute2);
                }
            }
            if (isCmdlet && !flag)
            {
                ParameterAttribute parameterAttribute = new ParameterAttribute();
                attributes.Insert(0, (Attribute)parameterAttribute);
            }
            RuntimeDefinedParameter definedParameter = lastType != null ? new RuntimeDefinedParameter(this._parameter.VariableName, lastType, attributes) : new RuntimeDefinedParameter(this._parameter.VariableName, typeof(object), attributes);

            if (this._initializer != null)
            {
                definedParameter.Value = (object)this._initializer;
            }
            else if (definedParameter.ParameterType == typeof(string))
            {
                definedParameter.Value = (object)"";
            }
            else if (definedParameter.ParameterType == typeof(bool))
            {
                definedParameter.Value = (object)false;
            }
            else if (definedParameter.ParameterType == typeof(SwitchParameter))
            {
                definedParameter.Value = (object)new SwitchParameter(false);
            }
            else if (LanguagePrimitives.IsNumeric(LanguagePrimitives.GetTypeCode(definedParameter.ParameterType)))
            {
                definedParameter.Value = (object)0;
            }
            return(definedParameter);
        }
示例#5
0
 internal RuntimeDefinedParameter(
     string name,
     TypeLiteral typeLiteral,
     Collection <Attribute> attributes)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw RuntimeDefinedParameter.tracer.NewArgumentException(nameof(name));
     }
     if (typeLiteral == null)
     {
         throw RuntimeDefinedParameter.tracer.NewArgumentNullException(nameof(typeLiteral));
     }
     this.name        = name;
     this.typeLiteral = typeLiteral;
     if (attributes == null)
     {
         return;
     }
     this.attributes = attributes;
 }
示例#6
0
        internal bool IsSwitchParameter()
        {
            TypeLiteral lastType = ParameterNode.GetLastType(this._parameter.TypeConstraint);

            return(lastType != null && lastType.IsSwitchParameter);
        }