As I understand it, properties can not return references, and since structs are value types, there's no way to return a reference to a struct via properties, which would enable:
public struct SomeStruct
{
public int SomeMember { get; set; }
}
class foo
{
private SomeStruct bar;
public SomeStruct Bar{ get { return bar; } set { bar = value; } }
}
//Somewhere else
foo f = new foo();
f.Bar.SomeMember = 42; //Error, this doesn't work
Will I have to resort to setMemberOfSomeStruct() or is there another way?
edit: Specifically, I want to avoid having to call new for structs like these all the time. I know that with an constructor SomeStruct(int), this would work:
f.Bar = new SomeStruct(42); //ugh