修复C#中的反编译程序错误

时间:2016-10-23 00:55:05

标签: c# decompiling

当我尝试在Visual Studio中构建程序时,我在第17行得到错误CS1908(公共SpellScore(字符串尝试,字符串[]目标,...)当我在0周围添加引号时,我得到相同的错误我也试过null。有关编译器如何搞砸了/正确版本应该是什么的任何想法?

public class SpellScore
{
    private double MinimumPercent;
    private string mvarAttempt;
    private long mvarAttrib;
    private bool mvarIsCorrect;
    private double mvarResult;
    private SpellingLevels mvarSpellingLevel;
    private string mvarTarget;

    public SpellScore(string Attempt, string[] Target, [Optional, DefaultParameterValue(0)] SpellingLevels Level)
    {
        this.mvarIsCorrect = false;
        int upperBound = Target.GetUpperBound(0);
         for (int i = Target.GetLowerBound(0); i <= upperBound; i++)
        {
            if (this.Correct(Attempt, Target[i], Level))
            {
                this.mvarIsCorrect = true;
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

反编译器向您展示了当方法具有可选参数时包含的编译器生成的属性。对于按原样编译的代码,您需要确保引用了声明这些属性的程序集,并包含using指令以将其命名空间置于范围内。

但实际上,您应该编辑反编译代码,使其看起来像普通的C#代码,如下所示:

public SpellScore(string Attempt,
    string[] Target, SpellingLevels Level = (SpellingLevels)0)

根据您显示的代码,SpellingLevels似乎是enum类型。如果没有好的Minimal, Complete, and Verifiable code example,就不可能知道。

更好的是,假设它是enum类型,请找出0的{​​{1}}值,并使用命名值而不是SpellingLevels

相关问题