只有第二个问题在这里提出,所以如果我遗漏了一些代码可能会帮助您评论这么说。C#如何在方法运行之前使用派生类变量设置基类变量
我有一个抽象类Report,派生类叫做BusinessBreakdown,派生类叫做BusinessWrittenBreakdown。
如何更改此代码,使BusinessWrittenBreakdown中的ReportTitle,DateField和DataLabel在BuildDefinition方法运行之前在BusinessBreakdown中设置具有相同名称的构造函数。
我试过使用谷歌搜索和所有,但不能解决如何,这是我得到。出现的错误似乎没有帮助,所以我更多地寻求一种可行的不同方法。
public class BusinessBreakdown : Report
{
static string ReportTitle;
static string DateField;
static string DateLabel;
public BusinessBreakdown(string theReportTitle, string theDateField, string theDateLabel)
: base(BuildDefinition)
{
ReportTitle = theReportTitle;
DateField = theDateField;
DateLabel = theDateLabel;
}
/// <summary>
/// Build the report definition
/// </summary>
/// <returns></returns>
public static ReportDef BuildDefinition(Settings settings)
{
// Create definition
var rdef = new ReportDef();
// Create configuration context
var context = new FsConfigContext();
rdef.ConfigContext = context;
// Report title
rdef.ReportTitle = ReportTitle;
// Create report date range configuration
ConfigDateRange drange = new ConfigDateRange(settings, "ReportDate", Config.ConfigDisposition.Filter,
new FilterExpressionDef
{
Expression = DateField
}, DateLabel);
rdef.ReportDate = drange;
///// code ...
return rdef;
}
}
}
public class BusinessWrittenBreakdown : BusinessBreakdown
{
// Report title
static string ReportTitle = "Business Written Breakdown Report";
// Report date range and label
static string DateField = "COMMISS.BRDateWritten";
static string DateLabel = "Written Date";
public BusinessWrittenBreakdown()
: base(ReportTitle, DateField, DateLabel)
{
}
/// more code...
}
}
你的领域为什么是静态的? – sstan
你说你得到一个错误,但不要说什么,或者它在哪里。 –
它不清楚你在问什么。你能举一个你想要发生什么的例子吗? –