Exemplo n.º 1
0
            /// <summary>
            /// Shifts the value of both this SmartArg and all afterward SmartArg objects
            /// to their next SmartArg. As an intended side effect, the invoking SmartArg is unlinked
            /// from it's connected SmartArg objects.
            /// </summary>
            /// <example>
            /// if:
            /// "b" is SmartArg in question
            ///
            /// before:
            /// [a] [b] [c] [d] [e] (SmartArg)
            /// [1] [2] [3] [4] [ ] (SmartArg value)
            ///
            /// after:
            /// [a] --- [c] [d] [e] (SmartArg)
            /// [1] --- [2] [3] [4] (SmartArg value)
            ///
            /// </example>
            public void Shift()
            {
                SmartArg curSmartArg = this;

                //create list of all afterward SmartArg objects
                List <SmartArg> afterwardSmartArgs = new List <SmartArg>();

                while (curSmartArg.HasNextSmartArg)
                {
                    curSmartArg = curSmartArg.NextSmartArg;
                    afterwardSmartArgs.Add(curSmartArg);
                }

                //reset curSmartArg for next enumeration
                curSmartArg = this;

                //remove last element in list
                afterwardSmartArgs.RemoveAt(afterwardSmartArgs.Count - 1);

                //perform shift
                for (int i = 0; i < afterwardSmartArgs.Count; i--)
                {
                    afterwardSmartArgs[i].ValueStr = afterwardSmartArgs[i].PrevSmartArg.ValueStr;
                }

                //unlink this SmartArg object from its connected SmartArg objects
                this.UnLink();
            }
Exemplo n.º 2
0
            /// <summary>
            /// Constructor that has side effects that impact previously created SmartArg objects
            /// </summary>
            /// <param name="stringArg"></param>
            public SmartArg(string stringArg)
            {
                this.PrevSmartArg = SmartArg.PrevDeclaredSmartArg;
                this.Index        = (this.PrevSmartArg?.Index ?? -1) + 1;
                this.ValueStr     = stringArg ?? "";

                //*** Keep These Statements Last ***
                //make this SmartArg the previously declared SmartArg's "NextSmartArg"
                if (SmartArg.PrevDeclaredSmartArg != (object)null)
                {
                    SmartArg.PrevDeclaredSmartArg.NextSmartArg = this;
                }
                //for the next SmartArg's creation, make this SmartArg the previously declared SmartArg
                SmartArg.PrevDeclaredSmartArg = this;
            }
Exemplo n.º 3
0
            /// <summary>
            /// Unlinks the current SmartArg from the linked list.
            /// Unlinking a SmartArg doesn't make it available for garbage collection.
            /// </summary>
            public void UnLink()
            {
                SmartArg curSmartArg = this;

                //Link previous SmartArg object to next SmartArg object
                if (curSmartArg.HasPrevSmartArg && curSmartArg.HasNextSmartArg)
                {
                    curSmartArg.PrevSmartArg = curSmartArg.NextSmartArg;
                }

                //Unlink this SmartArg from the others
                this.PrevSmartArg = null;
                this.NextSmartArg = null;

                //Correct index values of afterward SmartArg objects
                while (curSmartArg.HasNextSmartArg)
                {
                    curSmartArg = curSmartArg.NextSmartArg;
                    curSmartArg.Index--;
                }
            }
Exemplo n.º 4
0
            public SmartArg(string[] stringArgs)
            {
                this.PrevSmartArg = SmartArg.PrevDeclaredSmartArg;
                this.Index        = (this.PrevSmartArg?.Index ?? -1) + 1;
                try
                {
                    this.ValueStr = stringArgs[this.Index] ?? "";
                }
                catch (IndexOutOfRangeException)
                {
                    this.ValueStr = "";
                }

                //*** Keep These Statements Last ***
                //make this SmartArg the previously declared SmartArg's "NextSmartArg"
                if (SmartArg.PrevDeclaredSmartArg != (object)null)
                {
                    SmartArg.PrevDeclaredSmartArg.NextSmartArg = this;
                }
                //for the next SmartArg's creation, make this SmartArg the previously declared SmartArg
                SmartArg.PrevDeclaredSmartArg = this;
            }