Esempio n. 1
0
        public void Issue_88_generated_class_results_in_uncompilable_code()
        {
            var csharpCode = @"using RoslynDom.Common;
namespace Company.Core
   {
      public class className
      {
      }
   }";

            IRoot root       = RDom.CSharp.Load(csharpCode);
            var   firstClass = root.RootClasses.First();

            firstClass.Name = "Product";

            var backerField = new RDomField(name: "mRevisions", returnTypeName: "StringField");

            firstClass.AddOrMoveMember(backerField);
            var property = new RDomProperty(name: "Revisions", propertyTypeName: "string", declaredAccessModifier: AccessModifier.Public, isVirtual: true);

            firstClass.AddOrMoveMember(property);

            var formatted = RDom.CSharp.GetFormattedSourceCode(root);
            var expected  = "using RoslynDom.Common;\r\nnamespace Company.Core\r\n{\r\n    public class Product\r\n    {\r\n        private StringField mRevisions;\r\n        public virtual string Revisions { private get; private set; }\r\n    }\r\n}";

            Assert.AreEqual(expected, formatted);
        }
        public void Issue_88_generated_class_results_in_uncompilable_code()
        {
            var csharpCode = @"using RoslynDom.Common;
            namespace Company.Core
               {
              public class className
              {
              }
               }";

             IRoot root = RDom.CSharp.Load(csharpCode);
             var firstClass = root.RootClasses.First();
             firstClass.Name = "Product";

             var backerField = new RDomField(name: "mRevisions", returnTypeName: "StringField");
             firstClass.AddOrMoveMember(backerField);
             var property = new RDomProperty(name: "Revisions", propertyTypeName: "string", declaredAccessModifier: AccessModifier.Public, isVirtual: true);
             firstClass.AddOrMoveMember(property);

             var formatted = RDom.CSharp.GetFormattedSourceCode(root);
             var expected = "using RoslynDom.Common;\r\nnamespace Company.Core\r\n{\r\n    public class Product\r\n    {\r\n        private StringField mRevisions;\r\n        public virtual string Revisions { private get; private set; }\r\n    }\r\n}";
             Assert.AreEqual(expected, formatted);
        }