partial class, derived from an interface, without implementation

meiru

New member
Joined
Dec 7, 2022
Messages
4
Programming Experience
10+
I have something like this

C#:
partial class X : Window, InterfaceY
{
    void abc()    // part of the InterfaceY
    {
    }
}

partial class X : Window, InterfaceY
{
    void something()
    {
        abc();
    }
}

and, the problem is, that the second partial class X throws a CS0535, saying, that I don't implement the function 'abc'.

How can I solve this? Or how can I call 'abc' from 'something'? (I cannot modify the first partial class, since this one is generated)
 
What happens if you remove the InterfaceY on line 8?
 
"How can I solve this?"

C#:
abstract partial class X : Window, InterfaceY
{
    void something()
    {
        abc();
    }

    abstract abc();
}
?


Edit: wait; you're complaining that you have both those classes and you're getting CS0535? Are they in different namespaces? Two partial classes in the same namespace, one that does impl an interface and one that does not, will not throw CS0535:

1670433166989.png


^^ no errors

You don't need to repeat yourself with the inherits:


1670433212353.png


But the fact you have makes me wonder if you've got something more like this:
1670433295274.png
 
Last edited:
I have something like this
ps; I dislike these hypotheticals; people always make some mistake in hacking out their hypothetical obscuring of their real code, which means the advice given doesn't always reflect reality and is either irrelevant or unable to be back translated to fix the actual problem. Consider posting actual verbatim code that exhibits the problem
 
I have to agree with cjard. It won't always be possible as some problems are too complex but, ideally, we should be able to copy and paste your code and see the issue for ourselves.
 
ok, thank you... I found the problem... after knowing for sure that it would work, if I really have 2 partial classes (what I learned from your answers) I was able to find out, that the generated file was either generated wrongly (1. option set) or built correctly but ignored during the build (2. option set)... I then found out, that this happened because of a strange behavior of the generator I used (a useless attribute had to be there in order to work correctly)
so... thanks for your help
 
Back
Top Bottom