internal static RefStructsRoxor CreateRefStruct() { RefStructsRoxor rsrxr = new RefStructsRoxor(false); if (!rsrxr.IsValid) { throw new InvalidOperationException(); } return(rsrxr); }
public static bool DoBadStuffWithStruct() { RefStructsRoxor badNaughty = CreateDisposableRefStruct(); bool wasValid = badNaughty.IsValid; bool wasDisposedAtFirst = badNaughty.IsValid; Console.WriteLine($@"badNaughty was valid at first: {wasValid}."); Console.WriteLine($@"badNaughty was disposed at first: {wasDisposedAtFirst}."); badNaughty.Dispose(); bool isValidAfterDispose = badNaughty.IsValid; bool isDisposedAfterDispose = badNaughty.IsDisposed; Console.WriteLine($@"badNaughty was valid after Dispose: {isValidAfterDispose}."); Console.WriteLine($@"badNaughty was disposed after Dispose: {isDisposedAfterDispose}."); return(wasValid && !wasDisposedAtFirst && !isValidAfterDispose && isDisposedAfterDispose); }
public static RefStructsRoxor CreateDisposableRefStruct() => RefStructsRoxor.CreateRefStruct();