2012-03-19 67 views
3

此代码是一个后续问题以下,如果你想看到:Parse to Nullable Enum为空的类型入门类型定义打破了非可空类型

Type t = currentProperty.PropertyType; 
if (t.GetGenericTypeDefinition() == typeof(Nullable<>)) 
    t = t.GetGenericArguments().First(); 

我上线#2得到一个错误这是IF声明。

System.Reflection.TargetInvocationException : Exception has been thrown by the 
target of an invocation. ----> System.InvalidOperationException : This operation 
is only valid on generic types. 
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) 
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes) 
at System.Activator.CreateInstance(Type type, Object[] args) 

如何在执行IF语句中的代码之前测试该条件?

+0

什么是内异常? – 2012-03-19 03:55:45

回答