using System; namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty { internal class RefLocalsAndReturns { public delegate ref T RefFunc(); public delegate ref readonly T ReadOnlyRefFunc(); public ref struct RefStruct { private int dummy; } public readonly ref struct ReadOnlyRefStruct { private readonly int dummy; } public struct NormalStruct { private readonly int dummy; public void Method() { } } public readonly struct ReadOnlyStruct { private readonly int dummy; public void Method() { } } public static ref T GetRef() { throw new NotImplementedException(); } public static ref readonly T GetReadonlyRef() { throw new NotImplementedException(); } public void CallOnRefReturn() { // Both direct calls: GetRef().Method(); GetRef().Method(); // call on a copy, not the original ref: NormalStruct @ref = GetRef(); @ref.Method(); ReadOnlyStruct ref2 = GetRef(); ref2.Method(); } public void CallOnReadOnlyRefReturn() { // uses implicit temporary: GetReadonlyRef().Method(); // direct call: GetReadonlyRef().Method(); // call on a copy, not the original ref: ReadOnlyStruct readonlyRef = GetReadonlyRef(); readonlyRef.Method(); } public void CallOnInParam(in NormalStruct ns, in ReadOnlyStruct rs) { // uses implicit temporary: ns.Method(); // direct call: rs.Method(); // call on a copy, not the original ref: ReadOnlyStruct readOnlyStruct = rs; readOnlyStruct.Method(); } } }