I am using entity framework to generate a ‘CClass’ entity as below:
public partial class CClass: EntityObject
{
#region Factory Method
#region Primitive Properties
}
My rest of the partial class implementation is
public partial class CClass : IDemoralize
{
public Value xValue { get; set; }
public void IDemoralize.Demoralize()
{
// implementation
}
public void IDemoralize.Demoralize(Func<IDemoralize, bool> CustomDemoralization)
{
bool success = CustomDemoralization(this);
if (!success)
throw new ApplicationException();
}
public void IDemoralize.WriteModel()
{
// implementation
}
public void IDemoralize.WriteModel(Func<IDemoralize, bool> Write)
{
bool success = Write(this);
if (!success)
throw new ApplicationException();
}
}
Now since two methods listed below here does have common implementation across the whole design I want to move them to a base class called DemoralizeBase, so if code needs change then the consistency becomes manageable.
// in DemoralizeBase
public void Demoralize(Func<IDemoralize, bool> CustomDemoralization)
{
//implementation
}
public void WriteModel(Func<IDemoralize, bool> Write)
{
// implementation
}
Is there a way to do this or I should go with the existing design?
You could write those as extension methods:
This will then work as though it were an instance method, i.e.
One thing to watch: when calling extension methods on the current instance, the
this.(which is usually optional) is required, i.e.