blipson89 / Synthesis

Synthesis is a universal object mapper for Sitecore
MIT License
75 stars 25 forks source link

Sitecore namespace conflicts #98

Closed mattbarry closed 3 years ago

mattbarry commented 3 years ago

Do you want to request a feature or report a bug? Enhancement

What is the current behavior? The generated models reference the Sitecore.ContentSearch and Sitecore.Data namespaces directly. I'm in the unfortunate situation of inheriting a Helix-like project that has chosen a namespace of Org.Sitecore.Feature.Module. So when Synthesis references the Sitecore namespace the compiler thinks it is referring to the project namespace and compilation fails. Much of my codebase aliases the Sitecore namespace to something like SC, but I can't do that with the Synthesis-generated code.

What is the expected behavior?

The desired behaviour might reference global::Sitecore.ContentSearch and global::Sitecore.Data, similar to the way the searchFields constructor in concrete model classes references global::System.Collections.Generic.IDictionary. I would be happy to submit a PR if this sounds like a desirable solution.

Please mention your Sitecore version and Synthesis version. Sitecore 9.3.0 and Synthesis 9.1.2.1

blipson89 commented 3 years ago

Your best bet for this situation would be to use Leprechaun for code generation, if that's an option.

I am planning another Synthesis release next week. If you'd like to submit a PR to add global::, I think it would be in CodeDomGenerator.cs, but it's been a loooooong time since I've touched that code. If you don't want to submit a PR for it, I can also take a peek this weekend.

Leprechaun's code generator is a LOT more flexible and is designed to work with Synthesis out of the box.

mattbarry commented 3 years ago

Awesome. Thanks @blipson89! I had a look at the Synthesis code last night and it does indeed look like I could just update CodeDomGenerator.cs. I'll try to get a PR submitted this week, but I'll look into Leprechaun as well.

I really appreciate your suggestions!

blipson89 commented 3 years ago

Released in 9.1.4 - thank you for the help!