private void btnVisitor1_Click(object sender, EventArgs e) { txtResult.Text = "VISITOR Pattern #1" + Environment.NewLine; txtResult.Text += "Some of the result is written to Output window" + Environment.NewLine; Element objectStructure = new Element( new Element( new ElementWithLink( new Element( new Element( new ElementWithLink( new Element(null), new Element( null)))), new Element( new Element( new Element(null)))))); txtResult.Text += "Count the elements:" + Environment.NewLine; CountVisitor visitor = new CountVisitor(); visitor.CountElements(objectStructure); txtResult.Text += "Number of Elements are: " + visitor.Count + Environment.NewLine; }
public AdvertisementController(IAdvertisementService _advertisementService) { advertisementService = _advertisementService; newAdvertisement = new NewAdvertisement(_advertisementService); countVisitor = new CountVisitor(_advertisementService); deleteAdvertisement = new DeleteAdvertisement(_advertisementService); editAdvertisement = new EditAdvertisement(_advertisementService); }
public void Search_SimpleTwoOrExpressions_Ok() { var expression1 = Search.CreateSearchParameter("inStock", "true").Or(Search.CreateSearchParameter("id", "1234")); var expression2 = Search.CreateSearchParameter("productName", "Monitor").Or(Search.CreateSearchParameter("brand", "dell")); var resultExpression = expression1.And(expression2); var countVisitor = new CountVisitor(); countVisitor.CountParameters(resultExpression); }
public void CountNumberOfElementsInObjectStructure() { var sut = new CountVisitor(); var objectStructure = new Element( new Element( new ElementWithLink( new Element(new Element(new ElementWithLink(new Element(null), new Element(null)))), new Element(new Element(new Element(null)))))); sut.CountElements(objectStructure); Assert.That(sut.Count, Is.EqualTo(9), "elements"); }
public static void Run() { // Set up the object structure Element objectStructure = new Element(new Element(new ElementWithLink(new Element(new Element( new ElementWithLink(new Element(null), new Element(null)))), new Element(new Element(new Element(null)))))); Console.WriteLine("Count the Elements"); CountVisitor visitor = new CountVisitor(); visitor.CountElements(objectStructure); Console.WriteLine("Number of Elements is: " + visitor.Count); Console.WriteLine(); Console.WriteLine("******************************************"); Console.WriteLine(); }
public void PropertyVisitor_VisitingAStructWithPrimitiveProperties_DoesNotAllocate() { var container = new StructWithPrimitiveProperties(); var visitor = new CountVisitor(); GCAllocTest.Method(() => { visitor.Count = 0; PropertyContainer.Visit(ref container, visitor); }) .ExpectedCount(0) .Warmup() .Run(); Assert.That(visitor.Count, Is.EqualTo(2)); }
public void Query_Simple_Ok() { var expression = Search.CreateSearchParameter("inStock", "true").And(Search.CreateSearchParameter("id", "1234")); expression.Or(Search.CreateSearchParameter("id", "5678")).Or(Search.CreateSearchParameter("name", "adata")); var qb = new QueryBuilder("", ""); qb.Search(expression); var countVisitor = new CountVisitor(); countVisitor.CountParameters(qb.SearchParameterTree); qb.ToString(); }
public void PropertyVisitor_VisitingAnEmptyClass_DoesNotAllocate() { var container = new EmptyClass(); var visitor = new CountVisitor(); GCAllocTest.Method(() => { visitor.Count = 0; PropertyContainer.Accept(visitor, ref container); }) .ExpectedCount(0) .Warmup() .Run(); Assert.That(visitor.Count, Is.EqualTo(0)); }
public void PropertyVisitor_VisitingAClassWithCollectionProperties_DoesNotAllocate() { var container = new ClassWithCollectionProperties { Float32List = new List <float> { 1, 2, 3 } }; var visitor = new CountVisitor(); GCAllocTest.Method(() => { visitor.Count = 0; PropertyContainer.Visit(ref container, visitor); }) .ExpectedCount(0) .Warmup() .Run(); Assert.That(visitor.Count, Is.EqualTo(4)); }
static void Demo() { // Set up the object structure Element objectStructure = new Element( new Element( new ElementWithLink( new Element( new Element( new ElementWithLink( new Element(null), new Element( null)))), new Element( new Element( new Element(null)))))); Console.WriteLine("Count the Elements"); CountVisitor visitor = new CountVisitor(); visitor.CountElements(objectStructure); Console.WriteLine("Number of Elements is: " + visitor.Count); }
static void Main(string[] args) { PascalABCNewLanguageParser parser = new PascalABCNewLanguageParser(); string root = @"C:\PABCWork.NET\Samples"; //args[0]; var files = GetFiles(root); var visitor = new CountVisitor(); foreach (var x in files) { dynamic res = parser.BuildTree("ProgramFile", x, ParseMode.Normal); var executer = new ExecuteVisitor(visitor); if (res != null) { executer.visit(res); } } List <KeyValuePair <string, int> > myList = visitor.nodeCount.ToList(); myList.Sort((firstPair, nextPair) => { return(nextPair.Value.CompareTo(firstPair.Value)); } ); StreamWriter resFile = new StreamWriter("NodesCount.txt"); foreach (KeyValuePair <string, int> x in myList) { if (x.Value > 0) { resFile.WriteLine(x.Key + " - " + x.Value); } } resFile.Close(); //Console.ReadKey(); }