2012-03-19 10 views
3

あなたが見たい場合、これは次のようにフォローアップの質問です:Parse to Nullable EnumNULL可能型の型定義を取得するnull非許容型のコードを壊す

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

内部例外とは何ですか? –

答えて

関連する問題