随笔分类 - Code Snippets
摘要:Code Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->using System; class FlagsAttributeDemo { // Define an Enum without FlagsAttribute. enum ...
阅读全文
摘要:if (!Enum.IsDefined(typeof(SearchMode), options)) throw new ArgumentException(Properties.Resources.InvalidEnumerationValue, "options"); 如果数据库中存储的值,在程序里用枚举表示,在做parse的时候可以使用这样的方法监测options的值。
阅读全文
摘要:1: public bool Exists(Predicate predicate) 2: { 3: bool returnValue = false; 4: 5: Each(delegate(VALUE value) { returnValue |= predicate(value); }); 6:...
阅读全文
摘要:在Microsoft.Practices.ObjectBuilder2中的StagedStrategyChain类中只用的下面的方法来获取枚举里元素的个数: 1: private static int NumberOfEnumValues() 2: { 3: return typeof(TStageEnum).GetFields(BindingFlags.Public ...
阅读全文
摘要:虽然复杂,但是考虑到业务逻辑的需要,这套Lock方案还是相当不错的: 1: CacheItem cacheItemBeforeLock = null; 2: bool lockWasSuccessful = false; 3: 4: do 5: { 6: lock (inMemoryCache.SyncRoot) 7: { 8: ...
阅读全文