Skip to content

Commit

Permalink
Merge pull request #82 from tfreitasleal/master
Browse files Browse the repository at this point in the history
Improve criteria classes inheriting from BusinessBase (#58)
  • Loading branch information
tfreitasleal committed Mar 26, 2018
2 parents a1c6881 + 12b7e97 commit 82d1f67
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 65 deletions.
25 changes: 17 additions & 8 deletions trunk/Solutions/CslaGenFork/CodeGen/CslaTemplateHelperCS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2483,12 +2483,16 @@ public virtual string GetInitValue(CslaObjectInfo info, ValueProperty prop, Type

public static string GetDataTypeGeneric(Property prop, TypeCodeEx field)
{
if (field == TypeCodeEx.CustomType && prop is ValueProperty)
return ((ValueProperty) prop).CustomPropertyType;

var type = GetDataType(field);
if (AllowNull(prop) && prop.PropertyType != TypeCodeEx.CustomType)
{
if (field.IsNullableType())
type += "?";
}

return type;
}

Expand Down Expand Up @@ -2550,9 +2554,9 @@ public string PropertyInfoDeclare(CslaObjectInfo info, ValueProperty prop)
var noSilverlightStatement = string.Empty;
var silverlightStatement = string.Empty;
if (UseNoSilverlight())
noSilverlightStatement = PropertyInfoDeclare(info, prop, false);
noSilverlightStatement = PropertyInfoDeclareCore(info, prop);
if (UseSilverlight())
silverlightStatement = PropertyInfoDeclare(info, prop, true);
silverlightStatement = PropertyInfoDeclareCore(info, prop);
if (UseBoth() && noSilverlightStatement != silverlightStatement)
{
response += "#if SILVERLIGHT" + Environment.NewLine;
Expand All @@ -2577,7 +2581,7 @@ public string PropertyInfoDeclare(CslaObjectInfo info, ValueProperty prop)
return response;
}

private string PropertyInfoDeclare(CslaObjectInfo info, ValueProperty prop, bool isSilverlight)
private string PropertyInfoDeclareCore(CslaObjectInfo info, ValueProperty prop)
{
// "private static readonly PropertyInfo<{0}> {1} = RegisterProperty<{0}>(p => p.{2}, \"{3}\"{4});",
var response = string.Empty;
Expand Down Expand Up @@ -2673,9 +2677,9 @@ public string PropertyInfoChildDeclare(CslaObjectInfo info, ChildProperty prop)
var noSilverlightStatement = string.Empty;
var silverlightStatement = string.Empty;
if (UseNoSilverlight())
noSilverlightStatement = PropertyInfoChildDeclare(info, prop, false);
noSilverlightStatement = PropertyInfoChildDeclareCore(info, prop);
if (UseSilverlight())
silverlightStatement = PropertyInfoChildDeclare(info, prop, true);
silverlightStatement = PropertyInfoChildDeclareCore(info, prop);
if (UseBoth() && noSilverlightStatement != silverlightStatement)
{
response += "#if SILVERLIGHT" + Environment.NewLine;
Expand All @@ -2700,7 +2704,7 @@ public string PropertyInfoChildDeclare(CslaObjectInfo info, ChildProperty prop)
return response;
}

private string PropertyInfoChildDeclare(CslaObjectInfo info, ChildProperty prop, bool isSilverlight)
private string PropertyInfoChildDeclareCore(CslaObjectInfo info, ChildProperty prop)
{
// "private static readonly PropertyInfo<{0}> {1} = RegisterProperty<{0}>(p => p.{2}, \"{3}\"{4});",
var response = string.Empty;
Expand Down Expand Up @@ -5346,14 +5350,19 @@ public bool IsCriteriaNestedClassNeeded(CslaObjectInfo info)
public bool IsCriteriaObjectNeeded(CslaObjectInfo info)
{
return (from crit in info.CriteriaObjects
where crit.Properties.Count > 1 && !crit.NestedClass
where crit.Properties.Count > 1 &&
!crit.NestedClass &&
crit.CriteriaClassMode != CriteriaMode.BusinessBase &&
crit.CriteriaClassMode != CriteriaMode.CustomCriteriaClass
select FactoryOrDataPortal(crit)).FirstOrDefault();
}

public bool IsCriteriaExtendedClassNeeded(CslaObjectInfo info)
{
return (from crit in info.CriteriaObjects
where crit.Properties.Count > 1 && crit.CriteriaClassMode == CriteriaMode.BusinessBase
where crit.Properties.Count > 1 &&
crit.CriteriaClassMode != CriteriaMode.BusinessBase &&
crit.CriteriaClassMode != CriteriaMode.CustomCriteriaClass
select FactoryOrDataPortal(crit)).FirstOrDefault();
}

Expand Down
25 changes: 17 additions & 8 deletions trunk/Solutions/CslaGenFork/CodeGen/CslaTemplateHelperVB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2489,12 +2489,16 @@ public virtual string GetInitValue(CslaObjectInfo info, ValueProperty prop, Type

public static string GetDataTypeGeneric(Property prop, TypeCodeEx field)
{
if (field == TypeCodeEx.CustomType && prop is ValueProperty)
return ((ValueProperty) prop).CustomPropertyType;

var type = GetDataType(field);
if (AllowNull(prop) && prop.PropertyType != TypeCodeEx.CustomType)
{
if (field.IsNullableType())
type += "?";
}

return type;
}

Expand Down Expand Up @@ -2556,9 +2560,9 @@ public string PropertyInfoDeclare(CslaObjectInfo info, ValueProperty prop)
var noSilverlightStatement = string.Empty;
var silverlightStatement = string.Empty;
if (UseNoSilverlight())
noSilverlightStatement = PropertyInfoDeclare(info, prop, false);
noSilverlightStatement = PropertyInfoDeclareCore(info, prop);
if (UseSilverlight())
silverlightStatement = PropertyInfoDeclare(info, prop, true);
silverlightStatement = PropertyInfoDeclareCore(info, prop);
if (UseBoth() && noSilverlightStatement != silverlightStatement)
{
response += "#If SILVERLIGHT Then" + Environment.NewLine;
Expand All @@ -2583,7 +2587,7 @@ public string PropertyInfoDeclare(CslaObjectInfo info, ValueProperty prop)
return response;
}

private string PropertyInfoDeclare(CslaObjectInfo info, ValueProperty prop, bool isSilverlight)
private string PropertyInfoDeclareCore(CslaObjectInfo info, ValueProperty prop)
{
// "Private Shared ReadOnly {1} As PropertyInfo(Of {0}) = RegisterProperty(Of {0})(Function(p) p.{2}, \"{3}\"{4})",
var response = string.Empty;
Expand Down Expand Up @@ -2688,9 +2692,9 @@ public string PropertyInfoChildDeclare(CslaObjectInfo info, ChildProperty prop)
var noSilverlightStatement = string.Empty;
var silverlightStatement = string.Empty;
if (UseNoSilverlight())
noSilverlightStatement = PropertyInfoChildDeclare(info, prop, false);
noSilverlightStatement = PropertyInfoChildDeclareCore(info, prop);
if (UseSilverlight())
silverlightStatement = PropertyInfoChildDeclare(info, prop, true);
silverlightStatement = PropertyInfoChildDeclareCore(info, prop);
if (UseBoth() && noSilverlightStatement != silverlightStatement)
{
response += "#If SILVERLIGHT Then" + Environment.NewLine;
Expand All @@ -2715,7 +2719,7 @@ public string PropertyInfoChildDeclare(CslaObjectInfo info, ChildProperty prop)
return response;
}

private string PropertyInfoChildDeclare(CslaObjectInfo info, ChildProperty prop, bool isSilverlight)
private string PropertyInfoChildDeclareCore(CslaObjectInfo info, ChildProperty prop)
{
// "Private Shared ReadOnly {1} As PropertyInfo(Of {0}) = RegisterProperty(Of {0})(Function(p) p.{2}, \"{3}\"{4})",
var response = string.Empty;
Expand Down Expand Up @@ -5362,14 +5366,19 @@ public bool IsCriteriaNestedClassNeeded(CslaObjectInfo info)
public bool IsCriteriaObjectNeeded(CslaObjectInfo info)
{
return (from crit in info.CriteriaObjects
where crit.Properties.Count > 1 && !crit.NestedClass
where crit.Properties.Count > 1 &&
!crit.NestedClass &&
crit.CriteriaClassMode != CriteriaMode.BusinessBase &&
crit.CriteriaClassMode != CriteriaMode.CustomCriteriaClass
select FactoryOrDataPortal(crit)).FirstOrDefault();
}

public bool IsCriteriaExtendedClassNeeded(CslaObjectInfo info)
{
return (from crit in info.CriteriaObjects
where crit.Properties.Count > 1 && crit.CriteriaClassMode == CriteriaMode.BusinessBase
where crit.Properties.Count > 1 &&
crit.CriteriaClassMode != CriteriaMode.BusinessBase &&
crit.CriteriaClassMode != CriteriaMode.CustomCriteriaClass
select FactoryOrDataPortal(crit)).FirstOrDefault();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value,
Type destinationType)
{
if (value == null)
return string.Empty;

var valueType = value.GetType();
if (valueType == typeof(string) && string.IsNullOrWhiteSpace((string) value))
return string.Empty;

var fi = _enumType.GetField(Enum.GetName(_enumType, value));
var dna = (DescriptionAttribute) Attribute.GetCustomAttribute(fi, typeof(DescriptionAttribute));

Expand Down
20 changes: 14 additions & 6 deletions trunk/Solutions/CslaGenFork/Metadata/CslaObjectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,6 @@ public bool IsGenericType
{
get
{
if (ObjectType.IsCriteriaClass())
_isGenericType = true;

if (ObjectType.IsBaseClass() && CslaBaseClass != CslaBaseClasses.None)
_isGenericType = true;

Expand All @@ -409,9 +406,6 @@ public string GenericArguments
{
get
{
if (ObjectType.IsCriteriaClass())
_genericArguments = "T";

if (ObjectType.IsBaseClass() && CslaBaseClass != CslaBaseClasses.None)
_genericArguments = CslaBaseClass.GetGenericArguments();

Expand Down Expand Up @@ -1511,6 +1505,20 @@ public string GenericName
}
}

[Browsable(false)]
[XmlIgnore]
public string GenericNameXml
{
get
{
var arguments = _genericArguments != string.Empty ? _genericArguments : "?";
var result = _objectName + (_isGenericType ? string.Format("<{0}>", arguments) : string.Empty);
result = result.Replace("<", "{");
result = result.Replace(">", "}");
return result;
}
}

[Browsable(false)]
[XmlIgnore]
public AuthorizationActions ActionProperty { get; set; }
Expand Down
3 changes: 1 addition & 2 deletions trunk/Solutions/CslaGenFork/Util/PropertyBags/PropertyBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,7 @@ private void InitPropertyBag()
propertyInfo.Name == "Generate")
isreadonly = true;

if ((SelectedObject[0].IsCriteriaClass() ||
SelectedObject[0].IsBaseClass() && SelectedObject[0].CslaBaseClass != CslaBaseClasses.None) &&
if ((SelectedObject[0].IsBaseClass() && SelectedObject[0].CslaBaseClass != CslaBaseClasses.None) &&
(propertyInfo.Name == "IsGenericType" ||
propertyInfo.Name == "GenericArguments"))
isreadonly = true;
Expand Down
41 changes: 3 additions & 38 deletions trunk/Templates/CSLA40/CSharp/BaseClass.cst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<%@ CodeTemplate Inherits="CslaTemplateHelperCS" Language="CSharp" TargetLanguage="CSharp" Description="Generates a CSLA Editable Root Object." %>
<%@ Property Name="Info" Type="CslaObjectInfo" Optional="false" Category="Business Object" Description="Definition of the EditableRoot Object to create." %>
<%@ Property Name="Errors" Type="System.Text.StringBuilder" Optional="false" Category="Options" Description="Allows the template to return errors to master.cst" %>
Expand Down Expand Up @@ -55,43 +56,7 @@ namespace <%= GetContextObjectNamespace(Info, CurrentUnit, GenerationStep.Busine
}
%>
[Serializable]
<%
String[] clauses = GetGenericWhereClause(Info);
if (Info.InheritedType.FinalName != string.Empty)
{
%><%= GetBaseClassDeclarationInheritedType(Info) + GetInterfaceDeclaration(Info) %>
<%
if (clauses.Length > 0)
{
%>
<%= clauses[0] %>
<%
}
if (clauses.Length > 1)
{
%>
<%= clauses[1] %>
<%
}
}
else
{
%><%= GetBaseClassDeclaration(Info) + GetInterfaceDeclaration(Info) %>
<%
if (clauses.Length > 0)
{
%>
<%= clauses[0] %>
<%
}
if (clauses.Length > 1)
{
%>
<%= clauses[1] %>
<%
}
}
%>
<!-- #include file="BaseClassDeclaration.asp" -->
{
<%
if (CslaBaseClassesExtensions.IsNotListBaseClass(Info.CslaBaseClass))
Expand All @@ -111,7 +76,7 @@ namespace <%= GetContextObjectNamespace(Info, CurrentUnit, GenerationStep.Busine
<!-- #include file="ObjectAuthorizationMethods.asp" -->
<!-- #include file="BusinessRules.asp" -->
<%
Response.Write(Environment.NewLine);
//Response.Write(Environment.NewLine);
%>
}
}
Expand Down
38 changes: 38 additions & 0 deletions trunk/Templates/CSLA40/CSharp/BaseClassDeclaration.asp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

<%
String[] clauses = GetGenericWhereClause(Info);
if (Info.InheritedType.FinalName != string.Empty)
{
%><%= GetBaseClassDeclarationInheritedType(Info) %>
<%
if (clauses.Length > 0)
{
%>
<%= clauses[0] %>
<%
}
if (clauses.Length > 1)
{
%>
<%= clauses[1] %>
<%
}
}
else
{
%><%= GetBaseClassDeclaration(Info) %>
<%
if (clauses.Length > 0)
{
%>
<%= clauses[0] %>
<%
}
if (clauses.Length > 1)
{
%>
<%= clauses[1] %>
<%
}
}
%>
3 changes: 2 additions & 1 deletion trunk/Templates/CSLA40/CSharp/Constructor.asp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<%
if (Info.GenerateConstructor)
{
Expand All @@ -24,7 +25,7 @@ if (Info.GenerateConstructor)
#region Constructor

/// <summary>
/// Initializes a new instance of the <see cref="<%= Info.ObjectName %>"/> class.
/// Initializes a new instance of the <see cref="<%= Info.GenericNameXml %>"/> class.
/// </summary>
/// <remarks> Do not use to create a <%= Info.IsUnitOfWork() ? "Unit of Work" : "Csla object" %>. Use factory methods instead.</remarks>
<%
Expand Down
1 change: 1 addition & 0 deletions trunk/Templates/CSLA40/CSharp/Criteria.asp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<%
if (Info.CriteriaObjects.Count > 0)
{
Expand Down
1 change: 1 addition & 0 deletions trunk/Templates/CSLA40/CSharp/CriteriaObject.asp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<%
if (Info.CriteriaObjects.Count > 0)
{
Expand Down
13 changes: 13 additions & 0 deletions trunk/Templates/CSLA40/CSharp/ExtendedFile.cst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<%@ CodeTemplate Inherits="CslaTemplateHelperCS" Language="CSharp" TargetLanguage="CSharp" Description="Generates a CSLA Inherited Object." %>
<%@ Property Name="Info" Type="CslaObjectInfo" Optional="false" Category="Business Object" Description="Definition of the CSLA Object to inherit from." %>
<%@ Property Name="Errors" Type="System.Text.StringBuilder" Optional="false" Category="Options" Description="Allows the template to return errors to master.cst" %>
Expand Down Expand Up @@ -71,7 +72,19 @@ if (cachedContextUtilitiesNamespace != string.Empty)

namespace <%= Info.ObjectNamespace %>
{
<%
if (Info.ObjectType == CslaObjectType.BaseClass)
{
%>
<!-- #include file="BaseClassDeclaration.asp" --><%
}
else
{
%>
<%= Info.ClassVisibility == ClassVisibility.Public ? "public" : "internal" %> partial class <%= Info.ObjectName %>
<%
}
%>
{

#region OnDeserialized actions
Expand Down
9 changes: 8 additions & 1 deletion trunk/Templates/CSLA40/CSharp/XmlComment.asp
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@

<%
string classType = "business object";
if (Info.ObjectType == CslaObjectType.BaseClass)
classType = "base classe";
else if (Info.ObjectType == CslaObjectType.CriteriaClass)
classType = "criteria classe";
if ((firstComment == null && string.IsNullOrEmpty(Info.Parent.GenerationParams.ClassCommentFilenameSuffix)) ||
(firstComment == true && !string.IsNullOrEmpty(Info.Parent.GenerationParams.ClassCommentFilenameSuffix)))
{
firstComment = true;
%>
/// <summary>
/// <%= string.IsNullOrEmpty(Info.ClassSummary) ? Info.ObjectName : Info.ClassSummary %> (<%= CslaStereotype(Info) %>).<br/>
/// This is a generated base class of <see cref="<%= Info.ObjectName %>"/> business object.
/// This is a generated <see cref="<%= Info.GenericNameXml %>"/> <%= classType %>.
<%
if (string.IsNullOrEmpty(Info.ParentType))
{
Expand Down
Loading

0 comments on commit 82d1f67

Please sign in to comment.