Skip to content

Instantly share code, notes, and snippets.

@green224
Last active June 8, 2019 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save green224/d90e549fcfa2082c7063e3b02420d84d to your computer and use it in GitHub Desktop.
Save green224/d90e549fcfa2082c7063e3b02420d84d to your computer and use it in GitHub Desktop.

【C#】プロパティの多いクラスのデバッグ表示でStackOverFlow

自動生成したクラスなど、プロパティが非常に多いクラスを、Watch式などでデバッグ中に表示した際に、StackOverflowが起きる事がある。
例えばこういうコード

// ShaderのSwizzle operator相当の事をしたい
public Int4 xxxx { get=>new Int4(x,x,x,x); }
public Int4 xxxy { get=>new Int4(x,x,x,y); }
public Int4 xxxz { get=>new Int4(x,x,x,z); }
public Int4 xxxw { get=>new Int4(x,x,x,w); }
public Int4 xxyx { get=>new Int4(x,x,y,x); }
public Int4 xxyy { get=>new Int4(x,x,y,y); }
public Int4 xxyz { get=>new Int4(x,x,y,z); }
public Int4 xxyw { get=>new Int4(x,x,y,w); }
public Int4 xxzx { get=>new Int4(x,x,z,x); }
public Int4 xxzy { get=>new Int4(x,x,z,y); }
public Int4 xxzz { get=>new Int4(x,x,z,z); }
public Int4 xxzw { get=>new Int4(x,x,z,w); }
public Int4 xxwx { get=>new Int4(x,x,w,x); }
public Int4 xxwy { get=>new Int4(x,x,w,y); }
public Int4 xxwz { get=>new Int4(x,x,w,z); }
public Int4 xxww { get=>new Int4(x,x,w,w); }
public Int4 xyxx { get=>new Int4(x,y,x,x); }
public Int4 xyxy { get=>new Int4(x,y,x,y); }
public Int4 xyxz { get=>new Int4(x,y,x,z); }
public Int4 xyxw { get=>new Int4(x,y,x,w); }
public Int4 xyyx { get=>new Int4(x,y,y,x); }
 :
 :
 以下1000行ほど

これを含むクラスのインスタンスをWatchすると落ちる。


解決方法

System.Diagnostics.DebuggerBrowsable 属性を使用する

[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public Int4 xxxx { get=>new Int4(x,x,x,x); }

これでデバッグ中に表示されなくなり、StackOverflowを避けられる

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment