h5建站系统源码,可做外贸的网站有哪些,wordpress邮件系统,河南省住房和城乡建设厅门户网站背景
xml文件中有些元素的属性被删除#xff0c;导致文件无法被读取#xff08;C##xff09;。 调试之后发现#xff0c;因为属性被删除#xff0c;读进来会保持默认值null#xff0c;在后续的反射中如果用这个null给字符串属性赋值#xff0c;会抛异常。 另外发现前面…背景
xml文件中有些元素的属性被删除导致文件无法被读取C#。 调试之后发现因为属性被删除读进来会保持默认值null在后续的反射中如果用这个null给字符串属性赋值会抛异常。 另外发现前面还有其他一些属性也被删掉了但并不会导致异常只因它们的类型是int。
示例
using System.Reflection;
class Program
{public int A{set;get;}public string B{set;get;}static void Main(string[] args){Program program new Program();PropertyInfo pa program.GetType().GetProperty(A);pa.SetValue(program, null, null); // 正常PropertyInfo pb program.GetType().GetProperty(B);pb.SetValue(program, null, null); // 异常}
}