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
|