Do you know the answer to following question?
Let us say, it MyMethod() is declared as partial method in MyPartialClass in MyPartialClass.cs. I have also provided body of MyMethod() in MyPartialClass in MyPartialClass2.cs. I use a problem without answer“Magic” code generator which has actually generated MyPartialClass.cs, let us say based on some DB schema. Some innocent guy changes schema for good and then runs “Magic”. MyPartialClass.cs is re-generated but with MyMethod2() instead of MyMethod() declaration. Think of me. I am thinking that I have implemented MyMethod() which is used by “Magic” but in reality, “Magic” is using MyMethod2(). C# compiler does not tell me that I have partial method implemented without any declaration and my implementation is not used at all!
Any solution?
I think it is a problem without an answer.
EDIT I got an answer :-). I had a typo in my code and that is why compiler was not flagging error. Jon already has pointed that out.
You should get error CS0759. Test case:
partial class MyClass
{
partial void MyMethod()
{
Console.WriteLine("Ow");
}
}
partial class MyClass
{
partial void MyMethod2();
}
Compilation results:
Test.cs(6,18): error CS0759: No defining declaration found for implementing
declaration of partial method 'MyClass.MyMethod()'
Does that not do what you want it to?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With