Can't reference classes within a class

R

Ray Stevens

I have a dataclass that was created by a code generator. A snippit of its
output is as follows:



namespace SoftwareAG.EntireX.NETWrapper.Generated.laf801n1.Groups

{

public class Laf801n1

{

public class Laa001a2

{

public string environment ;

public string sourceApp ;

}

public class Laf801a1

{

public string certnoSeq ;

public string lender ;

}

public class Laf801a2

{

public string respD ;

public string respT ;

public string custName ;

}

}

}



I would like to pass this as a reference. The following code snippet works:



using SoftwareAG.EntireX.NETWrapper.Generated.laf801n1.Groups;

using SoftwareAG.EntireX.NETWrapper.Generated.laf801n1;

namespace LATF.TSR.DAL

{

public class FldDAL : BaseDAL

{

public void PlaceFooOrder(ref Laf801n1.Laa001a2 hdr, ref
Laf801n1.Laf801a1 request, ref Laf801n1.Laf801a2 response)

{

Flddev txn = new Flddev();

txn.Laf801n1(ref hdr, ref request, ref response);

}

}



While this does not (in fact, it can't even be done. intellisense shows
things like Laf801n1.ToString(), etc.):



using SoftwareAG.EntireX.NETWrapper.Generated.laf801n1.Groups;

using SoftwareAG.EntireX.NETWrapper.Generated.laf801n1;

namespace LATF.TSR.DAL

{

public class FldDAL : BaseDAL

{

public void PlaceFooOrder(ref Laf801n1 etx)

{

Flddev txn = new Flddev();

txn.Laf801n1(ref etx.Laa001a2, ref etx.Laf801a1, ref
etx.Laf801a2); // This is what I would like to code.

}

}



Is what I am attempting doable?
 
A

agapeton

First off make sure your namesapces are PascalCased and that you aren't
exposing public fields. You need to be using properties. I can't
think of a code generator in the world that would break the .NET
framework coding rules like the above.

You are trying to send a class. You can't do that. You can send
objects. You probably want to do something like

Laf801n1.Laa001a2 something1 = new Laf801n1.Laa001a2( );
Laf801n1.Laf801a1 something2 = new Laf801n1.Laf801a1( );
Laf801n1.Laf801a2 something3 = new Laf801n1.Laf801a2( );

txn.Laf801n1(ref something , ref something2, ref something3);
 
G

Guest

Classes are Reference type structure, to pass instance of a class by
reference you don't need "ref" keyword. Have you tried by simply removing ref
keywords?
 
?

=?iso-8859-1?Q?Lasse=20V=e5gs=e6ther=20Karlsen?=

Nested class declarations is a namespace-like feature. It does not make one
class contain an instance of another.

Example:

public class Outer
{
public class Inner { }
}

in this case, if you construct an object from Outer, it does not automatically
contain a field or anything containing an instance of Inner.

You need something like:

public class Outer
{
public class Inner { }
public Inner InnerObject = new Inner();
}

then:

Outer o = new Outer();
o.InnerObject.XYZ...

"public class" and "public struct" only defines the type, it does not declare
an object or field.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top