【发布时间】:2011-08-13 12:34:05
【问题描述】:
我创建了一个如下所示的界面。 DTO 对象是一个具有 3 个参数的复杂值对象。
public interface IOperation
{
DTO Operate(DTO ArchiveAndPurgeDTO);
}
我需要实现此接口的人能够从原始 Value 对象继承并在需要时对其进行扩展。
我的假设是他们可以简单地继承 DTO 对象,添加(例如)另一个属性并在实现此接口的同一个类中使用它。
当我尝试使用扩展值对象时,Visual Studio 抱怨我不再隐含接口。
我怎样才能实现这个功能。
提前感谢您的任何想法和/或建议。
工程师
编辑: DTO 代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Company.ArchiveAndPurge
{
public class DTO
{
public DTO(String FriendlyID)
{
friendlyId = FriendlyID;
}
private String friendlyId = String.Empty;
public String FriendlyId
{
get { return friendlyId; }
set { friendlyId = value; }
}
private String internalId = String.Empty;
public String InternalyId
{
get { return internalId; }
set { internalId = value; }
}
private Boolean archivedSuccessfully = false;
public Boolean ArchivedSuccessfully
{
get { return archivedSuccessfully; }
set { archivedSuccessfully = value; }
}
}
}
扩展 DTO:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Company.MSO.ArchiveAndPurge
{
public class DTO: Company.ArchiveAndPurge.DTO
{
private Boolean requiresArchiving = true;
public Boolean RequiresArchiving
{
get { return requiresArchiving; }
set { requiresArchiving = value; }
}
}
}
VS抱怨的接口实现:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Company.ArchiveAndPurge.Contracts;
using Company.ArchiveAndPurge;
namespace Company.MSO.ArchiveAndPurge
{
public class ResolveFriendlyId: IOperation
{
#region IOperation Members
public DTO Operate(DTO ArchiveAndPurgeDTO)
{
ArchiveAndPurgeDTO.InternalyId = ArchiveAndPurgeDTO.FriendlyId;
return ArchiveAndPurgeDTO;
}
#endregion
}
}
【问题讨论】:
-
显示DTO类代码和VS报错的代码
标签: c# oop inheritance interface