我有两个代码相似但变量不同的类
ISource.cs
public interface ISource
{
string AvailConfigPath { get; }
string AvailVersion { get; }
IDictionary<string, string> AvailFiles { get; }
}
public class Source : ISource
{
public string AvailConfigPath
{
get
{
return @"D:\Mindful\Visual Studio 2012\Projects\AutoUpdator\AutoUpdator\Source\AvailInfoFile.config";
}
}
private XDocument document = XDocument.Load(@"D:\Mindful\Visual Studio 2012\Projects\AutoUpdator\AutoUpdator\Source\AvailInfoFile.config");
public string AvailVersion
{
get
{
return document.Root
.Element("InfoConfigFile")
.Attribute("version").Value.ToString();
}
}
public IDictionary<string, string> AvailFiles
{
get
{
return document.Root
.Element("files")
.Elements("file")
.ToDictionary(x => x.Attribute("name").Value,
x => x.Attribute("version").Value);
}
}
}
ITarget.cs
public interface ITarget
{
string LocalConfigPath { get; }
string LocalVersion { get; }
IDictionary<string, string> LocalFiles { get; }
}
internal class Target : ITarget
{
public string LocalConfigPath
{
get
{
return @"D:\Mindful\Visual Studio 2012\Projects\AutoUpdator\AutoUpdator\Target\LocalInfoFile.config";
}
}
private XDocument document = XDocument.Load(@"D:\Mindful\Visual Studio 2012\Projects\AutoUpdator\AutoUpdator\Target\LocalInfoFile.config");
public string LocalVersion
{
get
{
return document.Root
.Element("InfoConfigFile")
.Attribute("version").Value;
}
}
public IDictionary<string, string> LocalFiles
{
get
{
return document.Root
.Element("files")
.Elements("file")
.ToDictionary(x => x.Attribute("name").Value,
x => x.Attribute("version").Value);
}
}
}
现在我想创建一个抽象类并将我的公共代码放在那个类文件中,然后在这两个类文件中继承该代码