Exemplo n.º 1
0
        public void Collection()
        {
            VariableCollection variables = new VariableCollection
            {
                new Variable("var"),
                new Variable("var"),
                new Variable("var2")
            };

            Assert.IsFalse(variables.IsReadOnly);
            Assert.AreEqual(2, variables.Count);
            {
                Variable[] arr = new Variable[variables.Count];
                variables.CopyTo(arr, 0);
                foreach (object?v in ((IEnumerable)arr))
                {
                    Assert.IsTrue(arr.Contains(v));
                }
            }
            Assert.IsTrue(variables.Contains(new Variable("var2")));
            Assert.IsTrue(variables.Remove(new Variable("var2")));
            Assert.AreEqual(1, variables.Count);
            variables.Clear();
            StringTemplate st = new StringTemplate("abc", new[] { new Variable("A") });

            variables.Collect(new[] { st });
            Assert.IsTrue(variables.Contains(new Variable("A")));
        }
Exemplo n.º 2
0
        public bool SatisfiesFormula(Formula formula)
        {
            VariableCollection variable = _expressionContext.Variables;

            foreach (var statu in _status)
            {
                variable.Add(statu.Key.ToString(), statu.Value);
            }
            bool eval = _expressionContext.CompileGeneric <bool>(formula.Expression).Evaluate();

            variable.Clear();
            return(eval);
        }
Exemplo n.º 3
0
 /// <summary>Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1" />.</summary>
 /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1" /> is read-only. </exception>
 public void Clear()
 {
     _collection.Clear();
 }
        public void Primer()
        {
            //ExStart
            //ExFor:Document.Variables
            //ExFor:VariableCollection
            //ExFor:VariableCollection.Add
            //ExFor:VariableCollection.Clear
            //ExFor:VariableCollection.Contains
            //ExFor:VariableCollection.Count
            //ExFor:VariableCollection.GetEnumerator
            //ExFor:VariableCollection.IndexOfKey
            //ExFor:VariableCollection.Remove
            //ExFor:VariableCollection.RemoveAt
            //ExSummary:Shows how to work with a document's variable collection.
            Document           doc       = new Document();
            VariableCollection variables = doc.Variables;

            // Documents have a variable collection to which name/value pairs can be added
            variables.Add("Home address", "123 Main St.");
            variables.Add("City", "London");
            variables.Add("Bedrooms", "3");

            Assert.AreEqual(3, variables.Count);

            // Variables can be referenced and have their values presented in the document by DOCVARIABLE fields
            DocumentBuilder  builder = new DocumentBuilder(doc);
            FieldDocVariable field   = (FieldDocVariable)builder.InsertField(FieldType.FieldDocVariable, true);

            field.VariableName = "Home address";
            field.Update();

            Assert.AreEqual("123 Main St.", field.Result);

            // Assigning values to existing keys will update them
            variables.Add("Home address", "456 Queen St.");

            // DOCVARIABLE fields also need to be updated in order to show an accurate up to date value
            field.Update();

            Assert.AreEqual("456 Queen St.", field.Result);

            // The existence of variables can be looked up either by name or value like this
            Assert.True(variables.Contains("City"));
            Assert.True(variables.Any(v => v.Value == "London"));

            // Variables are automatically sorted in alphabetical order
            Assert.AreEqual(0, variables.IndexOfKey("Bedrooms"));
            Assert.AreEqual(1, variables.IndexOfKey("City"));
            Assert.AreEqual(2, variables.IndexOfKey("Home address"));

            // Enumerate over the collection of variables
            using (IEnumerator <KeyValuePair <string, string> > enumerator = doc.Variables.GetEnumerator())
                while (enumerator.MoveNext())
                {
                    Console.WriteLine($"Name: {enumerator.Current.Key}, Value: {enumerator.Current.Value}");
                }

            // Variables can be removed either by name or index, or the entire collection can be cleared at once
            variables.Remove("City");

            Assert.False(variables.Contains("City"));

            variables.RemoveAt(1);

            Assert.False(variables.Contains("Home address"));

            variables.Clear();

            Assert.That(variables, Is.Empty);
            //ExEnd
        }
Exemplo n.º 5
0
        public void Primer()
        {
            //ExStart
            //ExFor:Document.Variables
            //ExFor:VariableCollection
            //ExFor:VariableCollection.Add
            //ExFor:VariableCollection.Clear
            //ExFor:VariableCollection.Contains
            //ExFor:VariableCollection.Count
            //ExFor:VariableCollection.GetEnumerator
            //ExFor:VariableCollection.IndexOfKey
            //ExFor:VariableCollection.Remove
            //ExFor:VariableCollection.RemoveAt
            //ExSummary:Shows how to work with a document's variable collection.
            Document           doc       = new Document();
            VariableCollection variables = doc.Variables;

            // Every document has a collection of key/value pair variables, which we can add items to.
            variables.Add("Home address", "123 Main St.");
            variables.Add("City", "London");
            variables.Add("Bedrooms", "3");

            Assert.AreEqual(3, variables.Count);

            // We can display the values of variables in the document body using DOCVARIABLE fields.
            DocumentBuilder  builder = new DocumentBuilder(doc);
            FieldDocVariable field   = (FieldDocVariable)builder.InsertField(FieldType.FieldDocVariable, true);

            field.VariableName = "Home address";
            field.Update();

            Assert.AreEqual("123 Main St.", field.Result);

            // Assigning values to existing keys will update them.
            variables.Add("Home address", "456 Queen St.");

            // We will then have to update DOCVARIABLE fields to ensure they display an up-to-date value.
            Assert.AreEqual("123 Main St.", field.Result);

            field.Update();

            Assert.AreEqual("456 Queen St.", field.Result);

            // Verify that the document variables with a certain name or value exist.
            Assert.True(variables.Contains("City"));
            Assert.True(variables.Any(v => v.Value == "London"));

            // The collection of variables automatically sorts variables alphabetically by name.
            Assert.AreEqual(0, variables.IndexOfKey("Bedrooms"));
            Assert.AreEqual(1, variables.IndexOfKey("City"));
            Assert.AreEqual(2, variables.IndexOfKey("Home address"));

            // Enumerate over the collection of variables.
            using (IEnumerator <KeyValuePair <string, string> > enumerator = doc.Variables.GetEnumerator())
                while (enumerator.MoveNext())
                {
                    Console.WriteLine($"Name: {enumerator.Current.Key}, Value: {enumerator.Current.Value}");
                }

            // Below are three ways of removing document variables from a collection.
            // 1 -  By name:
            variables.Remove("City");

            Assert.False(variables.Contains("City"));

            // 2 -  By index:
            variables.RemoveAt(1);

            Assert.False(variables.Contains("Home address"));

            // 3 -  Clear the whole collection at once:
            variables.Clear();

            Assert.That(variables, Is.Empty);
            //ExEnd
        }