小寒的blog
Programming is a darned hard thing—but I am going to like it.

随笔分类 -  c#

1 2 下一页
元数据编程实战_使用Emit运行时生成Protobuf编码类
摘要:protobuf是google的一种序列化对象的编码方式。相比xml和json的序列化方式,protobuf序列化的结果更小,而且序列化的速度也更快。本文简单介绍写如果通过Emit来在运行时动态的生成对数据对象的protebuf编码解码类。 通过本实例展示下元数据编程的能力。关于protebuf的编码原理可以参考这里http://code.google.com/intl/zh-CN/apis/protocolbuffers/docs/encoding.html ,本文只展示对简单的int32进行varint方式编码和string的编码,。在此基础上可以很容易的实现全部的protobuf的编码. 阅读全文
posted @ 2011-04-03 01:16 xhan 阅读(2235) 评论(3) 推荐(5)
发布个c#版的HandlerSocket客户端类库
摘要:HandlerSocket 是一个mysql 数据库的插件,它可以绕过mysql的查询分析和优化的过程,直接与innodb存储引擎进行交互。尤其是当大多数数据都被innodb缓存到内存中的时候,查询分析和优化过程就会是整个查询处理过程的瓶颈。通过使用HandlerSocket可以绕过这个瓶颈,从而提升性能。这要比mysql+memched要有优势,因为HandlerSocket不需要处理缓存失效的问题。下面看下HsClient访问mysql的一个例子代码1usingSystem;2usingSystem.Collections.Generic;3usingSystem.Linq;4usingS 阅读全文
posted @ 2011-03-24 18:22 xhan 阅读(2639) 评论(1) 推荐(1)
在c#中运行js脚本
摘要:1 . 新建文本JSCaller.js内容如下class JSCaller { function Eval(expression: String) {return eval(expression, "unsafe");} } 2. 打开.net的命令行窗口。运行jsc /t:library C:\JSCaller .js 得到JSCaller.dll3.在c#项目中引用JSCaller.dll 和... 阅读全文
posted @ 2010-10-22 09:22 xhan 阅读(6386) 评论(1) 推荐(0)
CallContext在多线程传递试验分析
摘要:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Runtime.Re... 阅读全文
posted @ 2010-07-09 00:47 xhan 阅读(819) 评论(0) 推荐(0)
使用代理拦截方法调用例子
摘要:从essential .net 第七章抄过来的使用代理拦截方法调用的例子。PriorityProxy用来在方法调用前后提升和回复线程的优先级代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--usingSystem;usingSystem.Collec... 阅读全文
posted @ 2010-07-01 11:02 xhan 阅读(441) 评论(0) 推荐(0)
Expression动态生成方法例子
摘要:实现和上个用DynamicMethod的方式生成的复制实体类对应一样功能代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--publicstaticclassExpMapper<TTarget,TSource>{privatestaticM... 阅读全文
posted @ 2010-06-05 19:31 xhan 阅读(940) 评论(0) 推荐(0)
DynamicMethod应用例子实现实体类的对应属性的复制
摘要:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Reflection... 阅读全文
posted @ 2010-06-04 15:54 xhan 阅读(962) 评论(6) 推荐(0)
c#4.0泛型接口和泛型委托的协变和逆变
摘要:先看个例子,此代码在c# 4.0下可以编译通过,因为c#4.0才开始支持逆变和协变代码 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--usingSystem;usingSystem.Collections.Generic;usingSystem.Li... 阅读全文
posted @ 2010-06-01 11:21 xhan 阅读(552) 评论(0) 推荐(0)
Exploring the System.Reflection.Emit Namespace(翻译)
摘要:System.Reflection.Emit命名空间提供了创建动态程序集的能力,动态程序集就是指在运行时创建的程序集。动态程序集能够被运行或者保存到磁盘上。处于这个原因,许多的.net编译器使用了 System.Reflection.Emit来提供代码生成。在这片文章中,我们将探索下System.Reflection.Emit命名空间,并构建一个简单的类库程序集System.Reflection.... 阅读全文
posted @ 2010-03-15 21:01 xhan 阅读(1050) 评论(3) 推荐(1)
如何序列化MailMessage对象
摘要:[代码]Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Net.Mail;usingSystem.Xml;... 阅读全文
posted @ 2010-01-12 17:08 xhan 阅读(730) 评论(0) 推荐(0)
10进制转26进制作为Excel列名
摘要:[代码] 阅读全文
posted @ 2009-12-29 18:16 xhan 阅读(593) 评论(0) 推荐(0)
在Ibatis.net中使用泛型映射
摘要:在Ibatis.net中parameterMap和resultMap中class属于用于指定要映射到的类型。由于泛型中包含<>所以会破坏xml文档格式。必须使用另一种表达方式来代替<>。比如class="System.Collections.Generic.Dictionary`2[[System.String],[System.Object]] 就相当于System.Co... 阅读全文
posted @ 2009-08-19 13:48 xhan 阅读(854) 评论(0) 推荐(0)
throw; 还是throw e
摘要:如果捕获到一个异常,到底是如何重新抛出。catch (Exception e) { throw; } 还是 catch (Exception e) { throw e; }throw;会保留原始的异常栈信息。这样方便调试很容易找到出错的行号throw e 会虽然异常信息都保留了,但是会修改异常堆栈信息,throw e那个行就会成为出错的行.而不是你try里面调用的代码时候实际的出错行了。so,一般... 阅读全文
posted @ 2009-07-29 10:37 xhan 阅读(1600) 评论(1) 推荐(0)
通过反射访问对象私有和保护成员
摘要:[代码] 阅读全文
posted @ 2009-07-15 13:07 xhan 阅读(612) 评论(0) 推荐(0)
File.ReadAllText方法,File.WriteAllText方法修改文件内容
摘要:File.ReadAllText (String) 打开一个文本文件,读取文件的所有行,然后关闭该文件。 File.ReadAllText (String, Encoding) ... 阅读全文
posted @ 2008-01-04 10:10 xhan 阅读(1768) 评论(0) 推荐(0)
异步编程概述<转>
摘要:NET Framework 允许您异步调用任何方法。定义与您需要调用的方法具有相同签名的委托;公共语言运行库将自动为该委托定义具有适当签名的 BeginInvoke 和 EndInvoke 方法。 BeginInvoke 方法用于启动异步调用。它与您需要异步执行的方法具有相同的参数,只不过还有两个额外的参数(将在稍后描述)。BeginInvoke 立即返回,不等待异步调用完成。BeginInvok... 阅读全文
posted @ 2008-01-04 09:44 xhan 阅读(318) 评论(0) 推荐(0)
使用NUnit进行DotNet程序测试<转>
摘要:使用NUnit进行DotNet程序测试 作者:kongxx 介绍 NUnit是目前比较流行的.Net平台的测试工具,以下就简单介绍一下他的开发。 准备 要使用NUnit,首先要确保您的机器上有NUnit的开发包,您可以从http://www.nunit.org/ 地方获取并安装(目前版本是NUnit v2.1.91)。正确安装后会在开始菜单下添加一个NUnit 2.2项目。 属性说明 在开始写例... 阅读全文
posted @ 2007-12-20 11:30 xhan 阅读(475) 评论(0) 推荐(0)
Effective C# 学习笔记 1
摘要:条款一:使用属性代替可访问的数据成员 1、在C#中属性(property)在访问时候看起来是数据成员,但却是用方法实现的!可以对set访问器做参数检查!可以对属性访问添加多线程支持! public class Person { private string name; public string Name { get { ... 阅读全文
posted @ 2007-08-28 09:18 xhan 阅读(290) 评论(0) 推荐(0)
通过代理为对象添加功能
摘要:using System; using System.Threading; using System.Runtime.Remoting.Proxies; using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting; namespace ConsoleApplication1 { public interfac... 阅读全文
posted @ 2007-08-27 11:55 xhan 阅读(381) 评论(1) 推荐(0)
摘要:类是 C# 中功能最为强大的数据类型。像结构一样,类也定义了数据类型的数据和行为。然后,程序员可以创建作为此类的实例的对象。与结构不同,类支持继承,而继承是面向对象编程的基础部分。有关更多信息,请参见继承。 声明类 类是使用 class 关键字来定义的,如下面的示例所示: public class Customer{ //Fields, properties, methods and ev... 阅读全文
posted @ 2007-06-10 20:20 xhan 阅读(328) 评论(0) 推荐(0)

1 2 下一页