G
greenxiar
Hi,
When i enumerate fields in class with reflection,
How to know if a field is marked as NonSerialized?
Type c2 = typeof(Class2);
foreach(FieldInfo m in c2.GetFields
(BindingFlags.NonPublic|
BindingFlags.Instance|
BindingFlags.GetField|
BindingFlags.SetField)) {
Console.WriteLine(m);
if (Attribute.IsDefined(m, typeof(NonSerializedAttribute)))
Console.WriteLine(": is NonSerialized Field!");
}
IsDefined, GetCustomAttributes, GetCustomAttribute seems can
not detect the NonSerializedAttribute!
Green Xiar
When i enumerate fields in class with reflection,
How to know if a field is marked as NonSerialized?
Type c2 = typeof(Class2);
foreach(FieldInfo m in c2.GetFields
(BindingFlags.NonPublic|
BindingFlags.Instance|
BindingFlags.GetField|
BindingFlags.SetField)) {
Console.WriteLine(m);
if (Attribute.IsDefined(m, typeof(NonSerializedAttribute)))
Console.WriteLine(": is NonSerialized Field!");
}
IsDefined, GetCustomAttributes, GetCustomAttribute seems can
not detect the NonSerializedAttribute!
Green Xiar