Skip to content

Commit dd4e11f

Browse files
committed
Helper class for base-class definition maintenance
1 parent c7c7dfa commit dd4e11f

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

EntityFramework.Reverse.POCO.Generator/EF.Reverse.POCO.Core.ttinclude

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,4 +3687,76 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
36873687
var spReturnClassName = WriteStoredProcReturnModelName(sp);
36883688
return (returnModelCount == 1) ? string.Format("System.Collections.Generic.List<{0}>", spReturnClassName) : spReturnClassName;
36893689
};
3690+
3691+
/// <summary>
3692+
/// Helper class in making dynamic class definitions easier.
3693+
/// </summary>
3694+
public sealed class BaseClassMaker
3695+
{
3696+
private string _typeName;
3697+
private System.Text.StringBuilder _interfaces;
3698+
3699+
public BaseClassMaker(string baseClassName = null)
3700+
{
3701+
SetBaseClassName(baseClassName);
3702+
}
3703+
3704+
/// <summary>
3705+
/// Sets the base-class name.
3706+
/// </summary>
3707+
public void SetBaseClassName(string typeName)
3708+
{
3709+
_typeName = typeName;
3710+
}
3711+
3712+
/// <summary>
3713+
/// Appends additional implemented interface.
3714+
/// </summary>
3715+
public bool AddInterface(string typeName)
3716+
{
3717+
if (string.IsNullOrEmpty(typeName))
3718+
return false;
3719+
3720+
if (_interfaces == null)
3721+
{
3722+
_interfaces = new System.Text.StringBuilder();
3723+
}
3724+
else
3725+
{
3726+
if (_interfaces.Length > 0)
3727+
{
3728+
_interfaces.Append(", ");
3729+
}
3730+
}
3731+
3732+
_interfaces.Append(typeName);
3733+
return true;
3734+
}
3735+
3736+
/// <summary>
3737+
/// Conditionally appends additional implemented interface.
3738+
/// </summary>
3739+
public bool AddInterface(string interfaceName, bool condition)
3740+
{
3741+
if (condition)
3742+
{
3743+
return AddInterface(interfaceName);
3744+
}
3745+
3746+
return false;
3747+
}
3748+
3749+
public override string ToString()
3750+
{
3751+
var hasInterfaces = _interfaces != null && _interfaces.Length > 0;
3752+
3753+
if (string.IsNullOrEmpty(_typeName))
3754+
{
3755+
return hasInterfaces ? " : " + _interfaces : string.Empty;
3756+
}
3757+
3758+
return hasInterfaces ? string.Concat(" : ", _typeName, ", ", _interfaces) : " : " + _typeName;
3759+
}
3760+
}
3761+
36903762
#>

0 commit comments

Comments
 (0)