Trouble in c# land

Trouble in c# land

Old forum URL: forums.lhotka.net/forums/t/2657.aspx


JonM posted on Wednesday, April 04, 2007

Hey all.  I've been using the VB.net version of CSLA 1.5x.  Now I'm doing a new project with the C# version of CSLA 2.1.4.  However, being new to c# and the new version I'm having trouble. 

I created my first business class, a read-only list.  The class library with my one business object builds and compiles just fine.  However, I'm having trouble using it from my winforms app.  I've got both my class library and the CSLA.dll referenced.  I've got my app.config setup.  When I try to create a collection in c# I get the error "MyObject is inaccessible due to its protection level."  What the heck does that mean?  Below is the 2 lines of code I'm using to create an instance of my collection.  Any help would really be appreciated.

JobProfiles _jobprofiles;

_jobprofiles = JobProfiles.GetReadOnlyList();

ajj3085 replied on Wednesday, April 04, 2007

The problem is not in any of the code you have posted.

Basically MyObject exists, but its scoped at such a level that it can't be seen.  Here's a snippit that illistrats the problem.

namespace ConsoleApplication11 {

    public class MyClass {
        private string MyString;
    }

    public static class Program {
        static void Main() {
            MyClass myClass;
            myClass = new MyClass();

            Console.WriteLine( myClass.MyString ); // this will generate the error
        }
    }
}

JonM replied on Wednesday, April 04, 2007

Okay, that makes sense to me.  I generated my read-only list object from the templates included with the c# download of csla.net.  How should I have my class scoped so I can use it?  This class is very simple, should I post the code?

ajj3085 replied on Wednesday, April 04, 2007

Jon,

The scoping rules for C# are the same as those for VB.Net.  The only difference I'm aware of is that in VB you have Friend, which translates to internal for C#.

So scope them as you would if you were doing this in Vb.net.

Also, the templates seem to be intended for you to modify to your specific needs before you use them, so taking them as is and generating your classes may not be a good way to start.

JonM replied on Wednesday, April 04, 2007

Okay.  Well apparently if you don't specify a scope in c# it is private (or internal).  I was only able to get to work by specifiying public, specifying internal gave me the same error.  Anyway, it works as public, thanks a lot for the help.  Apparently I need to buy a c# reference book.

ajj3085 replied on Wednesday, April 04, 2007

Yes, I should have mentioned that.. but isn't that how VB.net works too?  Or is it public by default?

Bayu replied on Thursday, April 05, 2007

ajj3085:
Yes, I should have mentioned that.. but isn't that how VB.net works too?  Or is it public by default?


Haha,

VB.Net is a mature language, especially since the 2005 version. Nevertheless, it has it roots in VB6 and before where all you did was programming in routines and modules (no class inheritance supported).

So,  you bet the default is public!

;-p

Bayu

NinjaPenguin replied on Thursday, April 05, 2007

Hi ,

There is a book "C# & vb.net Conversion pocket reference" by O'Reilly, which as a long time VB guy, I have found useful for those anoying issues when converting sample code from one language to the other which would of helped you in this case. It lists all the equivalents between the languages and then all the language specific quirks and how to deal with them when converting code.

You may also like to try one of the various C# / VB.Net language converters that are on the web for free (just Google it).

I hope that is of some help to you for any future language issues.

Regards,

Simon Geering

Skafa replied on Thursday, April 05, 2007

To name just one:

http://converter.telerik.com/

I haven't used it, but stated by some bloggers, it appears to do a good job.

JonM replied on Sunday, April 08, 2007

It is up and running now.  Thanks for all your help.  I already have the OReilly conversion book.  I just need to read it more closely.

Copyright (c) Marimer LLC