我该如何检查,如果一个类是只读在C#? [英] How do I check if a class is readonly in c#?

查看:83
本文介绍了我该如何检查,如果一个类是只读在C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以写一个单元测试,确保只读类我写的(它没有制定者的一类)保持只读的未来?我不希望任何人在我的课添加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

这篇关于我该如何检查,如果一个类是只读在C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆