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)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…