Exemple #1
0
        public void Delegates()
        {
            const string code = @"    
            public class Class1 
            {
                public delegate int Delegate1(string param1, Class1 p2);
            }
            ";

            CSharpParser parser = new CSharpParser();

            parser.ParseCode(code);

            ICodeRoot codeRoot = parser.CreatedCodeRoot;
            Class     clazz    = (Class)codeRoot.WalkChildren()[0];

            Delegate con = (Delegate)clazz.WalkChildren()[0];

            Assert.That(con.Name, Is.EqualTo("Delegate1"));
            Assert.That(con.Modifiers, Has.Count(1));
            Assert.That(con.Modifiers[0], Is.EqualTo("public"));
            Assert.That(con.ReturnType.Name, Is.EqualTo("int"));
            Assert.That(con.Parameters, Has.Count(2));
            Assert.That(con.Parameters[0].Name, Is.EqualTo("param1"));
            Assert.That(con.Parameters[0].DataType, Is.EqualTo("string"));
            Assert.That(con.Parameters[1].Name, Is.EqualTo("p2"));
            Assert.That(con.Parameters[1].DataType, Is.EqualTo("Class1"));
        }
Exemple #2
0
        public void Delegate()
        {
            Delegate inter = new Delegate(controller);

            inter.Name = "File";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller, "int");
            Parameter param = new Parameter(controller);

            param.Name     = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            CodeRoot root = CreateClassAndNamespace(inter);

            CodeRootMap map = new CodeRootMap();

            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();

            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "public delegate int File");
        }
        public void Delegate()
        {
            Delegate item = new Delegate(controller, "Delegate1", new DataType(controller, "void"));
            item.Parameters.Add(new Parameter(controller, "int", "i"));
            item.Parameters.Add(new Parameter(controller, "string", "j"));
            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Delegate1 (int, string)"));

            Class cl = new Class(controller, "Class1");
            cl.AddChild(item);

            Assert.That(item.FullyQualifiedDisplayName, Is.EqualTo("Class1.Delegate1 (int, string)"));
        }
        public void A_Delegate_Is_Created()
        {
            const string code = "public delegate int Delegate1();";

            CSharpParser   parser = new CSharpParser();
            IBaseConstruct bc     = parser.ParseSingleConstruct(code, BaseConstructType.DelegateDeclaration);

            Assert.That(bc, Is.Not.Null);
            Assert.That(bc, Is.InstanceOfType(typeof(Delegate)));

            Delegate con = (Delegate)bc;

            Assert.That(con.Name, Is.EqualTo("Delegate1"));
            Assert.That(con.Parameters.Count, Is.EqualTo(0));
            Assert.That(con.ReturnType.Name, Is.EqualTo("int"));
            Assert.That(con.Modifiers.Count, Is.EqualTo(1));
            Assert.That(con.Modifiers[0], Is.EqualTo("public"));
        }
 public VBDelegatePrinter(Delegate obj)
 {
     this.obj = obj;
 }
Exemple #6
0
 public VBDelegatePrinter(Delegate obj)
 {
     this.obj = obj;
 }
        public void Delegate_Changed_ReturnType()
        {
            const string delegateName = "MyEnumerationName1";
            DataType type1 = new DataType(controller, DataType1);
            DataType type2 = new DataType(controller, DataType2);
            string expectedResult = String.Format("{0} delegate {1} {2}", Modifier1, type2, delegateName);

            Delegate merged1 = new Delegate(controller);
            Delegate merged2 = new Delegate(controller);
            Delegate merged3 = new Delegate(controller);

            Delegate changing = new Delegate(controller, delegateName, type2, Modifier1);
            Delegate unchanging = new Delegate(controller, delegateName, type1, Modifier1);

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
        public void Delegate_Changed_GenericType()
        {
            const string delegateName = "MyEnumerationName1";
            const string genericTypeName1 = "MyGenericTypeName1";
            const string genericTypeName2 = "MyGenericTypeName2";
            DataType type1 = new DataType(controller, DataType1);
            string expectedResult = String.Format("{0} delegate {1} {2}<{3}>", Modifier1, type1, delegateName, genericTypeName2);

            Delegate merged1 = new Delegate(controller);
            Delegate merged2 = new Delegate(controller);
            Delegate merged3 = new Delegate(controller);

            Delegate changing = new Delegate(controller, delegateName, type1, Modifier1);
            changing.GenericType = genericTypeName2;
            Delegate unchanging = new Delegate(controller, delegateName, type1, Modifier1);
            unchanging.GenericType = genericTypeName1;

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
        public void Delegate_Added_Modifier()
        {
            const string delegateName = "MyEnumerationName1";
            DataType type1 = new DataType(controller, DataType1);
            string expectedResult = String.Format("{0} {1} delegate {2} {3}", Modifier1, Modifier2, type1, delegateName);

            Delegate merged1 = new Delegate(controller);
            Delegate merged2 = new Delegate(controller);
            Delegate merged3 = new Delegate(controller);

            Delegate changing = new Delegate(controller, delegateName, type1, Modifier1);
            changing.Modifiers.Add(Modifier2);
            Delegate unchanging = new Delegate(controller, delegateName, type1, Modifier1);

            Merge_And_Assert(merged1, merged2, merged3, changing, unchanging, expectedResult);
        }
        public void Delegate()
        {
            Delegate inter = new Delegate(controller);
            inter.Name = "File";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller,"int");
            Parameter param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            Assert.That(inter.IsTheSame(inter.Clone(), ComparisonDepth.Outer), Is.True);
        }
Exemple #11
0
        private void Process_Delegate_Declaration(DelegateDeclaration node)
        {
            if (node == null) throw new ArgumentNullException("node");

            var dele = new Delegate(controller);
            dele.Name = node.Name.Text;
            dele.Modifiers.AddRange(FormatterUtility.GetModifiersFromEnum(node.Modifiers));
            dele.ReturnType = FormatterUtility.GetDataTypeFromTypeReference(node.ReturnType, document, controller);

            foreach (ParameterDeclaration paramNode in node.Parameters)
            {
                Parameter param = GetParameterFromParameterDeclaration(document, controller, paramNode);
                param.ParentObject = dele;
                dele.Parameters.Add(param);
            }

            SetupBaseConstruct(node, dele);
        }
        public void Delegate()
        {
            Delegate inter = new Delegate(controller);
            inter.Name = "File";
            inter.Modifiers.Add("public");
            inter.ReturnType = new DataType(controller,"int");
            Parameter param = new Parameter(controller);
            param.Name = "i";
            param.DataType = "int";
            inter.Parameters.Add(param);

            CodeRoot root = CreateClassAndNamespace(inter);

            CodeRootMap map = new CodeRootMap();
            map.AddCodeRoot(root, Version.User);
            map.AddCodeRoot(root, Version.NewGen);
            map.AddCodeRoot(root, Version.PrevGen);

            string result = map.GetMergedCodeRoot().ToString();
            Assert.That(result, Is.EqualTo(root.ToString()));
            Assertions.StringContains(result, "class Class1");
            Assertions.StringContains(result, "[Serializable(true)]");
            Assertions.StringContains(result, "namespace ArchAngel.Tests");
            Assertions.StringContains(result, "public delegate int File");
        }