Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / December 2006

Tip: Looking for answers? Try searching our database.

Can't access public member from C# (works in VB, C++/CLI)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
wpcmame - 27 Dec 2006 08:42 GMT
I got the following code

public ref class A {
 value struct PrivateType sealed { Int32 id; };
public:
 ref struct B abstract sealed {
   static const PrivateType x = {1};
   static const PrivateType y = {2};
 };
 A() { }
 property PrivateType P { void set(PrivateType p) { mt = p; } }
private:
 PrivateType mt;
};

The assmbly compiles fine with a warning about B:x & B:y using a private
type but that is what I want. (I want to ensure that only the constants
within the class are used with the property P and I don't want to use an enum)

It also works fine to use the assembly from VB
Dim x As New A()
x.P = A.B.x

and C++/CLI
A^ x = gcnew A();
x->P = A::B::x;

But not from C#
A x = new A();
x.P = A.B.x;

error: A.P is inaccessible due to its protection level.
error: A.B.x is inaccessible due to its protection level.

Also got strange warnings from FxCop
- A+B.x  Non-constant fields should not be visible
Static fields should be constant

isn't that what "static const" means?

When looking at the type PrivateType in FxCop it says IsUnmanaged=True

MSIL says:
set_P: public hidebysig specialname instance void
A:B:x: public static valuetype Test.A/PrivateType
modopt([mscorlib]System.Runtime.CompilerServices.IsConst)
Ben Voigt - 27 Dec 2006 20:14 GMT
>I got the following code
>
[quoted text clipped - 36 lines]
>
> isn't that what "static const" means?

No, C++/CLI has a keyword literal which is the same as C# const.  C++/CLI
const is meaningless to the CLR, it marks it with an attribute which is only
understood by the C++/CLI compiler.

> When looking at the type PrivateType in FxCop it says IsUnmanaged=True
>
> MSIL says:
> set_P: public hidebysig specialname instance void
> A:B:x: public static valuetype Test.A/PrivateType
> modopt([mscorlib]System.Runtime.CompilerServices.IsConst)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.