This might be a dumb question, but I'd love to know if there was a way I could do this.
To ease the process of importing lots and lots of Space-delimited files, I came up with a simple scheme to describe the layout in a dynamic type and throw it to a parser which calls a delegate.
A layout looks likes this:
var layout = new
{
Code = new SDFColumn() { Start = 0, Length = 20 },
Name = new SDFColumn() { Start = 20, Length = 3 }
// etc
};
All works great. I'm now in a situation where I have 2 very large SDFs to import, whose structure is 85% identical, bar a few differences at the end.
Is there a way to append the layout of one to another, e.g:
var layoutCommon = new
{
/* Common fields */
};
var layoutFile01 = new
{
/* Changes for first file type */
};
var layoutFile02 = new
{
/* Changes for the second file type */
};
var finalLayout = /* ??? */;
One thing I realised would not work, was:
var completeLayout = { };
if(file01)
completeLayout = { /* everything */ };
else
completeLayout = { /* everything */ };
This doesn't work, obviously, because all 3 types are fundamentally different.
Any ideas would be appreciated :)
Have you tried using dynamic
instead of var
? That should delay typing until runtime, so your potential objects don't have to match. var
is simply a substitute for any static type; it's not actually dynamic at all.