知らない:
- これが機能する場合。
- それが良い考えなら。
- それについてもっと知るためにそれが何と呼ばれるか。
しかし、その意図はかなり明白だと思います。
public static class DebugLogic
{
public static bool ThrowIfNull = false;
public static T OrNew<T>(this T obj) where T : class
{
if (obj != null) return obj;
else if (ThrowIfNull) throw new ArgumentNullException(//to do...);
else return Activator.CreateInstance<T>();
}
}
使用目的:
var customer = order.Sale.OrNew().Customer.OrNew().Name
私は何をやっている?これは非常識ですか、それとも役に立ちますか?役に立ったようです。