只有第二個問題在這裏提出,所以如果我遺漏了一些代碼可能會幫助您評論這麼說。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
你說你得到一個錯誤,但不要說什麼,或者它在哪裏。 –
它不清楚你在問什麼。你能舉一個你想要發生什麼的例子嗎? –