Adding an interface to a partial class

前端 未结 3 597
抹茶落季
抹茶落季 2020-12-31 08:05

I have a class that is generated by a third party tool:

public partial class CloudDataContext : DbContext 
{
    // ...SNIPPED... 
    public DbSet

        
相关标签:
3条回答
  • 2020-12-31 08:49

    Here's a quick checklist. Do the classes have identical:

    • Names?
    • Namespaces?
    • Access modifiers?

    Example:

    • You decide to split an existing class into two files.
    • The original file's namespace doesn't match its folder path.
    • Consequently, the new class file you create has a mismatching namespace.
    • Build fails.
    0 讨论(0)
  • 2020-12-31 08:49

    IN my Case problem was that interface Method that was implemented in other part of the partial class was not compiling and C# was giving error of not implemented Method

    0 讨论(0)
  • 2020-12-31 08:54

    The problem must be somewhere else, because you can implement interface in the other part of partial class then it's set on. I just tried following and it compiles just fine:

    public interface IFoo
    {
        int Bar { get; set; }
    }
    
    public partial class Foo
    {
        public int Bar { get; set; }
    }
    
    public partial class Foo : IFoo
    {
    
    }
    

    The properties probably use different types in interface and class.

    0 讨论(0)
提交回复
热议问题