As an explanation, take this type of value in C #:
struct ObjRef
{
public object Value;
public ObjRef(object value) { Value = value; }
}
I can imagine a graph of objects where there are two instances in a box of this type, each of which contains a link to the other. This is what I mean by a reference loop with value types only.
My question is whether it is ever possible to build such a graph of objects in .NET. In theory, the design, if it exists, will look like this:
object left = new ObjRef();
object right = new ObjRef(left);
left.Value = right;
but obviously the last line is invalid C #. Create the last line:
((ObjRef)left).Value = right;
does not achieve the result, as the casts are unpacked left, and you end up mutating the copy. So, at least in direct C #, this is not like a construct.
- , , , dynamic, IL - ? - , CLR ?
, . , , , / .
, , , . :
interface IObjRef
{
IObjRef Value { get; set; }
}
struct ObjRef : IObjRef
{
IObjRef value;
public IObjRef Value { get { return value; } set { this.value = value; } }
public ObjRef(IObjRef value) { this.value = value; }
}
:
IObjRef left = new ObjRef();
IObjRef right = new ObjRef(left);
left.Value = right;
โ 72, .