我有哈希表将字符串保存为详细信息的键和类,现在我需要详细访问类的成员。我有这样的代码:
private readonly Hashtable _data = new Hashtable();
public ResultStatus Register<T,T1,T2>( T dataT, T1 dataT1,T2 dataT2 )
{
if( _data.ContainsKey( dataT ) )
{
return ResultStatus.DuplicateData;
}
var dataItem = new DataItem<T,T1,T2>( dataT,dataT1,dataT2 );
if( !_validatorManager.IsValid( (int)(object)dataT2 ) )
{
return ResultStatus.ContentError;
}
_data.Add( dataT, dataItem );
return ResultStatus.Success;
}
和我的DataItem类:
public class DataItem<T,T1,T2>
{
public T ItemName { get; set; }
public T1 ItemContent { get; set; }
public T2 ItemType { get; set; }
public DataItem( T name, T1 content, T2 type )
{
ItemName = name;
ItemContent = content;
ItemType = type;
}
}
和另一个检索它内容的类:
public Tuple<ResultStatus, T1> GetType<T,T1>( T itemName )
{
if( !_data.ContainsKey( itemName ) )
{
return new Tuple<ResultStatus, T1>( ResultStatus.Success, ( T1 ) ( object ) 0 );
}
else
{
return new Tuple<ResultStatus, T1>( ResultStatus.Success, _data[itemName].ItemType ); ==> ?? //Here .ItemType not shown
}
}
如何在DataItem类上访问ItemType?