- 浏览: 399619 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
Guide lines to make a immutable C# classes.
the article is based on the post here: http://stackoverflow.com/questions/352471/how-do-i-create-an-immutable-class
You cannot asssume that the C# language allows you to change the semantic of the assignment oprator, if is to copy the reference on the reference types, and to memberwise copy on the struct types.
To make a class immutable in C#, you basically have to following the rules as follows.
I think you're on the right track -
- all information injected into the class should be supplied in the constructor
- all properties should be getters only
- if a collection (or Array) is passed into the constructor, it should be copied to keep the caller from modifying it later
- if you're going to return your collection, either return a copy or a read-only version (for example, using ArrayList.ReadOnly or similar - you can combine this with the previous point and store a read-only copy to be returned when callers access it), return an enumerator, or use some other method/property that allows read-only access into the collection
- keep in mind that you still may have the appearance of a mutable class if any of your members are mutable - if this is the case, you should copy away whatever state you will want to retain and avoid returning entire mutable objects, unless you copy them before giving them back to the caller - another option is to return only immutable "sections" of the mutable object - thanks to @Brian Rasmussen for encouraging me to expand this point
发表评论
-
wpf - example to enhance ComboBox for AutoComplete
2014-09-19 15:56 1976first let’s see an example ... -
Investigate and troubleshoot possible memory leak issue of .NET application
2014-07-31 10:42 0Hi All, I would like to sh ... -
C# – CoerceValueCallback合并、替换元数据值
2013-08-05 21:59 1925Topic: C# – CoerceValueCallbac ... -
wpf – ListView交替背景色
2013-07-02 20:56 6551Wpf – Alternate background col ... -
C# - 简单介绍TaskScheduler
2013-06-29 17:18 12038标题: C# - 简单介绍TaskSchedulerTit ... -
c# - Get enum from enum attribute
2013-06-27 21:32 1244DescriptionAttribute gives the ... -
C# - PInvoke, gotchas on the RegisterClassEx and the CreateWindowEx
2013-06-24 13:49 2571I get an exception message li ... -
c# - Use PInvoke to create simple win32 Application
2013-06-24 11:59 10946In this post, .net platform h ... -
c# - Linq's Select method as the Map function
2013-06-19 18:47 1287If you comes from a functiona ... -
c# - Tips of Linq expression Any to determine if a collection is Empty
2013-06-19 18:29 938When you are @ the linq expres ... -
myth buster - typeof accepting array of types not acceptable
2013-06-19 17:17 813I have seen from some book whe ... -
windows - trying to create WIN32 application with PInvoke
2013-06-19 14:34 0While it is stupid to do such ... -
WPF - Setting foreground color of Entire window
2013-06-13 16:00 1918You might as well as I would s ... -
WPF - Enhanced TabControl - TabControlEx aka Prerendering TabControl
2013-06-13 13:12 5330As an opening word, let's che ... -
wpf - ControlTemplate and AddLogicChild/RemoveLogicalChild
2013-06-10 15:42 1185Recently I was trying to debug ... -
c# - P/Invoke, DllImport, Marshal Structures and Type conversions
2013-06-05 15:25 1712P/Invoke as in the following q ... -
c# - A study on the NativeWindow - encapsulate window handle and procedure
2013-06-05 14:40 6091NativeWindow gives you a way t ... -
WCF - Notify server when client connects
2013-06-03 18:19 1221It is sometimes very importan ... -
wcf - Debug to enable Server exception in Fault message
2013-06-03 15:47 1091WCF will be able to send back ... -
c# - determine if a type/object is serialzable
2013-05-30 16:35 867In WCF, primitives type are s ...
相关推荐
A simple, unified fingerprint authentication library for Android with RxJava extensions. Eliminates the need to deal with the different available Fingerprint APIs, including Imprint and Samsung Pass....
Processing of signals is often facilitated by transforming to a representation in which individual components are statistically independent. In such a natural coordinate system, the components of the ...
reprint 是一个适用于 Python 2/3 的简易变量绑定与多行输出刷新的库
本资源"reprint-0.3.0.tar.gz"就是从PyPI官网获取的一个Python库——`reprint`的特定版本,版本号为0.3.0。 `reprint`库主要解决的是在Python程序中动态更新控制台输出的问题。在开发过程中,我们有时需要实时显示...
Gartner在2018年发布的研究笔记中,特别提到了应用安全测试(AST)市场的现状和发展趋势。研究笔记的标题为“应用安全测试市场的魔法象限”,它由分析师Ayal Tirosh、Dionisio Zumerle和Mark Horvath撰写,涉及...
reprint 使用说明 直接从datasource,dbgrid,stringgrid导入数据, 只需简单设置,不用手工制作,即可生成您需要的报表,具有预览功能。即可自定义纸张,又可适应 打印机默认纸张。各种打印设置,功能更强大。 ...
reprint 使用说明 本人长期使用delphi做数据库的开发,报表控件使用Quickrpt,在打印上经常遇到一些问题,于是自己经常编写一部分打印的程序,经过总结开发了这个控件。 本控件可打印 datasource,dbgrid,...
reprint是一个Python 2/3模块,用于绑定变量并刷新终端中的多行输出。 用于计算Unicode字符宽度的解决方案来自 特征 Python 2/3支持 简单的变量绑定和变量更改后自动刷新命令行 同时多行刷新,每行绑定到不同的...
不推荐使用请改用 ,它支持... 在您的Application.onCreate ,使用Reprint.initialize(this)初始化Reprint。 这将加载棉花糖模块和Spass模块(如果包含)。 然后,在代码中的任何位置,都可以调用Reprint.authenticate
是检测估计和调制理论的经典著作,最新版,2013版,英文原版,Highly readable paperback reprint of one of the great time-tested classics in the field of signal processing Together with the reprint of Part ...
I am pleased that Springer-Verlag has decided to reprint this book, givingme the opportunity to include a number of corrections. The changes in this printing are mainly limited to the correction of...
标题中的“Gartner Reprint_APM_英文原版”指的是由知名市场研究机构Gartner发布的关于应用性能监控的报告原文版。Gartner是一家全球领先的信息技术和市场研究公司,其报告对业界具有广泛的影响力。 描述中提到的...
- 书中所提到的DOI编号(10.1007/978-3-662-05086-6)和ISBN编号(978-3-642-07698-5、978-3-662-05086-6)是电子书的电子检索和购买的唯一标识,用户可以通过这些编号在出版社网站或其他电子书销售平台上找到并购买...
reprint 使用说明 本控件可打印 datasource,dbgrid,stringgrid. 一 、控件属性: 1、colstitle 设置报表的列标题属性 (1) Print:boolean;;是否打印 (2) Font:tfont;;字体 (3) Rowsline:tpen;;横线...
重印 描述 按照字母顺序,由Aidan Guarniere,Cassandra Hurlbut,Jonathan Wilferd和翁飞凤撰写。 不可替代令牌(NFT)可以是数字文件,例如图片,动画,音频或视频,但它们不可互换,因为它们是由区块链技术制成的...
Free-Reprint-Articles.com - **平台特点**:允许再版的文章,可以提高文章的传播范围。 - **应用**:适合希望增加文章曝光率的作者。 #### 18. Favouritearticles.com - **平台特点**:可能侧重于精选优质文章。 ...
具有带通选择性的ICA算法可以改善对于带通时间序列的分离以及对于周期性脑功能响应信号的提取. 因此本文提出的方案可将被估计信号, 如:周期性响应信号以及具有平滑空间分布的脑功能激活区, 的先验特性以特征选择的...
在安卓平台上,指纹识别技术为用户提供了安全便捷的身份验证方式,极大地增强了应用的安全性和用户体验。本文将深入探讨如何在Android应用程序中实现指纹识别功能,基于提供的"安卓指纹识别模块",我们将详细介绍...