方法中的泛型--同一方法中使用多个泛型:
原创:
以下是我使用的同一方法中使用多个泛型, 且泛型继承于指定的类
/// <summary>
/// 从数据库填写业务表到获取题的已填选项
/// </summary>
/// <typeparam name="TSource">NiToptics 泛型</typeparam>
/// <param name="niToptics"></param>
/// <param name="niAItem"></param>
static public void GetValueFromNiTopics<TSource, TTarget>(TSource niToptics, TTarget niAItem)
where TSource : NiToptics
where TTarget : NiAItem
{
for (int i = 0; i < niToptics.Count; i++)
{
NiTopticItem toptic = niToptics[i];
bool hasFindField = niAItem.Dict字段值.ContainsKey(toptic.ID);
if (hasFindField)
{
switch (toptic.SelectMode)
{
case SelectedMode.SingleSelect:
case SelectedMode.MultSelect:
{
string strResult = string.Empty;
for (int j = 0; j < toptic.Options.Count; j++)
{
if (toptic.Options[j].IsSelected)
{
strResult += string.Format("[{0}]", toptic.Options[j].Name);
}
}
niAItem.Dict字段值[toptic.ID] = strResult;
}
break;
case SelectedMode.Edit:
default:
break;
}
}
}
}