我有一个无法解释的情况。请查看以下代码,并注意变量 c 和 d 的定义及其奇怪的值。 c 等于
null
,但 d 不是。鉴于我百分之百确定以下几点,这肯定是不可能的(对吧?):
- a.value是一个字段,而不是属性
- 类型限定符是封闭的引用类型,具有基础类型对象
- 应用程序仅为单线程。
- 我已经执行过“清理解决方案”。
private static object CreateConstraints(CompositeElement constraintsElement)
{
Contract.Requires(constraintsElement != null);
var constraintTypes = from e in constraintsElement where e.DefinitionName.IsAnyOf("ConstraintType", "ConstraintTypeNamePrependedWithComma") select (Qualifier)e.Value;
var declarer = (MemberDeclaration)constraintsElement.Parent.Value;
GenericTypeParameterCollection genericTypeParameters = declarer.Name.Suffixes.OfType<GenericTypeParameterCollection>().First();
Element a = constraintsElement["TypeName"];
a.SetValue();
var c = a.value as Qualifier;
var d = a.value as Qualifier;
genericTypeParameters.First(gp => gp.Type == c).Constraints.AddRange(constraintTypes);
return null;
}
我还制作了两次运行的反汇编 截图。个人认为我不确定它们是否有误。
因此,我想问一下是否我漏掉了什么可以使这种行为完全正常,或者这里真的有一些非常奇怪的东西?
ReferenceEquals(gp.Type, c)
或者ReferenceEquals(gp.Type, d)
替换gp.Type == c
实际上在本地窗口中并没有改变任何内容... - JBSnorro