示例#1
0
        public CommandParam(CommandParam copy)
        {
            this.name        = copy.name;
            this.type        = copy.Type;
            this.parent      = null;
            this.nextParam   = null;
            this.value       = copy.value;
            this.stringValue = copy.stringValue;
            this.charIndex   = copy.charIndex;
            this.lineIndex   = copy.lineIndex;

            // Copy array children.
            this.count = 0;
            if (type == CommandParamType.Array)
            {
                foreach (CommandParam copyChild in copy.GetChildren())
                {
                    AddChild(new CommandParam(copyChild));
                }
            }
        }
示例#2
0
        //-----------------------------------------------------------------------------
        // Constructor
        //-----------------------------------------------------------------------------

        // Recursively check whether the parameters are matching, outputting the new parameters.
        private static bool AreParametersMatching(CommandReferenceParam reference, CommandParam userParams, out CommandParam newParameters)
        {
            newParameters = null;

            if (reference == null)
            {
                newParameters = new CommandParam(userParams);
                return(true);
            }
            if (!userParams.IsValidType(reference.Type))
            {
                newParameters = null;
                return(false);
            }

            // Make sure arrays are matching.
            if (reference.Type == CommandParamType.Array)
            {
                newParameters      = new CommandParam(CommandParamType.Array);
                newParameters.Name = reference.Name;

                // Find the child index of the first parameter with a default value.
                int defaultIndex = 0;
                for (CommandReferenceParam p = reference.Children; p != null; p = p.NextParam)
                {
                    if (p.DefaultValue != null)
                    {
                        break;
                    }
                    defaultIndex++;
                }

                // Check if the reference is variadic on the last parameter.
                CommandReferenceParam lastRefChild = reference.GetChildren().LastOrDefault();
                bool isVariadic = false;
                if (lastRefChild != null && lastRefChild.IsVariadic)
                {
                    isVariadic = true;
                }

                // Verify the user parameter's child count is within the valid range.
                if (userParams.ChildCount < defaultIndex ||
                    (userParams.ChildCount > reference.ChildCount && !isVariadic))
                {
                    newParameters = null;
                    return(false);
                }

                // Verify each child paremeter matches the reference.
                CommandReferenceParam referenceChild = reference.Children;
                CommandParam          userChild      = userParams.Children;
                int count = reference.ChildCount;
                if (isVariadic)
                {
                    count = Math.Max(count, userParams.ChildCount);
                }
                for (int i = 0; i < count; i++)
                {
                    CommandParam newChild;
                    if (i < userParams.ChildCount)
                    {
                        if (!AreParametersMatching(referenceChild, userChild, out newChild))
                        {
                            newParameters = null;
                            return(false);
                        }
                        userChild = userChild.NextParam;
                    }
                    else
                    {
                        newChild = new CommandParam(referenceChild.DefaultValue);
                    }
                    newParameters.AddChild(newChild);
                    if (referenceChild.NextParam != null)
                    {
                        referenceChild = referenceChild.NextParam;
                    }
                }
            }
            else
            {
                if (userParams.Type == CommandParamType.Array)
                {
                    newParameters = new CommandParam(CommandParamType.Array);
                    foreach (CommandParam userChild in userParams.GetChildren())
                    {
                        newParameters.AddChild(new CommandParam(userChild));
                    }
                }
                else
                {
                    newParameters = new CommandParam(reference);
                    newParameters.SetValueByParse(userParams.StringValue);
                }
            }

            return(true);
        }
示例#3
0
 //-----------------------------------------------------------------------------
 // Script Commands
 //-----------------------------------------------------------------------------
 private void CommandProperties(CommandParam parameters)
 {
     foreach (CommandParam child in parameters.GetChildren())
         ParseProperty(child);
 }
示例#4
0
        public CommandParam(CommandParam copy)
        {
            this.name			= copy.name;
            this.type			= copy.Type;
            this.parent			= null;
            this.nextParam		= null;
            this.value			= copy.value;
            this.stringValue	= copy.stringValue;
            this.charIndex		= copy.charIndex;
            this.lineIndex		= copy.lineIndex;

            // Copy array children.
            this.count = 0;
            if (type == CommandParamType.Array) {
                foreach (CommandParam copyChild in copy.GetChildren())
                    AddChild(new CommandParam(copyChild));
            }
        }
        //-----------------------------------------------------------------------------
        // Constructor
        //-----------------------------------------------------------------------------
        // Recursively check whether the parameters are matching, outputting the new parameters.
        private static bool AreParametersMatching(CommandReferenceParam reference, CommandParam userParams, out CommandParam newParameters)
        {
            newParameters = null;

            if (reference == null) {
                newParameters = new CommandParam(userParams);
                return true;
            }
            if (!userParams.IsValidType(reference.Type)) {
                newParameters = null;
                return false;
            }

            // Make sure arrays are matching.
            if (reference.Type == CommandParamType.Array) {
                newParameters = new CommandParam(CommandParamType.Array);
                newParameters.Name = reference.Name;

                // Find the child index of the first parameter with a default value.
                int defaultIndex = 0;
                for (CommandReferenceParam p = reference.Children; p != null; p = p.NextParam) {
                    if (p.DefaultValue != null)
                        break;
                    defaultIndex++;
                }

                // Check if the reference is variadic on the last parameter.
                CommandReferenceParam lastRefChild = reference.GetChildren().LastOrDefault();
                bool isVariadic = false;
                if (lastRefChild != null && lastRefChild.IsVariadic)
                    isVariadic = true;

                // Verify the user parameter's child count is within the valid range.
                if (userParams.ChildCount < defaultIndex ||
                    (userParams.ChildCount > reference.ChildCount && !isVariadic))
                {
                    newParameters = null;
                    return false;
                }

                // Verify each child paremeter matches the reference.
                CommandReferenceParam referenceChild = reference.Children;
                CommandParam userChild = userParams.Children;
                int count = reference.ChildCount;
                if (isVariadic)
                    count = Math.Max(count, userParams.ChildCount);
                for (int i = 0; i < count; i++) {
                    CommandParam newChild;
                    if (i < userParams.ChildCount) {
                        if (!AreParametersMatching(referenceChild, userChild, out newChild)) {
                            newParameters = null;
                            return false;
                        }
                        userChild = userChild.NextParam;
                    }
                    else {
                        newChild = new CommandParam(referenceChild.DefaultValue);
                    }
                    newParameters.AddChild(newChild);
                    if (referenceChild.NextParam != null)
                        referenceChild = referenceChild.NextParam;
                }
            }
            else {
                if (userParams.Type == CommandParamType.Array) {
                    newParameters = new CommandParam(CommandParamType.Array);
                    foreach (CommandParam userChild in userParams.GetChildren())
                        newParameters.AddChild(new CommandParam(userChild));
                }
                else {
                    newParameters = new CommandParam(reference);
                    newParameters.SetValueByParse(userParams.StringValue);
                }
            }

            return true;
        }