Пример #1
0
        protected bool Equals(MutablePair <TLeft, TRight> other)
        {
            if (other is null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            return(EqualityComparer <TLeft> .Default.Equals(Left, other.Left) && EqualityComparer <TRight> .Default.Equals(Right, other.Right));
        }
        /// <summary>
        /// Gets the string to draw for a list item.
        /// </summary>
        /// <param name="x">The list item.</param>
        /// <returns>The string to draw for a list item.</returns>
        static KeyValuePair<string, string> GetDrawString(MutablePair<CharacterTemplateID, ushort> x)
        {
            var keyStr = x.Key.ToString();

            var itm = CharacterTemplateManager.Instance;
            if (itm != null)
            {
                var template = itm[x.Key];
                if (template != null)
                    keyStr += " [" + template.TemplateTable.Name + "]";
            }
            keyStr += " - ";

            return new KeyValuePair<string, string>(keyStr, x.Value.ToString());
        }
Пример #3
0
        /// <summary>
        /// Gets the string to draw for a list item.
        /// </summary>
        /// <param name="x">The list item.</param>
        /// <returns>The string to draw for a list item.</returns>
        static KeyValuePair <string, string> GetDrawString(MutablePair <CharacterTemplateID, ushort> x)
        {
            var keyStr = x.Key.ToString();

            var itm = CharacterTemplateManager.Instance;

            if (itm != null)
            {
                var template = itm[x.Key];
                if (template != null)
                {
                    keyStr += " [" + template.TemplateTable.Name + "]";
                }
            }
            keyStr += " - ";

            return(new KeyValuePair <string, string>(keyStr, x.Value.ToString()));
        }
        /// <summary>
        /// Handles the Click event of the btnAdd control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnAdd_Click(object sender, EventArgs e)
        {
            // Validate
            if (!_selectedItem.HasValue)
            {
                MessageBox.Show("You must select an item to add first.");
                return;
            }

            if (RequireDistinct)
            {
                if (
                    lstItems.Items.Cast <MutablePair <CharacterTemplateID, ushort> >().Any(
                        x => _selectedItem.HasValue && x.Key == _selectedItem.Value))
                {
                    MessageBox.Show("That item is already in the list.");
                    _selectedItem = null;
                    return;
                }
            }

            byte amount;

            if (!byte.TryParse(txtAmount.Text, out amount))
            {
                MessageBox.Show("Invalid amount specified.");
                return;
            }

            // Add
            var newItem = new MutablePair <CharacterTemplateID, ushort>(_selectedItem.Value, amount);

            lstItems.Items.Add(newItem);

            if (RequireDistinct)
            {
                _selectedItem = null;
                txtItem.Text  = string.Empty;
            }

            // Select the new item
            lstItems.SelectedItem = newItem;
        }
Пример #5
0
        /// <summary>
        /// Runs the tests!
        /// </summary>
        /// <param name="sketch"></param>
        /// <param name="filename"></param>
        public override void run(Sketch.Sketch sketch, string filename)
        {
            // store the first filename as a way to tell what user we're working on.
            if (_filename == null)
            {
                _filename = filename;
            }

            Dictionary <ShapeType, MutablePair <int, int> > sketchResults = new Dictionary <ShapeType, MutablePair <int, int> >();

            foreach (ShapeType type in LogicDomain.Gates)
            {
                sketchResults.Add(type, MutablePair.Create(0, 0));
            }

            Sketch.Sketch handLabeled = sketch.Clone();

            _pipeline.process(sketch);

            foreach (Sketch.Shape correctShape in handLabeled.Shapes)
            {
                if (!LogicDomain.IsGate(correctShape.Type))
                {
                    continue;
                }

                Sketch.Shape resultShape = sketch.ShapesL.Find(delegate(Sketch.Shape s) { return(s.GeometricEquals(correctShape)); });

                if (resultShape == null)
                {
                    throw new Exception("Could not find shape.");
                }

                sketchResults[correctShape.Type].Item1++;
                if (resultShape.Type == correctShape.Type)
                {
                    sketchResults[correctShape.Type].Item2++;
                }
            }

            _results.Add(sketchResults);
        }
        /// <summary>
        /// Handles the Click event of the btnAdd control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void btnAdd_Click(object sender, EventArgs e)
        {
            // Validate
            if (!_selectedItem.HasValue)
            {
                MessageBox.Show("You must select an item to add first.");
                return;
            }

            if (RequireDistinct)
            {
                if (
                    lstItems.Items.OfType<MutablePair<ItemTemplateID, byte>>().Any(
                        x => _selectedItem.HasValue && x.Key == _selectedItem.Value))
                {
                    MessageBox.Show("That item is already in the list.");
                    _selectedItem = null;
                    return;
                }
            }

            byte amount;
            if (!byte.TryParse(txtAmount.Text, out amount))
            {
                MessageBox.Show("Invalid amount specified.");
                return;
            }

            // Add
            var newItem = new MutablePair<ItemTemplateID, byte>(_selectedItem.Value, amount);
            lstItems.Items.Add(newItem);

            if (RequireDistinct)
            {
                _selectedItem = null;
                txtItem.Text = string.Empty;
            }

            // Select the new item
            lstItems.SelectedItem = newItem;
        }
Пример #7
0
 public PreparedMoney(MutablePair <Banknote, int> data)
 {
     Nominal = data.Key.Nominal;
     Number  = data.Value;
 }
Пример #8
0
    public static void Main(String[] args)
    {
        Type testTypeAccessCode = typeof(System.String[]);

        Pair p;

        p = new Pair(1, new Pair(2, new Pair(3, Null.NULL)));
        foreach (Object o in p) {
        System.Console.WriteLine(o);
        }

        try {
        p = new Pair(321, 2);
        System.Console.WriteLine(p.Car);
        p.Car = 123;
        System.Console.WriteLine(p.Car);
        } catch (InvalidOperationException ioe) {
        System.Console.WriteLine(ioe);
        }

        p = new MutablePair(321, 2);
        System.Console.WriteLine(p.Car);
        p.Car = 123;
        System.Console.WriteLine(p.Car);

        Test t = new Test();
        MethodInfo mi;

        mi = t.GetType().GetMethod("GetVal",
                   BindingFlags.Public | BindingFlags.Instance,
                   null,
                   CallingConventions.Any,
                   new Type[] { typeof(B), typeof(B) },
                   null);
        System.Console.WriteLine(mi);
        System.Console.WriteLine(mi.IsStatic);

        mi = t.GetType().GetMethod("GetVal",
                   BindingFlags.Public | BindingFlags.Static,
                   null,
                   CallingConventions.Any,
                   new Type[] { typeof(B), typeof(B) },
                   null);
        System.Console.WriteLine(mi);
        System.Console.WriteLine(mi.IsStatic);

        mi = t.GetType().GetMethod("NeedInt",
                   BindingFlags.Public | BindingFlags.Instance,
                   null,
                   CallingConventions.Any,
                   new Type[] { typeof(int) },
                   null);
        System.Console.WriteLine(mi);

        mi = t.GetType().GetMethod("NeedInt",
                   BindingFlags.Public | BindingFlags.Instance,
                   null,
                   CallingConventions.Any,
                   new Type[] { typeof(Int32) },
                   null);
        System.Console.WriteLine(mi);

        System.Console.WriteLine(Type.GetType("System.Object"));
        System.Console.WriteLine(Type.GetType("System.Object[]"));
        System.Console.WriteLine(Type.GetType("System.Void"));

        TestVA("hi");
        TestVA("hi", "there");
        TestVA("hi", "there", 1, 2, 3, new object[] { "a", "b" });

        PlayWith("TestVA");
        PlayWith("TestVA2");
    }
Пример #9
0
 public List ToList()
 {
     ensureArray();
     List result = Null.NULL;
     for (int i = _chars.Length - 1; i >= 0; i--)
     result = new MutablePair(_chars[i], result);
     return result;
 }