Esempio n. 1
0
        private void BuildListTree <T>(params T[] arrayElements)
        {
            var instance = new ClassWithMembers <List <T> >(arrayElements.ToList(), arrayElements.ToList());
            var treeItem = new ObjectTreeItem(instance);

            treeItem.CreateTree();

            Trace.WriteLine(treeItem.ToFormattedString());
        }
Esempio n. 2
0
        public void TreeCanHandleGuid()
        {
            var instance = new ClassWithMembers <Guid>(new Guid(), new Guid());

            var treeItem = new ObjectTreeItem(instance);

            treeItem.CreateTree();

            Trace.WriteLine(treeItem.ToFormattedString());
        }
Esempio n. 3
0
        public void TreeCanHandleIpAddress()
        {
            var instance = new ClassWithMembers <IPAddress>(new IPAddress(19216811), new IPAddress(19216811));

            var treeItem = new ObjectTreeItem(instance);

            treeItem.CreateTree();

            Trace.WriteLine(treeItem.ToFormattedString());
        }
Esempio n. 4
0
        private void TestObjectTreeCreation <T>(T property, T field)
        {
            var instance = new ClassWithMembers <T>(field, property);

            var treeItem = new ObjectTreeItem(instance);

            treeItem.CreateTree();

            Trace.WriteLine(treeItem.ToFormattedString());
        }
Esempio n. 5
0
        public void TreeCanHandleEnumberable()
        {
            var action = new Func <IEnumerable <string> >(CreateString);

            var instance = new ClassWithMembers <IEnumerable <string> >(action.Invoke(), new List <string>());

            var treeItem = new ObjectTreeItem(instance);

            treeItem.CreateTree();

            Trace.WriteLine(treeItem.ToFormattedString());
        }
Esempio n. 6
0
        public void TreeCanHandleDelegates()
        {
            Del del = delegate(string name)
            { Console.WriteLine("Notification received for: {0}", name); };
            var instance = new ClassWithMembers <Delegate>(del);

            var treeItem = new ObjectTreeItem(instance);

            treeItem.CreateTree();

            Trace.WriteLine(treeItem.ToFormattedString());
        }
Esempio n. 7
0
        public void TreeCanHandleOwnGenericList()
        {
            var instance = new ClassWithMembers <OwnGenericListClass <string> >(new OwnGenericListClass <string>()
            {
                "test1", "test2"
            }, new OwnGenericListClass <string>());

            var treeItem = new ObjectTreeItem(instance);

            treeItem.CreateTree();

            Trace.WriteLine(treeItem.ToFormattedString());
        }
        IRecordObject IRecordTypeHandler.Handle(IAnalyze analyze)
        {
            if (analyze.LastRecordType == RecordTypeEnumeration.ClassWithId)
            {
                return(null);
            }

            var record = new ClassWithMembers();

            record.ClassInfo = new ClassInfo(analyze);
            record.LibraryId = analyze.Reader.ReadInt32();

            return(record);
        }
Esempio n. 9
0
        public void TreeCanHandleFunctions()
        {
            var instance1 = new ClassWithMembers <Func <string, int> >(s => 5);
            var instance2 = new ClassWithMembers <Func <string> >(() => "test", () => "test");
            var instance3 = new ClassWithMembers <Func <string> >(() => "test", () => "test");

            var treeItem1 = new ObjectTreeItem(instance1);
            var treeItem2 = new ObjectTreeItem(instance2);
            var treeItem3 = new ObjectTreeItem(instance3);

            treeItem1.CreateTree();
            treeItem2.CreateTree();
            treeItem3.CreateTree();

            Trace.WriteLine(treeItem1.ToFormattedString());
            Trace.WriteLine(treeItem2.ToFormattedString());
            Trace.WriteLine(treeItem3.ToFormattedString());
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            // naming conventions
            // https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/general-naming-conventions?redirectedfrom=MSDN
            // https://github.com/ktaranov/naming-convention/blob/master/C%23%20Coding%20Standards%20and%20Naming%20Conventions.md

            Console.WriteLine("Hello World!");

            // different types of string concatenation & interpolation
            string someStringValue      = "some value";
            string anotherStringValue   = "another value";
            string differentStringValue = "different value";

            string doNotConcatStringLikeThis = "Use this to format " + someStringValue + " with " + anotherStringValue + " and " + differentStringValue;
            string concatString      = string.Concat(someStringValue, anotherStringValue, differentStringValue);
            string formatString      = string.Format("Use this to format {0} with {1} and {2}", someStringValue, anotherStringValue, differentStringValue);
            string interpolateString = $"Use this to format {someStringValue} with {anotherStringValue} and {differentStringValue}";

            Console.WriteLine("-----");

            // class members
            Console.WriteLine(ClassWithMembers.StaticString);
            ClassWithMembers classWithMembers = new ClassWithMembers();

            classWithMembers.ChangeSomeValues(10);
            classWithMembers.WriteSomething();

            Console.WriteLine("-----");

            // Inheritance & Basic Polymorphism
            BaseClass    bc   = new BaseClass();
            DerivedClass dc   = new DerivedClass();
            BaseClass    bcdc = new DerivedClass();

            bc.Method1();
            bc.Method2();

            dc.Method1();
            dc.Method2();

            // runtime polymorphism
            // calls method1 of derived class because of virtual/override
            bcdc.Method1();
            // calls method2 of base class, because of new keyword (method hiding)
            bcdc.Method2();
            // calls overloaded method2 of derived class because of casting
            ((DerivedClass)bcdc).Method2("sdf");

            Console.WriteLine("-----");

            // Polymorphism with abstract base class
            AbstractShape abstractLine = new DerivedLine(0, 1, 1, 1);

            abstractLine.ShowOrigin();
            double abstractLinePerimeter = abstractLine.GetPerimeter();

            AbstractShape abstractCircle = new DerivedCircle(5, 5, 3);

            abstractCircle.ShowOrigin();
            double abstractCircleArea = abstractCircle.GetArea();

            DerivedCompoundShape derivedCompound = new DerivedCompoundShape(7, 7);

            derivedCompound.Add(abstractLine);
            derivedCompound.Add(abstractCircle);
            derivedCompound.Add(new DerivedLine(3, 4, 5, 6));
            derivedCompound.ShowOrigin();
            derivedCompound.PrintShapeType();

            // casting works in IDE, but will throw an error at runtime if "line" is smth else than a Line obje
            //AbstractShape shape = new DerivedCircle(0, 0, 1);
            //DerivedLine line3 = (DerivedLine)shape;

            Console.WriteLine("-----");

            // Polymorphism with interfaces
            IBetterShapeComposition betterLine = new BetterLine(0, 1, 1, 1);

            betterLine.ShowOrigin();
            double betterLinePerimeter = betterLine.GetPerimeter();

            IBetterShapeComposition betterCircle = new BetterCircle(5, 5, 3);
            double betterCircleArea = betterCircle.GetArea();

            betterCircle.ShowOrigin();

            BetterCompoundShape betterCompound = new BetterCompoundShape(7, 7);

            betterCompound.Add(betterLine);
            betterCompound.Add(betterCircle);
            betterCompound.Add(new BetterLine(3, 4, 5, 6));
            betterCompound.ShowOrigin();
            betterCompound.PrintShapeType();

            Console.WriteLine("-----");

            // Very good solution for this usecase - Polymorphism with interfaces and a base class
            Line line = new Line(0, 1, 1, 1);

            line.ShowOrigin();
            double linePerimeter = line.GetPerimeter();

            Circle circle     = new Circle(5, 5, 3);
            double circleArea = betterCircle.GetArea();

            betterCircle.ShowOrigin();

            CompoundShape compoundShape = new CompoundShape(7, 7);

            compoundShape.Add(line);
            compoundShape.Add(circle);
            compoundShape.Add(new Line(3, 4, 5, 6));
            compoundShape.ShowOrigin();
            compoundShape.PrintShapeType();

            Console.WriteLine("-----");

            IShapeStack shapeStack = new ShapeStack(5);

            shapeStack.Push(line);
            Console.WriteLine($"Is empty? {shapeStack.IsEmpty()}");

            if (!shapeStack.IsEmpty())
            {
                shapeStack.DescribeStack();
            }

            Console.WriteLine("-----");

            IShapeComposition poppedShape = shapeStack.Pop();

            Console.WriteLine("Following shape was popped from stack:");
            poppedShape.PrintShapeType();
            Console.WriteLine($"Is stack empty? {shapeStack.IsEmpty()}");

            Console.WriteLine("-----");
        }