Auto mapping override ref property to field #3284
Replies: 4 comments
-
How exactly would this be implemented? The CLR requires that the virtual members of an interface be overridden by compatible members on the implementing class. The class would still be required to have the property accessors. At best the compiler could explicitly auto-generate them: struct Vec3 : IVec3 {
public float X,Y,Z;
ref float IVec.X {
get { return this.X; }
set { this.X = value; }
}
ref float IVec.Y {
get { return this.Y; }
set { this.Y = value; }
}
ref float IVec.Z {
get { return this.Z; }
set { this.Z = value; }
}
} But given that the auto-property implementation is not much more verbose does this really buy any advantages? |
Beta Was this translation helpful? Give feedback.
-
Well I wish this feature would be support by CLR if needed. I'm not sure so I don't mention it. But not that kind of workaround for sure |
Beta Was this translation helpful? Give feedback.
-
As soon as you access a struct via interface or access a field by ref, the struct will be boxed first, so as to keep the reference valid. So, you are replacing a float value copy with a memory allocation, a whole struct copy, a pointer return, and derefencing operations. What's the benefit to use it? |
Beta Was this translation helpful? Give feedback.
-
@qrli With generic constraint you don't boxed struct |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Since we have ref return feature. We now could use ref return property as abstract, virtual, or interface
So I think we could map those ref return property to field directly
Beta Was this translation helpful? Give feedback.
All reactions