T
Thomas Themel
Hi,
I'm currently trying to model a few complex data objects in C#. These
have a huge number of attributes which are manipulated in large blocks
by comparatively few API calls.
For maintainability, I've come up with creating nested structs that
contain the sets of attributes manipulated by one API call - so
currently the way to access actual attributes is something like
'theObject.Details.Name' or 'theObject.AdditionalDetails.TemplateID'.
The obvious way to design the 'Details' and 'AdditionalDetails'
properties would be as structs. However, this strikes me as an
inefficient solution, since every time a client access
'theObject.Details.Something' a complete copy of the theObject.Details
struct is created, only to be discarded immediately.
(If this is handled in a sane way by the runtime environment, it would
make me happy - however, I didn't have time to get into IL enough to
figure this out myself yet.)
What I'm looking for is something equivalent to the C++ const& semantics
for exposing structured properties. The only thing I've come up with is
something like
class Details
{
Details(string someAttribute, string someOtherAttribute)
{
SomeAttribute = someAttribute ;
SomeOtherAttribute = someOtherAttribute ;
}
public readonly string SomeAttribute ;
public readonly string SomeOtherAttribute ;
}
However, this is obviously a nightmare to maintain, since my structs
contain about 20 members each.
Any ideas on how to do this so that
- access to object.Details.Something is possible without copying
object.Details
- there is no way for a caller to change object.Details.Something
- I don't need to spend half of my time maintaining huge parameter
lists
?
thanks,
I'm currently trying to model a few complex data objects in C#. These
have a huge number of attributes which are manipulated in large blocks
by comparatively few API calls.
For maintainability, I've come up with creating nested structs that
contain the sets of attributes manipulated by one API call - so
currently the way to access actual attributes is something like
'theObject.Details.Name' or 'theObject.AdditionalDetails.TemplateID'.
The obvious way to design the 'Details' and 'AdditionalDetails'
properties would be as structs. However, this strikes me as an
inefficient solution, since every time a client access
'theObject.Details.Something' a complete copy of the theObject.Details
struct is created, only to be discarded immediately.
(If this is handled in a sane way by the runtime environment, it would
make me happy - however, I didn't have time to get into IL enough to
figure this out myself yet.)
What I'm looking for is something equivalent to the C++ const& semantics
for exposing structured properties. The only thing I've come up with is
something like
class Details
{
Details(string someAttribute, string someOtherAttribute)
{
SomeAttribute = someAttribute ;
SomeOtherAttribute = someOtherAttribute ;
}
public readonly string SomeAttribute ;
public readonly string SomeOtherAttribute ;
}
However, this is obviously a nightmare to maintain, since my structs
contain about 20 members each.
Any ideas on how to do this so that
- access to object.Details.Something is possible without copying
object.Details
- there is no way for a caller to change object.Details.Something
- I don't need to spend half of my time maintaining huge parameter
lists
?
thanks,