我该如何检查,如果一个类是只读在C#?我该

2023-09-04 06:51:33 作者:我老婆说夏天不许看美女

我可以写一个单元测试,确保只读类我写的(它没有制定者的一类)保持只读的未来?我不希望任何人在我的课添加setter属性。

Can I write a unit test that make sure that a readonly class I write (a class which has no setters) remains readonly in the future? I do not want that anyone to add a setter property in my classes.

基本上,我怎么检查,如果一个类是没有制定者在C#?

Basically, how do I check if a class is has no setters in C#?

推荐答案

注:提问者最初提出的问题?我如何确定一类是值类型后来又改变了它。的

bool isValueType = object.GetType().IsValueType

bool isValueType = typeof(YourClass).IsValueType

MSDN: http://msdn.microsoft.com/ EN-US /库/ system.type.isvaluetype.aspx