开发者

Script# and namespaces - compile errors

I am currently playing around with Script# (version 0.6.3) which complains about the following code:

Check that your C# source compiles and that you are not using an unsupported feature

[ProjectDir]\Space1\Bar.cs:

using Application1.Space2;

namespace Application1.Space1
{
    public sealed class Bar
    {
        private void Baz()
        {
            IFoo foo = null;
            foo.Do(); //Here
        }
    }
}

[ProjectDir]\Space2\IFoo.cs:

namespace Application1.Space2
{
    public interface IFoo
    {
        void Do();
    }
}

The code compiles without any error under the reg开发者_如何学运维ular csc.exe

What am I doing wrong?


I think it's a problem with the current version. If you move the class file to the root of the project does it work?

EDIT: Correction, it's due to a change in the current version. From @scriptsharp via twitter: "web app project produces multiple scripts (per folder). If you don't need that model, just use a class lib project. HTH." It didn't used to do that. Still doesn't exactly explain the reason it outputs that terrible error message. I kind of like that it's forcing you to separate application logic from the object model, but it would be nice if that change was documented somewhere obvious. I love SS and really hope to see it grow into a more seriously developed/supported application.


This error can happen if you use partial namespaces, e.g.:

using Application1;

namespace Application1.Space1
{
     public class Bar
     {
          public Space2.Foo GetFoo()
          {}
     }
}

The above will generate a compiler error, while:

using Application1;

namespace Application1.Space1
{
     public class Bar
     {
          public Application1.Space2.Foo GetFoo()
          {}
     }
}

Will compile without errors.

I've also had it happen with:

object.method().property.method();

Fixed with:

variable = object.method();
variable.property.method();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜