This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Is there a way to iterate through a collection of fields in an entity? I have a program that is used to sync data on multiple computers. As much as possible we are using Generics to reduce the amount of code used. This approach is working well for the GetData<T>() part, however, for the saving on the other end, it doesn't work so well. What I need is smething like Foreach(var fld in entitiy.Fields). At the moment, we need to create about 30 processors to save the data, on for each entity type (table). This is a bit of a nightmare, especially when we occasionally change tables in the main application. but forget to update the processor in the sync application. |
|
|
No, but you can use Reflection (internally that's all we do anyway). Look for instance fields that don't have the TransientAttribute. You could also look at using a custom T4 template against the .lsmodel file to generate strong-typed processor methods or classes. |
|
|
Both reflection and T4 templates are totally new to me. Can you point me in the direction of some examples that I could look at. Many thanks. |
|
|
For Reflection, google ".net reflection." For general examples, http://odetocode.com/Articles/288.aspx is a reasonable place to start, but the key API for your purposes would probably be Type.GetFields: http://msdn.microsoft.com/en-us/library/6ztex2dc.aspx For T4, here's MSDN: http://msdn.microsoft.com/en-us/library/bb126445.aspx And here's some info about using T4 with LightSpeed: http://www.mindscape.co.nz/blog/index.php/2010/04/12/using-t4-templates-with-lightspeed/ If you're new to this area, I'd strongly recommend starting with Reflection rather than T4 -- T4 is more powerful, but is quite a lot more to get your head around (and might not even be viable without a dose of Reflection anyway)! |
|