New Posts New Posts RSS Feed: Forcing full-qualified types in DomainModelTemplate
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Forcing full-qualified types in DomainModelTemplate

 Post Reply Post Reply
Author
leeatkinson View Drop Down
Newbie
Newbie


Joined: 01-Jul-2010
Posts: 17
Post Options Post Options   Quote leeatkinson Quote  Post ReplyReply Direct Link To This Post Topic: Forcing full-qualified types in DomainModelTemplate
    Posted: 05-Jul-2010 at 8:30am
Hi

Is it possible to force DomainModelTemplate to use fully-qualified type names (e.g. 'System.String' vs 'String')?

For now, I've extended it as below, but it would be nice if the template itself had this ability. This is to avoid clashes with types already existing in one's model.

Thanks

Lee

public class MyDomainModelTemplate : DomainModelTemplate
     {
          public MyDomainModelTemplate(TextTransformation textTransformation)
               : base(textTransformation)
          {
          }
          override protected void WriteEntityManagerCtors(CsdlWrapper csdl) {
            if (!csdl.IsPrimaryEdmx) return;
      
            WriteRegion("Constructors", () => {
               var className = csdl.EntityManagerName;
               var baseClassName = "IbEm.EntityManager";
               WriteCtor(AccessType.Public, className, baseClassName, new String[] { }, new String[] { });
               WriteCtor(AccessType.Public, className, baseClassName, new[] { "System.Boolean" }, new[] { "shouldConnect" });
               WriteCtor(AccessType.Public, className, baseClassName, new[] { "System.Boolean", "System.String" }, new[] { "shouldConnect", "dataSourceExtension" });
               WriteCtor(AccessType.Public, className, baseClassName, new[] { "System.Boolean", "System.String", "IbEm.EntityServiceOption" }, new[] { "shouldConnect", "dataSourceExtension", "entityServiceOption" });
               WriteCtor(AccessType.Public, className, baseClassName, new[] { "IbEm.EntityManager" }, new[] { "entityManager" });
               WriteCtor(AccessType.Public, className, baseClassName, new[] { "IbEm.EntityManager", "System.Boolean", "System.String", "IbEm.EntityServiceOption" }, new[] { "entityManager", "shouldConnect", "dataSourceExtension", "entityServiceOption" });
               WriteEntityManagerStaticCtor(csdl);
            });
          }
          override protected void WriteEntityPathForMethod(EntityOrComplexTypeWrapper entityOrComplexType)
          {
               WriteSummary("Returns the property path for the given expression.");

               WriteXComment("<example>");
               WriteXComment("Usage:");
               WriteXComment("<code>");
               WriteXComment("   var r = Employee.PathFor(e => e.Manager.City); // returns \"Manager.City\"");
               WriteXComment("</code>");
               WriteXComment("</example>");
               var funcTypeName = FmtGenericTypeName("Func", entityOrComplexType.Name, "System.Object");
               var exprTypeName = FmtGenericTypeName("Expression", funcTypeName);
               var methDef = new MethodDef("PathFor", "System.String", AccessType.Public,
                new[] { exprTypeName }, new[] { "expr" });
               methDef.SetStatic(true);
               var entityType = entityOrComplexType as EntityTypeWrapper;
               if (entityType != null)
               {
                    methDef.SetOverload(entityType.IsDerived);
               }
               WriteCodeDef(methDef, () => WriteEntityPathForMethodCore(entityOrComplexType));
          }
          override protected void WriteEntityPropertyNamesInnerClassCore(String propertyName) {
            var fmt = (this.CodeGenLanguage.IsCSharp)
               ? "public const System.String {0} = \"{0}\";"
               : "Public Const {0} As System.String = \"{0}\"";
            WriteLine(String.Format(fmt, FmtName(propertyName)));
          }

          private String FmtName(String name) {
            return NamingService.FmtName(name);
          }

Edited by leeatkinson - 05-Jul-2010 at 8:30am
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 06-Jul-2010 at 8:35pm
In the .tt file, you can add one line of code that will fully qualify all system types:
 
...
var template = new MyTemplate(this);
template.NamingService.FullyQualifySystemTypes = true;  // Add this line
template.Generate();
...
 
Back to Top
leeatkinson View Drop Down
Newbie
Newbie


Joined: 01-Jul-2010
Posts: 17
Post Options Post Options   Quote leeatkinson Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jul-2010 at 1:26am
Many thanks.

However, it only seems to fully-qualify some of the system types - for example, the property types of entities.

Some aren't - for example, PathFor is still defined:

public static String PathFor(Expression<Func<Entity, Object>> expr) {
      return IbCore.PropertyPath.For<Entity>(expr);
    }


Lee

Edited by leeatkinson - 07-Jul-2010 at 1:39am
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 07-Jul-2010 at 7:37pm

;)  Ok.  We'll get that fixed.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down