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,
--
[*Thomas Themel*] The fundamental problem with vi is that it doesn't have
[extended contact] a mouse and therefore you've got all these commands.
[info provided in] - Bill Joy, <http://www.cs.pdx.edu/~kirkenda/joy84.html>
[*message header*] 2 5129
Thomas,
Like you said, you will create a copy every time. The only way around
this is to create a class, but like you said, it seems like an nightmare to
maintain.
I would stil use the class route, using read-only properties, but I
would write a program that would generate the code for you which you can
compile. Using reflection, you can scan a type (your structure), and then
have it spit out code which would expose the read-only properties which are
copied over from the structure (through the constructor perhaps). If you
want to get fancy, you can even write a static cast operator to your struct
to convert from your class to an instance of the struct and embed it in the
code.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com
"Thomas Themel"
<th*********************************************** *****@isogsglei.iwoars.net wrote in message
news:sl******************************************* *********************@eristoteles.iwoars.net... 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, -- [*Thomas Themel*] The fundamental problem with vi is that it doesn't
have [extended contact] a mouse and therefore you've got all these commands. [info provided in] - Bill Joy,
<http://www.cs.pdx.edu/~kirkenda/joy84.html> [*message header*]
Nicholas Paldino [.NET/C# MVP] <ni**************@exisconsulting.com>
wrote on 2003-09-15: I would stil use the class route, using read-only properties, but I would write a program that would generate the code for you which you can compile. Using reflection, you can scan a type (your structure), and then have it spit out code which would expose the read-only properties which are copied over from the structure (through the constructor perhaps). If you want to get fancy, you can even write a static cast operator to your struct to convert from your class to an instance of the struct and embed it in the code.
Thanks, I hadn't thought about this kind of stuff yet (being the old
fashioned C++ person that I am). I think I'll hack up something to
handle it this way.
ciao,
--
[*Thomas Themel*] "That which is novice-friendly is too frequently
[extended contact] expert-hostile, and vice versa."
[info provided in] - Tom Christiansen, crossposting
[*message header*] "GUIs considered harmful" to eight groups This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: E G |
last post by:
Hi!
I am having problems in designing a class. First, I have a base class
that allocates a 3D data set and allows some other mathematical
operations with it, something like this:
template...
|
by: alexhong2001 |
last post by:
When design a class, should always make it "derivable" as a base class? Is
there really a situation that the designed class not "derivable"?
When should make a member "protected"? Only when...
|
by: Naren |
last post by:
Hello All,
I am presently designing a cleint server architecture.
I require some suggestions and help by the experts here.
MyServer class conatins a list of Mysock class.
class Myserver
{...
|
by: Darren |
last post by:
X-No-Archive
Hi all,
Can anyone help me with structuring the data in a small tool I have to
build? I'm trying to work out if there's a design pattern or data
structure that would remove some...
|
by: Dave |
last post by:
I have a system that basically stores a database within a database (I'm
sure lots have you have done this before in some form or another).
At the end of the day, I'm storing the actual data...
|
by: Gary James |
last post by:
This may not be a direct C# question, but since I'll be using using C# for
development, I thought I'd pose the question here.
I'll soon be involved in the design of a new software product that...
|
by: Sky Sigal |
last post by:
Hello:
I'm currently messing around, and need as much feedback/help as I can get, trying to find the most
economical/graceful way to build usercontrols that rely on styling to look any good...
...
|
by: krzysztof.konopko |
last post by:
Hello!
I want to design a class hierarchy with one base abstract class, let's
say CBase. I have a predicate that every object in the class hierarchy
must have a parent object of type from this...
|
by: weaknessforcats |
last post by:
Introduction
Polymorphism is the official term for Object-Oriented Programming (OOP). Polymorphism is implemented in C++ by virtual functions.
This article uses a simple example hierarchy which...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |