How to create a group of methods/properties within a class?
Here is another solution using explicit interfaces:
public interface ICustomMethods { string FullName {get;}}public partial class Employee: Entity, ICustomMethods { public ICustomMethods CustomMethods { get {return (ICustomMethods)this;} } //explicitly implemented string ICustomMethods.FullName { get { return this.FirstName + " " + this.LastName; } }}
Usage:
string fullName;fullName = employee.FullName; //Compiler error fullName = employee.CustomMethods.FullName; //OK
public class CustomMethods{ Employee _employee; public CustomMethods(Employee employee) { _employee = employee; } public string FullName { get { return string.Format("{0} {1}", _employee.FirstName, _employee.LastName); } }}public partial class Employee : Entity{ CustomMethods _customMethods; public CustomMethods CustomMethods { get { if (_customMethods == null) _customMethods = new CustomMethods(this); return _customMethods; } }}
typically I would put Properties like FullName
right on the Partial class but I can see why you might want separation.