gpt4 book ai didi

c# - 部分方法 C# 3.0 的问题

转载 作者:行者123 更新时间:2023-11-30 19:34:58 24 4
gpt4 key购买 nike

你知道下面问题的答案吗?

Let us say, it MyMethod() is declaredas partial method in MyPartialClass inMyPartialClass.cs. I have alsoprovided body of MyMethod() inMyPartialClass in MyPartialClass2.cs.I use a problem without answer“Magic”code generator which has actuallygenerated MyPartialClass.cs, let ussay based on some DB schema. Someinnocent guy changes schema for goodand then runs “Magic”.MyPartialClass.cs is re-generated butwith MyMethod2() instead of MyMethod()declaration. Think of me. I amthinking that I have implementedMyMethod() which is used by “Magic”but in reality, “Magic” is usingMyMethod2(). C# compiler does not tellme that I have partial methodimplemented without any declarationand my implementation is not used atall!

Any solution?

我认为这是一个没有答案的问题。

编辑 我得到了答案:-)。我的代码中有一个拼写错误,这就是编译器没有标记错误的原因。乔恩已经指出了这一点。

最佳答案

您应该收到错误 CS0759。测试用例:

partial class MyClass
{
partial void MyMethod()
{
Console.WriteLine("Ow");
}
}

partial class MyClass
{
partial void MyMethod2();
}

编译结果:

Test.cs(6,18): error CS0759: No defining declaration found for implementing 
declaration of partial method 'MyClass.MyMethod()'

这不是您想要的吗?

关于c# - 部分方法 C# 3.0 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/738580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com