Re: Help With Nesting Classes In Library



joey.powell@xxxxxxxxxxxx wrote:
I am writing a class that will do some binary file IO. The class will
need to read a header from the binary file, and it will also need to
read a varying number of records in the file. I currently have two main
methods: Open(string FilePath) and Close(). I would like to read all of
the data into variables whenever Open is called. I would like to have a
Header (sub?)class within the main class, and maybe a collection or
array for the records. The following is a snippet of what I have so
far...

You're right: there's some confusion here. I've made some notes
in-line.

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace MyNameSpace
{
public class MyClass
{
private FileStream fsMyFile;
private BinaryReader brMyFile;

public void Open(string FilePath)
{
fsMyFile = new FileStream(FilePath, FileMode.Open,
FileAccess.ReadWrite);
brMyFile = new BinaryReader(fsMyFile);


The following line should compile fine. It doesn't matter that Header
is nested inside MyClass: you're just setting a static property of the
class Header to be 2.

Header.MyCode = 2;
}

public void Close()
{
brMyFile.Close();
fsMyFile.Close();
}

public static class Header
{
private static int _MyCode;
public static int MyCode
{
get { return _MyCode; }
set { _MyCode = value; }
}
}
}
}

========================

I want to be able to reference this dll to other projects and then use
it like...

MyClass someclass = new MyClass();
someclass.Open("[path to file]");

The difficulty with the following is that you're trying to use a static
class name as though it were a property name, and an instance property
at that. The first thing you have to decide is whether MyCode is an
instance-level thing (that is, there is one MyCode for each Header that
you create) or whether it's a static thing (that is, there is only one
MyCode in the entire program, no matter how many Headers or MyClasses
you instantiate). Once you have that sorted out, I can give you more
information on how to achieve what you want.

.



Relevant Pages

  • Re: Help With Nesting Classes In Library
    ... I have one main file that contains a header and several, ... MyClass someclass = new MyClass; ... public static int MyCode ... I want to be able to reference this dll to other projects and then use ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Help With Nesting Classes In Library
    ... There will be exactly one MyCode for the header. ... need to read a header from the binary file, and it will also need to ... is nested inside MyClass: you're just setting a static property of the ...
    (microsoft.public.dotnet.languages.csharp)
  • Help With Nesting Classes In Library
    ... I am writing a class that will do some binary file IO. ... need to read a header from the binary file, and it will also need to ... private BinaryReader brMyFile; ... public static int MyCode ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Mutli Type in same file
    ... then you can use a Random file and just offset ... by the number of records the header took up. ... header out to 1000 bytes and read that in via binary mode. ... using a binary file and your own read and write code is not ...
    (comp.lang.basic.visual.misc)
  • parse c c++ header to map binary block for display
    ... The program open the binary file, it casts it to the structure and it ... whenever the structure changes, i don't have to manually change my ... I thought of a parser for the C/C++ header to collect the available ...
    (comp.lang.perl.misc)

Loading