0
如何檢索用於初始化RuleViewModelBase的類型T的名稱?現在我得到 「RuntimeType」如何檢索T型的名稱?我總是得到「RuntimeType」
public abstract class RuleViewModelBase<T> : IRuleViewModel where T : RuleEntity, new()
{
public bool Editable
{
set
{
_editable = value;
if (Condition != null)
{
Condition.Editable = value;
}
if (Content != null)
{
Content.Editable = value;
}
}
get
{
return _editable;
}
}
private bool _editable;
private string _groupsJson;
private List<RuleGroupJM> _groups;
public string RuleType { get {
return typeof(T).GetType().Name; }
}
public RuleContentVm Content { set; get; }
public RuleConditionVm Condition { set; get; }
public virtual void SaveToEntity(T rule)
{
}
public RuleEntity ConvertToEntity()
{
T rule = new T();
rule = (T)this.Content.SaveToEntity(rule);
rule = (T)this.Condition.SaveToEntity(rule);
SaveToEntity(rule);
return rule;
}
}
'typeof(T)'產生'T'的類型。調用'GetType'就可以得到'typeof'返回的值的類型。這顯然不是你想要的。 –