using System;
class Test{
public struct Ref{
public delegate int GetD<T>(T A);
public delegate void SetD<T, VT>(ref T trg, VT val);
public struct RefIn<T, VT>{
public readonly GetD<T> Get;
public readonly SetD<T, VT> Set;
public RefIn(GetD<T> g, SetD<T, VT> s){
Get = g;
Set = s;
}
}
public static RefIn<T, VT> Wrap<T, VT>(GetD<T> g, SetD<T, VT> s){
return new RefIn<T, VT>(g, s);
}
}
struct Hoge {
public int A;
}
public static void Main(){
Hoge trg = new Hoge();
var wr = Ref.Wrap(
(Hoge t) => t.A,
(ref Hoge t, int v) => t.A = v
);
wr.Set(ref trg, 100);
Console.Write( wr.Get(trg) );
}
}
dXNpbmcgU3lzdGVtOwoKY2xhc3MgVGVzdHsKCXB1YmxpYyBzdHJ1Y3QgUmVmewoJCXB1YmxpYyBkZWxlZ2F0ZSBpbnQgR2V0RDxUPihUIEEpOwoJCXB1YmxpYyBkZWxlZ2F0ZSB2b2lkIFNldEQ8VCwgVlQ+KHJlZiBUIHRyZywgVlQgdmFsKTsKCQlwdWJsaWMgc3RydWN0IFJlZkluPFQsIFZUPnsKCQkJcHVibGljIHJlYWRvbmx5IEdldEQ8VD4gR2V0OwoJCQlwdWJsaWMgcmVhZG9ubHkgU2V0RDxULCBWVD4gU2V0OwoJCQlwdWJsaWMgUmVmSW4oR2V0RDxUPiBnLCBTZXREPFQsIFZUPiBzKXsKCQkJCUdldCA9IGc7CgkJCQlTZXQgPSBzOwoJCQl9CgkJfQoJCXB1YmxpYyBzdGF0aWMgUmVmSW48VCwgVlQ+IFdyYXA8VCwgVlQ+KEdldEQ8VD4gZywgU2V0RDxULCBWVD4gcyl7CgkJCXJldHVybiBuZXcgUmVmSW48VCwgVlQ+KGcsIHMpOwoJCX0KCX0KCXN0cnVjdCBIb2dlIHsKCQlwdWJsaWMgaW50IEE7Cgl9CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpewoJCUhvZ2UgdHJnID0gbmV3IEhvZ2UoKTsKCQkKCQl2YXIgd3IgPSBSZWYuV3JhcCgKCQkJKEhvZ2UgdCkgPT4gdC5BLAoJCQkocmVmIEhvZ2UgdCwgaW50IHYpID0+IHQuQSA9IHYKCQkpOwoJCQoJCXdyLlNldChyZWYgdHJnLCAxMDApOwoJCUNvbnNvbGUuV3JpdGUoIHdyLkdldCh0cmcpICk7Cgl9Cn0K