2

Visual Studio 2010では、初回例外が出力ウィンドウに書き込まれるのを防ぐことはできますか?設計上失敗しているキャストが多数あり、デバッグ時に出力ウィンドウがアプリケーションの速度を大幅に低下させているシナリオがあります。タイプ「System.InvalidCastException」の最初のチャンスの例外が発生しました...何度も何度も時間がかかります。Visual Studioのコンソールは高速ではありません:<)

ファーストチャンスの例外で中断しないオプションを知っていますが、それは出力ウィンドウに影響を与えないようです。私たちを遅くしている領域の前にこれを置くこともしません:

Debug.Listeners.Clear()

[出力]ウィンドウを閉じても効果はありません。ただし、リリースモードでは非常に高速に実行されます。

どんな助けでも大歓迎です!

4

2 に答える 2

4

I can answer this for Visual Studio 2013:

In VS 2013 you can go to the DEBUG menu - Options and Settings... - Debugging - Output Window. Under "General Output Settings" you find "Exception Messages". Turn it off.

于 2015-06-16T07:36:30.863 に答える
1

Per @Iridium's comment, I wound up changing to a Try pattern and return a bool as a success flag instead of throwing an InvalidCastException. Looks a lot like this:

if (!property.CanAssignValue(valueToSet))
{
    Debug.Write(string.Format("The given value {0} could not be assigned to property {1}.", value, property.Name));
    return false;
}
property.SetValue(instance, valueToSet, null);
return true;

The "CanAssignValue" became three quick extensions:

public static bool CanAssignValue(this PropertyInfo p, object value)
{
    return value == null ? p.IsNullable() : p.PropertyType.IsInstanceOfType(value);
}

public static bool IsNullable(this PropertyInfo p)
{
    return p.PropertyType.IsNullable();
}

public static bool IsNullable(this Type t)
{
    return !t.IsValueType || Nullable.GetUnderlyingType(t) != null;
}

Thanks!

于 2012-06-05T18:07:08.180 に答える