Forums

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

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

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

Postby gauthier » Fri Dec 19, 2008 1:26 am

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?
Last edited by gauthier on Sat Dec 20, 2008 6:10 pm, edited 1 time in total.
gauthier
 
Posts: 116

Re: const members: how to access them

Postby Charles » Fri Dec 19, 2008 6:02 am

Looks like a bug to me. Will fix soon. The temporary workaround expression would be:
sharp'Foo.Bar.Baz' to int
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: const members: how to access them

Postby Charles » Sat Dec 20, 2008 1:30 am

What did you intend as the difference between ConstHolder and StaticConstHolder other than the name? They seem to hold the same thing.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: const members: how to access them

Postby Charles » Sat Dec 20, 2008 2:23 am

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.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: const members: how to access them

Postby gauthier » Sat Dec 20, 2008 3:13 am

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).
gauthier
 
Posts: 116


Return to Discussion

Who is online

Users browsing this forum: No registered users and 11 guests