I would really suggest getting your hands on the book Domain-Driven-Design
[2], especially the chapter on interfacing with legacy systems using the
Anti-Corruption layer [1] which is pretty close to what you need to do
having a translation layer to bridge the cobol/.net domains.

[1] http://patternshare.org/default.aspx/Home.DDD.AnticorruptionLayer
[2] http://domaindrivendesign.org/books/index.html

Still, I'm sure a $20m!? project has bigger problems than deciding whether
to waste more money trying to develop a cobol like solution in .NET :-) The
world have moved on. Integrate with the legacy system but don't let it
dictate your design decisions. Sure Java can do it, .NET can to but it
smells! bad!

On 11/16/06, Jon Rothlander <[EMAIL PROTECTED]> wrote:

>>I'm sorry for saying this, but you seem to miss what everyone was trying
>>to tell you in the past 15+ messages: you *can* do what you want in C#.
>>But just because you can do it, it doesn't mean that you should.


Exactly!

 Here's another example...

DATE  Start(1) Length(8)
YEAR  Start(1) Length(4)
MONTH Start(5) Length(2)
DAY   Start(7) Length(2)


Ok, here's a stab at that allowing direct conversion between string and your
structure above and .net's datetime:

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;


namespace Union
{
   [StructLayout(LayoutKind.Explicit, Size = 16)]
   public unsafe struct CobolDate
   {
       [FieldOffset(0)]
       fixed char year[4];
       [FieldOffset(8)]
       fixed char month[2];
       [FieldOffset(12)]
       fixed char day[2];
       [FieldOffset(0)]
       fixed char date[8];

       public string Date
       {
           get {
               fixed (char* c = date) {
                   return new string(c, 0, 8);
               }
           }
       }

       public string Year
       {
           get {
               fixed (char* c = year) {
                   return new string(c, 0, 4);
               }
           }
       }

       public string Month
       {
           get {
               fixed (char* c = month) {
                   return new string(c, 0, 2);
               }
           }
       }

       public string Day
       {
           get {
               fixed (char* c = day) {
                   return new string(c, 0, 2);
               }
           }
       }

       public static unsafe implicit operator CobolDate(string s)
       {
           fixed (char* c = s) {
               return *(CobolDate*)c;
           }
       }

       public static unsafe implicit operator DateTime(CobolDate d)
       {
           string s = new string(d.date, 0, 8);
           return DateTime.ParseExact(s, "yyyyMMdd", null);
       }

       // now this would've been pretty useful to convert any of the
structures
       //public static T ConvertMe<T>(string cobol) where T : struct
       //{
       //    fixed (char* c = cobol) {
       //        return *(T*)c;
       //    }
       //}

   }

   class Program
   {
       static unsafe void Main(string[] args)
       {
           // assume cobol data is unicode
           string test = "20061202OTHERCRAPFROMTHECOBOLSYSTEM";
           // implicit conversion
           CobolDate cd = test;

           Console.WriteLine(cd.Date);
           Console.WriteLine(cd.Year);

           DateTime dotnetdate = cd;
           Console.WriteLine(dotnetdate.ToLongDateString());

           Console.ReadLine();
       }
   }
}

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to