【发布时间】:2015-10-05 10:48:39
【问题描述】:
给定类型列表:
public class TypeLists
{
public static List<Type> types
{
get
{
return new List<Type>() { typeof(ValueBool), typeof(ValueInt), typeof(ValueDouble), typeof(ValueString) };
}
}
}
我想传递此列表或其他列表,以便在一种方法中通用地使用它们,该方法将以下列方式转换随附的对象参数:
public static SettingValueUnit UsingAType<T>(object value)
{
var a = (T)value;
}
我尝试实现它的使用:
foreach (Type t in TypeLists.types)
{
SettingValueUnit ValueUnit = UsingAType<t>(D.SettingValue.value);
}
但我收到以下错误
错误 1 't' 由于其保护级别而无法访问
我受限于 .Net 3.5 紧凑型框架。 我将不胜感激。
【问题讨论】:
-
我现在意识到这个错误的性质很奇怪,因为我正在使用紧凑框架的沙盒版本。
标签: c# generics .net-3.5 compact-framework