是否有过一个理由使用goto语句在现代.NET code?有过、语句、理由、现代

2023-09-02 01:46:01 作者:漫长的岁月很漫长

我刚刚发现这个code反射器在.NET基础库...

I just found this code in reflector in the .NET base libraries...

    if (this._PasswordStrengthRegularExpression != null)
    {
        this._PasswordStrengthRegularExpression = this._PasswordStrengthRegularExpression.Trim();
        if (this._PasswordStrengthRegularExpression.Length == 0)
        {
            goto Label_016C;
        }
        try
        {
            new Regex(this._PasswordStrengthRegularExpression);
            goto Label_016C;
        }
        catch (ArgumentException exception)
        {
            throw new ProviderException(exception.Message, exception);
        }
    }
    this._PasswordStrengthRegularExpression = string.Empty;
Label_016C:
    ... //Other stuff

我听说过所有的不可恐惧流亡使用GOTO地狱永恒高谈阔论的。我始终认为MS codeRS在相当高的方面,虽然我可能不同意他们所有的决定,我一直尊重他们的推理。

I've heard all of the "thou shalt not use goto on fear of exile to hell for eternity" spiel. I always held MS coders in fairly high regard and while I may not have agreed with all of their decisions, I always respected their reasoning.

所以 - 是有一个很好的理由,code这样说我失踪?是这样的code提取物只是放在一起由一个不称职的开发者?或者是.NET反射回来不准确的code?

So - is there a good reason for code like this that I'm missing? Was this code extract just put together by an inept developer? or is .NET reflector returning inaccurate code?

我希望有是的一个很好的理由,而我只是一味地失踪了。

I'm hoping there is a good reason, and I'm just blindly missing it.

感谢大家的输入

推荐答案

反射器是不完美的。这种方法的实际code可从参考源。它位于NDP FX的 src XSP 系统网络安全 admembershipprovider.cs:

Reflector is not perfect. The actual code of this method is available from the Reference Source. It is located in ndpfxsrcxspsystemwebsecurityadmembershipprovider.cs:

        if( passwordStrengthRegularExpression != null )
        { 
            passwordStrengthRegularExpression = passwordStrengthRegularExpression.Trim();
            if( passwordStrengthRegularExpression.Length != 0 ) 
            { 
                try
                { 
                    Regex regex = new Regex( passwordStrengthRegularExpression );
                }
                catch( ArgumentException e )
                { 
                    throw new ProviderException( e.Message, e );
                } 
            } 
        }
        else 
        {
            passwordStrengthRegularExpression = string.Empty;
        }

请注意它是如何未能检测到最后的else子句以及它与一个goto补偿。这几乎是肯定绊倒-了由try / catch块的if()语句中。

Note how it failed to detect the last else clause and compensated for it with a goto. It is almost certainly tripped-up by the try/catch blocks inside the if() statements.

显然,你会想,以有利于实际源$ C ​​$ C,而不是反编译的版本。在自己的评论是非常有益的,可以被准确的来源计数。好了,主要是准确的,有从车的后处理工具,它删除了微软的程序员的名字了一些轻微损坏。标识符有时会被破折号更换,code重复两次。你可以在这里下载源。

Clearly you'll want to favor the actual source code instead of the decompiled version. The comments in themselves are quite helpful and you can count on the source being accurate. Well, mostly accurate, there's some minor damage from a buggy post-processing tool that removed the names of the Microsoft programmers. Identifiers are sometimes replaced by dashes and the code is repeated twice. You can download the source here.

 
精彩推荐
图片推荐