Page 1 of 1

[solved - ticket:101] const members: how to access them

PostPosted: Fri Dec 19, 2008 1:26 am
by gauthier
with such cobra

use System.Net
class Test
def main is shared
print ConstHolder.Foo.bar
print ConstHolder.FooFoo.baz
print StaticConstHolder.Foo.bar
print StaticConstHolder.FooFoo.baz


and such c#

Code: Select all
public class ConstHolder {
   public static class Foo {
      public const string Bar = "ConstHolder.Foo.Bar";
   }
   public class FooFoo{
      public const string Baz = "ConstHolder.FooFoo.Baz";
   }
}
public class StaticConstHolder{
   public static class Foo {
      public const string Bar = "StaticConstHolder.Foo.Bar";
   }
   public class FooFoo {
      public const string Baz = "StaticConstHolder.FooFoo.Baz";
   }
}


compiler give

Code: Select all
error: Cannot access instance member "Foo" on type "ConstHolder". Make the member "shared" or create an instance of the type.
error: Cannot access instance member "FooFoo" on type "ConstHolder". Make the member "shared" or create an instance of the type.
error: Cannot access instance member "Foo" on type "StaticConstHolder". Make the member "shared" or create an instance of the type.
error: Cannot access instance member "FooFoo" on type "StaticConstHolder". Make the member "shared" or create an instance of the type.


it seems const string member are seen as instance instead of const.

How can I access const string members from c# libraries?

Re: const members: how to access them

PostPosted: Fri Dec 19, 2008 6:02 am
by Charles
Looks like a bug to me. Will fix soon. The temporary workaround expression would be:
sharp'Foo.Bar.Baz' to int

Re: const members: how to access them

PostPosted: Sat Dec 20, 2008 1:30 am
by Charles
What did you intend as the difference between ConstHolder and StaticConstHolder other than the name? They seem to hold the same thing.

Re: const members: how to access them

PostPosted: Sat Dec 20, 2008 2:23 am
by Charles
Fixed, tested and checked in.

The real bug was that Cobra would not access nested types due to the false error you received. The .NET standard library doesn't have many nested types that you directly use (they recommend against such a style and mostly follow that recommendation in their own libraries), so this problem hadn't been found before.

Re: const members: how to access them

PostPosted: Sat Dec 20, 2008 3:13 am
by gauthier
Chuck wrote:What did you intend as the difference between ConstHolder and StaticConstHolder other than the name? They seem to hold the same thing.


I've missed the static class modifier for the StaticConstHolder class

Chuck wrote:Fixed, tested and checked in.

The real bug was that Cobra would not access nested types due to the false error you received. The .NET standard library doesn't have many nested types that you directly use (they recommend against such a style and mostly follow that recommendation in their own libraries), so this problem hadn't been found before.


Thanks, there is such things in the System.Net (ftp).