Можно ли реализовать интерфейс на классе Linq2Sql?

Можно всегда писать части приложения в Python. Не каждый компонент одинаково важен для производительности. Python интегрируется легко с C++ исходно, или с Java через Jython, или с.NET через IronPython.

Между прочим, IronPython более эффективен, чем реализация C Python на некоторых сравнительных тестах.

8
задан mattruma 22 October 2009 в 18:58
поделиться

1 ответ

LinqToSQL classes are partial classes, so you can have an additional file that implements the interface for the LinqToSQL class.

Just add this to a new file, using the same class name as your LinqToSQL class:

public partial class LinqToSqlClass : IFoo {
    public void Foo() {
        // implementation
    }
}

If your LinqToSQL class already implements the necessary proporties you should be able to only include the interface declaration.

To answer the comment about using a differently-named LinqToSQL property to implement the interface, you can use the syntax above and just call the LinqToSQL property from the interface property, or to keep things a bit cleaner, use explicit implementation:

public partial class LinqToSqlClass : IFoo {
    void IFoo.Foo() {
        return this.LinqFoo(); // assumes LinqFoo is in the linq to sql mapping
    }
}

By using this syntax, clients accessing your class will not see a redundant property used only for implementing an interface (it will be invisible unless the object is cast to that interface)

13
ответ дан 5 December 2019 в 12:59
поделиться
Другие вопросы по тегам:

Похожие вопросы: