如何将通用覆盖“TooLow”吸气剂代码提取到单个“模板”吸气剂?泛型?重载'<'?
get {
bool rtn = _prmpt.MinValue.HasValue && (_prmpt.ResultValue < _prmpt.MinValue);
return rtn;
}
目标是只拥有此代码一次。但是我还没有弄清楚如何处理'int?和“十进制?” 调用来做.HasValue
和<
正确使用泛型。. . . 建议?先感谢您。
/// <summary>
/// abstracted Generic Prompt Base
/// </summary>
public abstract class GenPromptBase
{
public string InputValueType { get; set; }
public abstract bool TooLow { get; }
}
/// <summary>
/// Derived Generic 'Money' class of 'GenPromptBase'
/// </summary>
public class GenPromptMoney : GenPromptBase
{
PromptMoney _prmpt;
public GenPromptMoney(PromptMoney prmptParms)
{
_prmpt = prmptParms;
InputValueType = _prmpt.InputValueType;
}
public override void ParseInput(string result)
{
_prmpt.ResultValue = decimal.Parse(result);
}
public override bool TooLow
{
get
{
bool rtn = _prmpt.MinValue.HasValue && (_prmpt.ResultValue < _prmpt.MinValue);
return rtn;
}
}
}
/// <summary>
/// Derived Generic 'Value' class of 'GenPromptBase'
/// </summary>
public class GenPromptValue : GenPromptBase
{
PromptValue _prmpt;
public GenPromptValue(PromptValue prmptParms)
{
_prmpt = prmptParms;
InputValueType = _prmpt.InputValueType;
}
public override void ParseInput(string result)
{
_prmpt.ResultValue = int.Parse(result);
}
public override bool TooLow
{
get
{ bool rtn = _prmpt.MinValue.HasValue && (_prmpt.ResultValue < _prmpt.MinValue);
return rtn;
}
}
}
/// <summary>
/// Generic Prompt Class
/// </summary>
public class GenPrompt<Z>
{
public string InputValueType { get; set; }
public Z MinValue;
public Z MaxValue;
}
/// <summary>
/// Derived 'Money' class of 'GenPrompt« decimal? »'
/// </summary>
public class PromptMoney : GenPrompt<decimal?>
{
public PromptMoney(
decimal? minValue = null,
decimal? maxValue = null,
string inputValueType = Constants.U_GOI_FORMAT_OPTION_MONEY)
{
InputValueType = inputValueType;
MinValue = minValue;
MaxValue = maxValue;
ResultValue = null;
}
public decimal? ResultValue;
}
/// <summary>
/// Derived 'Value' class of 'GenPrompt« int? »'
/// </summary>
public class PromptValue : GenPrompt<int?>
{
public PromptValue(
int? minValue = null,
int? maxValue = null,
string inputValueType = Constants.U_GOI_FORMAT_OPTION_NUMBER)
{
InputValueType = inputValueType;
MinValue = minValue;
MaxValue = maxValue;
ResultValue = null;
}
public int? ResultValue;
}