Guys, What would this company gain by re-writing their COBOL code in .NET? Was .NET the platform randomly drawn out of a hat? If you have to do COBOL code, the best is to do it *in COBOL*!
Trying to emulate COBOL structures in .NET might be cheaper in the short-term, but much more expensive in the long-run! Maintenance and client-code is going to be absolutely fugly. This is getting more and more a candidate for http://thedailywtf.com/ :P -- Ernst Kuschke MVP - C# (South Africa) http://www.ernstkuschke.com On 11/14/06, RYoung <[EMAIL PROTECTED]> wrote:
Here's something else with attributes: class Program { static void Main(string[] args) { Data d1 = new Data(); d1.FirstName = "Ron"; d1.LastName = "Young"; Data d2 = new Data(); d2.FullName = d1.FullName; d2.FirstName = "Craig"; Console.WriteLine(d1.FullName); Console.WriteLine(d2.FullName); } } class Data { private char[] namebuffer = new char[20]; [Length(20), Offset(0)] public string FullName { get { return ReadBuffer("FullName"); } set { SetBuffer("FullName", value); } } [Length(10), Offset(0)] public string FirstName { get { return ReadBuffer("FirstName"); } set { SetBuffer("FirstName", value); } } [Length(10), Offset(9)] public string LastName { get { return ReadBuffer("LastName"); } set { SetBuffer("LastName", value); } } public Data() { for (int i = 0; i < namebuffer.Length; i++) { namebuffer[i] = ' '; } } private int GetLength(string fieldName) { PropertyInfo prop = this.GetType().GetProperty(fieldName); LengthAttribute lengthAttribute = (LengthAttribute)prop.GetCustomAttributes(typeof(LengthAttribute), false)[0]; return lengthAttribute.Length; } private int GetOffset(string fieldName) { PropertyInfo prop = this.GetType().GetProperty(fieldName); OffsetAttribute offsetAttribute = (OffsetAttribute)prop.GetCustomAttributes(typeof(OffsetAttribute), false)[0]; return offsetAttribute.Offset; } private string ReadBuffer(string fieldName) { int length = GetLength(fieldName); int offset = GetOffset(fieldName); char[] buffer = new char[length]; for (int i = 0; i < length; i++) { buffer[i] = namebuffer[offset]; offset++; } return new string(buffer); } private void SetBuffer(string fieldName, string value) { int offset = GetOffset(fieldName); for (int i = 0; i < value.Length; i++) { namebuffer[offset] = value[i]; offset++; } } } class LengthAttribute : Attribute { private int length; public int Length { get { return length; } } public LengthAttribute(int length) { this.length = length; } } class OffsetAttribute : Attribute { private int offset; public int Offset { get { return offset; } } public OffsetAttribute(int offset) { this.offset = offset; } } ----- Original Message ----- From: "Jon Rothlander" <[EMAIL PROTECTED]> To: <ADVANCED-DOTNET@DISCUSS.DEVELOP.COM> Sent: Monday, November 13, 2006 9:21 PM Subject: [ADVANCED-DOTNET] Data Structures in .Net? > I'm working on something that is common in other languages, but something > that .Net doesn't seem to support, at least it's not common enough for me > to > search the Internet for it or find it in any books. What I am trying to > do > is actually simple... > > Let's say that you have the following data... > > First Name (20) > Last Name (20) > Middle Name (20) > Area Code (3) > Delimiter2 (1) > Phone_Prefix (3) > Delimiter2 (1) > Phone_Suffix (4) > > That data might look like... > > Jon Rothlander Gregory 123-123-1234 > > What I want to do is to create the following variables.... > > Name_First > Name_Last > Name_Middle > Phone_AreaCode > Phone_Del1 > Phone_Pre > Phone_Del2 > Phone_Suf > > But I also want to create the following variables as well... > > Name_Full > Phone_Full > > What I cannot figure out is how to do something like... > > Name_Full = "Jon Rothlander Gregory " > Phone_Full = "123-123-1234" > > Then have the values in the other varibles get filled without having to > code > lots of Mid() string commands. > > In other lanugauges like C, RPG, COBOL, and other, you can declare a > variable that points to a given set of memory. Then you can declare other > variables to point that that same memory. Then when you update one > variables, all the other variables that also point to that memory are > automatically update as well. That's what I'm trying to do. > > If you could do this in .Net like you could in COBOL or RPG, you would do > something like... > > Dim Name_Full as String Length(60) Start(1) End(60) > Dim Name_First as String Length(20) Start(1) End(20) > Dim Name_Last as String Length(20) Start(21) End(40) > Dim Name_Middle as String Length(20) Start(41) End(60) > > What you are able to do here is to tell the compiler that Name_Full starts > at position 1 and goes to position 60. Name_First starts at 1 and goes to > 20. When you move a value into Name_First, the memory is updated and both > Name_Full and Name_First are updated because they point to the same memory > location. > > Is there something like this available in .Net? I have been told that > there > is, but no one has been able to provide me a sample. > > I know that I can go in and build a class to control this. I have done > that > and it works. The problem is that it's way to much work. I want to find > something a little less complex. When I built a class to support this, I > was able to create the variables as properties over a local property that > stores the full set of data. Then each property pulls out a given > Mid(x,y) > value based on the definition of the variable. This does work, but it's a > major pain. I have been told that .Net does support some various ways to > have multiple variables point at the same memory location. > > Any ideas how .Net supports that? I'm not sure where to start looking. > > Best regards, > Jon > > =================================== > This list is hosted by DevelopMentor(r) http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com > =================================== This list is hosted by DevelopMentor(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
=================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com