Giter Club home page Giter Club logo

Comments (8)

KathleenDollard avatar KathleenDollard commented on July 17, 2024

Thank you for your feedback

Unfortunately you caught me just before I travel for four days, so it will probably be this weekend before I can address this. My apologies.

Namespace nesting is a challenge - I believe I have an open issue on this and do plan to solve it.

Whitespace is another challenge for me, but this is a bug and I'll record it as such.

I will check on the missing Get/Set and public keyword. Obviously bugs, not sure what happened here.

I plan another attack (rewrite) on the whitespace issue. At present, I see reformatting with the VS rules as the best alternative for new code, but ideally it would preserve existing code.

Thank you again for your feedback, and let me know after I update for these changes whether you see anything else. As well, I'll add your code as a unit test to ensure problems don't recur.

Kathleen

from roslyndom.

KathleenDollard avatar KathleenDollard commented on July 17, 2024

(2) No space between type and field name

When items are created by constructors other than those designed for factories, the NeedsFormatting value is not set to true.

Other whitespace issues remain and a more complex solution and/or a way to explicitly set formatting in a simple way, and if that is done, doing this at output via NeedsFormatting may become a problem.

from roslyndom.

KathleenDollard avatar KathleenDollard commented on July 17, 2024

(4) No public keyword

The constructor was setting the AccessModifier instead of the DeclaredAccessModifier. The DeclaredAccessModifier properties now also set the AccessModifier

Note, I changed the parameter name to declaredAccessModifier, which is a breaking change. I did think about the pain of this change, but decided it should not be misleading which value is being set.

from roslyndom.

KathleenDollard avatar KathleenDollard commented on July 17, 2024

(3) No get/set block on property

A property created without specifying any accessors will be a read/write auto-property.

There were actually several issues changed behind this

  • CanGet/CanSet properties are calculated based on the presence of a Set or Get Accessor
  • CanGet/CanSet parameters on properties changed to IsReadOnly/IsWriteOnly because they do not parallel the CanGet/CanSet properties. These are used in determining whether to build the setter/getter
  • A bug in AccessorType usage in Accessors was fixed
  • A bug in statement usage in Accessors was fixed
  • A new overload doesn't require a name - names are only meaningful for some event accessors

from roslyndom.

KathleenDollard avatar KathleenDollard commented on July 17, 2024

(5) Missing ";" after property (although it wouldn't be needed if there were a get/set block

This is automatically fixed by fixing 3

from roslyndom.

KathleenDollard avatar KathleenDollard commented on July 17, 2024

*** Can you explain what goal you wanted here ****

Specifically, the fix I made ignores your field. Do you want a property constructor that takes a field and uses it as the backing field? How would this work with your "StringField"? Do you have an implicit conversion?

from roslyndom.

KathleenDollard avatar KathleenDollard commented on July 17, 2024

(6) The formatting is a bit rough

Yes, it is rough. Formatting/whitespace is the bane of my existence.

You're correct that you need an easy answer, so I'm adding a new method called GetFormattedSourceCode which you would use like this:

         var formatted = RDom.CSharp.GetFormattedSourceCode(root);

which results in

using RoslynDom.Common;
namespace Company
{
    namespace Core
    {
        public class Product
        {
            private StringField mRevisions;
            public virtual string Revisions { private get; private set; }
        }
    }
}

from roslyndom.

KathleenDollard avatar KathleenDollard commented on July 17, 2024

(1) Nested namespaces, while OK, were unexpected

Internally, namespaces are held as single parts - this is because there is no difference between the following:

namespace A.B {}
namespace A { namespace B{} }

However, we humans like what we like, so the namespaces in input code will be preserved via a "GroupGuid" (the same approach will later be taken for other grouping locations, see issue #53 ). If adding new namespaces, the GroupGuid can also be used for combining.

The final test for all these issues is:

     [TestMethod]
      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);
      }

and the final output:

using RoslynDom.Common;
namespace Company.Core
{
    public class Product
    {
        private StringField mRevisions;
        public virtual string Revisions { private get; private set; }
    }
}

Thank you again for your input!!!!

from roslyndom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.