我正在使用ASP.NET MVC + LinqToSQL。
我的申请中有附件模型。我在几个模型中需要<IEnumerate>Attachment Attachments
。我不是不为不同的父类创建不同的附件模型。有简单的方法吗?
答案 0 :(得分:0)
您是否想要在模型中的更多位置使用附件?例如Employee
和Customer
个对象?你的意思是:
public class Attachment { /* Various properties... */ }
public class Attachments : List<Attachment>
{
public void DoSomething()
{
foreach (Attachment attachment in this)
DoSomethingToAttachment(attachment);
}
}
public interface IAttachmentHandler
{
void HandleAttachments();
}
public class Employee : IAttachmentHandler
{
private Attachments _attachments;
public void HandleAttachments()
{
_attachments.DoSomething();
}
}
public class Customer : IAttachmentHandler
{
private Attachments _attachments;
public void HandleAttachments()
{
_attachments.DoSomething();
}
}