【问题标题】:MVC Model: The left hand side of an assignment must be a variable, property or indexerMVC 模型:赋值的左侧必须是变量、属性或索引器
【发布时间】:2016-05-09 21:00:37
【问题描述】:

我有一个我继承的应用程序,但没有原始代码。我已经使用 Reflector 9 对程序集进行了反编译,其中一个生成的模型被标题中的错误所困扰。通常这种错误很简单,但这次却让我感到莫名其妙。完整代码如下,错误在于包含

的行
  (((nullable2 = this.Variations) = nullable2.HasValue 

Variations 是在代码后面 10 行定义的属性

  public decimal? Variations { get; set; }

函数的完整代码是:

 public decimal GMActual
    {
        get
        {
            decimal? nullable2;
            decimal? nullable3;
            decimal? pOValue = this.POValue;
            if ((pOValue.HasValue ? pOValue.GetValueOrDefault() : (((nullable2 = this.Variations) = nullable2.HasValue ? new decimal?(nullable2.GetValueOrDefault()) : ((decimal?) (nullable3 = null))).HasValue ? nullable2.GetValueOrDefault() : 0M)) == 0M)
            {
                return 0M;
            }
            pOValue = this.POValue;
            pOValue = this.MonthActual;
            pOValue = this.POValue;
            return (((pOValue.HasValue ? pOValue.GetValueOrDefault() : (((nullable2 = this.Variations) = nullable2.HasValue ? new decimal?(nullable2.GetValueOrDefault()) : ((decimal?) (nullable3 = null))).HasValue ? nullable2.GetValueOrDefault() : 0M)) - (pOValue.HasValue ? pOValue.GetValueOrDefault() : (((nullable2 = this.CostOnSage) = nullable2.HasValue ? new decimal?(nullable2.GetValueOrDefault()) : ((decimal?) (nullable3 = null))).HasValue ? nullable2.GetValueOrDefault() : 0M))) / (pOValue.HasValue ? pOValue.GetValueOrDefault() : (((nullable2 = this.Variations) = nullable2.HasValue ? new decimal?(nullable2.GetValueOrDefault()) : null).HasValue ? nullable2.GetValueOrDefault() : 0M)));
        }
    }

据我所知。我将小数分配给小数。这是一个简单的值分配,但是,我错过了什么?

感谢您的任何建议

【问题讨论】:

  • 使用== 运算符进行比较,使用= 进行赋值
  • 有两行包含(((nullable2 = this.Variations) = nullable2.HasValue。错误是在if 还是return 行?
  • 两行都有。
  • 代码被混淆了:尝试减少它:f.e. 'nullable3' 始终为 null,因此 ' ((decimal?) (nullable3 = null))).HasValue' 为 false...
  • 我确实尝试减少它,但它导致变量未定义变量的错误。这是一个奇怪的结果,因为我可以想象如果牙套有问题会出现这种情况。但情况似乎并非如此,因为没有其他属性或方法受到影响,所以我回到原来的错误

标签: c# variables variable-assignment


【解决方案1】:

你想用代码实现什么?

您的意思是检查是否相等?如果是这样,则需要在您的 return 语句中的所有出现中将 = 替换为 ==。

【讨论】:

    【解决方案2】:

    这对我来说没有任何意义:(((nullable2 = this.Variations) = nullable2.HasValue,从我在这里可以看到,这是 if 语句的条件部分。我猜你想要做的是更像这样的事情:

    nullable2 = this.Variations
    nullable2.HasValue ? ... //and the rest of the statement
    

    或者您是否要检查它是否不为空且等于变体?那么这应该工作:

    (nullable2 != null && nullable2 == this.Variations) ? ...//the rest of the statement.
    

    【讨论】:

      【解决方案3】:

      反编译器接缝弄乱了代码 - 尝试另一个检查。您还想知道什么是您“修复”是正确的?

      PS:你是想盗取那个代码吗?它被混淆了:原始程序员接缝不希望您看到该代码;)。

      【讨论】:

      • 哈哈,那个人离开了大楼(大约 2 年前,拿走了所有的代码,也许吧?我们不知道。剩下的只是一堆已编译的二进制文件,用于加载网络应用程序...)没有文档没有同事在公司新手我...我尝试过 ilspy、telerik 和最后的 Reflector。不涉及代码窃取,但总是对更好的方法持开放态度:)
      猜你喜欢
      • 1970-01-01
      • 2015-07-07
      • 2017-05-28
      • 2018-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      • 2012-07-06
      相关资源
      最近更新 更多