473,396 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to use code templates for entity properties

I'm using VCS Express 2005.
I have a lot of property definitions in different classes like

public class MyEntity {
public string somestringfield {
get { return (string)Row["somestringfield"]; }
set { Row["somestringfield"] = value; }
}

public string someotherstringfield {
get { return (string)Row["someotherstringfield"]; }
set { Row["someotherstringfield"] = value; }
}
}

When template changes I must manually change it in hundreds of places.

I tried to use template

#define StringFieldTemplate( propname ) \
public string propname { \
get { return (string)Row[propname]; } }
set { Row[propname] = value; } \
};

public class MyEntity {
StringFieldTemplate("somestringfield2")
StringFieldTemplate("someotherstringfield2")
}

But got error.
How to implement this ?

Andrus.
May 26 '07 #1
3 2390
C# does not expand macro expansion, for various reasons that have been
discussed many times.

Can I ask... what sort of changes are you talking about? And what sort
of architecture? For instance, if there is a common base-class it
might be possible to use a method from a base-class (i.e.
GetValue(...) and SetValue(...)) - although since this appears to be
Data-Table based I'm not 100% sure how well this would work.

If the code is *that* predictable, it might be possible to script the
changes? I have done this before using reflection (or
System.ComponentModel) to list the properties by Type. This might also
be something that something like "resharper" could help with (I'm not
a regular user of resharper, so I don't know if it can do this
particular type of tranform en-masse to an existing codebase).

Finally; are these properties to support the model ar the view? i.e.
are they for binding purposes or for coding purposes (or both). If
they are mainly for binding, then you might be able to put the main
code (i.e. the bit that might change) into a bespoke
PropertyDescriptor using a TypeDescriptionProvider.

Marc

May 26 '07 #2
Can I ask... what sort of changes are you talking about?

They classical entity objects described everywhere.

I created in entity base class property Row

GetEntity() method fills Row property from database.

poperty getter and setter methods convert to/from Row
>And what sort
of architecture? For instance, if there is a common base-class it
might be possible to use a method from a base-class (i.e.
GetValue(...) and SetValue(...)) - although since this appears to be
Data-Table based I'm not 100% sure how well this would work.
I have the following entity base class

public abstract class Entity {

public DataRow Row;

}

If the code is *that* predictable, it might be possible to script the
changes? I have done this before using reflection (or
System.ComponentModel) to list the properties by Type. This might also
be something that something like "resharper" could help with (I'm not
a regular user of resharper, so I don't know if it can do this
particular type of tranform en-masse to an existing codebase).

Finally; are these properties to support the model ar the view? i.e.
are they for binding purposes or for coding purposes (or both). If
they are mainly for binding, then you might be able to put the main
code (i.e. the bit that might change) into a bespoke
PropertyDescriptor using a TypeDescriptionProvider.
They are for use strong typing in code.
For binding to winforms textboxes etc. I use DataTable
entity object Row property refers to this datatable row.

I read your codeproject article and tried your code from previous thread but
havent found
a way to use dynamic properties.

So I started to manually create getter/setter method for every entity for
every property.

Andrus.
May 27 '07 #3
They are for use strong typing in code.
For binding to winforms textboxes etc. I use DataTable
entity object Row property refers to this datatable row.

So I started to manually create getter/setter method for every entity for
every property.
If you want to use them directly from code with strong typing, then
you need compile-time properties. I understand you are using a DataRow
as the storage, but by wrapping it you prevent yourself from using
DataView that would provide dynamic properties at runtime for you;
likewise, typed datasets would additionally provide compile-time
property support.

You might have already answered, but is there any specific reason you
can't just expose the DataRow (or a sub-class) directly? It just seems
a peculiar hybrid of an OO and DataTable solution.

So: where do you want to go? Scripting the properties seems like it
might be quite possible (assuming that the schema is available
somewhere) - but likewise, so might a typed DataSet (which would be
less effort). Dynamic properties remains an option, but doens't
provide the compile-type support you want, unless you back them with
compile-time properties, which puts you right back at square one. I'd
be looking at either scripting from schema, or typed DataSet from
schema.

Marc

May 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Ransburg | last post by:
Hello! I've got the following XML "template" (for example). <personalData> <address> <name>$var1</name> <zip>$var2</name> </address> <telephone type=$var3>$var4</telephone>
14
by: john.burton.email | last post by:
I've done some extensive searching and can't seem to find an answer to this - Is it correct to using "using" with templates, for example: using std::vector; Or do I need to specify the type...
3
by: Andy | last post by:
Hi all, I'm having a problem doing an Xslt transform in code. I've done it before, so I'm not really sure why its not working. The problem is that the result of the transform is an empty...
20
by: Steve Jorgensen | last post by:
A while back, I started boning up on Software Engineering best practices and learning about Agile programming. In the process, I've become much more committed to removing duplication in code at a...
11
by: Arsen Vladimirskiy | last post by:
Hello, If I have a few simple classes to represent Entities such as Customers and Orders. What is the proper way to pass information to the Data Access Layer? 1) Pass the actual ENTITY to...
4
by: Stefano | last post by:
Hi all, I'm designing classes for my application. I'd like to create a business entity that could be expanded with other properties when needed. For example, this could be my entity: ...
2
by: jesl | last post by:
Group, I have created a User Control with the property "Html" of type string. If I declare this control on an ASPX page with the value "<b>This is an entity: &lt;</b>" for the property "Html", the...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
4
by: Jeff | last post by:
hi asp.net 2.0 I have a table, (lets call the table "Car") which links to the aspnet_Users table. (UserId) I'm creating an entity class of the car table, containing all the fields in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.