2010-11-12 58 views

回答

1
 Type t = typeof(x) 
     for fields: 
     t.GetFields().Where(p=> !p.Attributes.HasFlag(FieldAttributes.NotSerialized)); 
     for type 
     t.Attributes.HasFlag(TypeAttributes.Serializable); 
1

你有没有试过?

o.GetType().FindInterfaces().Any(x => x == typeof(ISerializable)); 
+2

如果要检查执行的接口,不是吗更好地使用(o是ISerializable)而不是将Reflection拖拽到此? – 2010-11-12 09:50:02

5
typeof(MyClass).IsSerializable; 
2

因为你所要求的实例,而不是类,正确的答案居然是:

o.GetType().IsSerializable; 
相关问题