這裏是構造函數:如何將泛型類型參數傳遞給從構造函數調用的方法?
public PartyRoleRelationship(PartyRole firstRole, PartyRole secondRole)
{
if (firstRole == secondRole)
throw new Exception("PartyRoleRelationship cannot relate a single role to itself.");
if (firstRole.OccupiedBy == null || secondRole.OccupiedBy == null)
throw new Exception("One or both of the PartyRole parameters is not occupied by a party.");
// Connect this relationship with the two roles.
_FirstRole = firstRole;
_SecondRole = secondRole;
T = _FirstRole.GetType().MakeGenericType();
_SecondRole.ProvisionRelationship<T>(_FirstRole); // Connect second role to this relationship.
}
在最後一行,在那裏它_SecondRole呼籲ProvisionRelationship,它給我的運行時錯誤:類型或命名空間「T」找不到...
我該如何(a)正確地分配T,或(b)通過構造函數傳遞一個泛型類型?我一直在瀏覽不少帖子,但由於缺乏理解可能錯過了某些內容。任何人的幫助將不勝感激。
我編輯了你的標題。請參見「[應的問題包括‘標籤’,在他們的頭銜?(http://meta.stackexchange.com/questions/19190/)」,這裏的共識是「不,他們不應該」。 – 2013-03-03 23:11:54
什麼是.ProvisionRelationship(PartyRole角色)應該完成? – Moop 2013-03-03 23:12:06