迄今为止,这个对我来说证明是有点棘手。我想知道是否可以使用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