迄今爲止,這個對我來說證明是有點棘手。我想知道是否可以使用System.Type對象類型轉換對象。類型使用C中的「類型」對象投射對象#
我已經說明下面我的意思:
public interface IDataAdapter
{
object Transform(object input);
Type GetOutputType();
}
public class SomeRandomAdapter : IDataAdapter
{
public object Transform(object input)
{
string output;
// Do some stuff to transform input to output...
return output;
}
public Type GetOutputType()
{
return typeof(string);
}
}
// Later when using the above methods I would like to be able to go...
var output = t.Transform(input) as t.GetOutputType();
以上是一個通用的接口,這就是爲什麼我使用「對象」的類型。
我在示例中沒有使它清楚,但是這兩種方法在IDataAdapter接口中。 – Ryall 2009-09-03 16:31:36
再次感謝傑夫。 – Ryall 2009-09-03 16:37:20
沒問題,我再次更新了我的答案。 – 2009-09-03 16:58:55