gpt4 book ai didi

c# - 陷入无限循环,遍历 C# 类中的属性

转载 作者:行者123 更新时间:2023-11-30 22:15:50 26 4
gpt4 key购买 nike

<分区>

我正在循环访问 C# 类的属性,以将值与另一个实例进行比较。这个概念看起来很简单,并且适用于我正在尝试做的事情。但是,我的 foreach 循环永远不会停止。它只是继续循环遍历类并导致 StackOverflowException。我对此不知所措。任何帮助将不胜感激!

public static Object ORIGINALRECORD { get; set; }

protected String DirtySets()
{
String sDirtySets = "";

foreach (PropertyInfo property in this.GetType().GetProperties(BindingFlags.Public|BindingFlags.Instance))
{
if (ORIGINALRECORD.GetType() == this.GetType())
{
System.Diagnostics.Debug.WriteLine(property.Name);
object originalValue = ORIGINALRECORD.GetType().GetProperty(property.Name).GetValue(ORIGINALRECORD, null);
object newValue = property.GetValue(this, null);
if (!object.Equals(originalValue, newValue))
{
sDirtySets = (sDirtySets == "" ? "" : sDirtySets + ",") + property.Name + "=?";
}
}
}

return "SET "+sDirtySets;
}

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