
.Net
ISaiSai
这个作者很懒,什么都没留下…
展开
-
System.Web.Routing 3.5 MatchContentPathSegment BUG
requestPathSegment.LastIndexOf(subsegment5.Literal, length - 1, StringComparison.OrdinalIgnoreCase);length 可能为0 导致错误========== 错误信息 ========== 索引超出范围。必须为非负值并小于集合大小。参数名: startIndex原创 2012-07-03 16:12:35 · 683 阅读 · 0 评论 -
C# 结构Struct可以继承接口Interface
public struct MyS : IStruct { public void SayHello() { Console.WriteLine("Hello"); } } public interface IStruct原创 2013-01-23 15:13:37 · 5960 阅读 · 0 评论 -
C# 自定义数据类型
由于需要一个大于64位的数据类型(ulong),因此需要自己写一个数据类型存储大约600位的数据,并能够按位与 按位或主要用到的技术:1.操作符重载operator & ,operator |2.自定义的强制转换 implicit operatorusing System;using System.Collections.Generic;us原创 2013-01-23 17:06:04 · 6717 阅读 · 0 评论 -
C# struct构造函数限制
1.struct结构不能包含显示的无参构造函数2.struct有参数构造函数必须为所有属性赋值 public struct MyTest { // 不能有显示的无参构造函数 public MyTest() { } public s原创 2013-01-23 15:25:20 · 11427 阅读 · 1 评论 -
linq 的Order 与 sql 的orderby 的优先级
sql 的 order by 优先级谁在前面 按照谁排序select 2 as A,3as B Union allselect 2 ,4Union allselect 1 ,4 Union allselect 1 ,3 order by a ,b 结果1 31 42 32 4lin原创 2013-01-12 15:35:56 · 1066 阅读 · 0 评论 -
C# 删除文件夹中特定前缀文件
// 找到特定前缀的文件 var files = new DirectoryInfo(filePath).GetFiles(newFilePrefix + "*");// 判断是否只读 并删除 foreach (var fileInfo in files) { if (fileI原创 2013-01-16 10:49:22 · 1838 阅读 · 0 评论 -
Lambada表达式本质就是匿名代理
static void Main(string[] args) { SayHello(p => Console.WriteLine(p.UserName), () => new TicketResponse { UserName = "myTicket" }); SayHello(p => Console.WriteLine(p原创 2013-03-11 13:56:01 · 790 阅读 · 0 评论 -
Linq concat 连接两个List
http://www.dotnetperls.com/list-concat连接两个List需要使用ToList方法将concat 的结果转化为List using System;using System.Collections.Generic;using System.Linq;class Program{ static void Main() {转载 2013-03-15 11:14:35 · 8903 阅读 · 0 评论 -
单元测试DeploymentItem 无效的解决办法
需要将Local.testsettings启用部署勾选上,并且始终复制该文件在解决方案资源管理器的“解决方案项”之下双击要编辑的运行配置文件。随即出现一个对话框,它具有诸如“.testrunconfig”之类的名称。单击“部署”。在“要部署的其他文件或目录”下,指定要复制的其他文件或文件夹。要执行此操作,请单击“添加文件”选择原创 2013-03-22 14:39:40 · 1873 阅读 · 0 评论 -
C# 代理 delegate +=的本质
C# 代理或事件中会使用到+=方法注册事件,通过IL查看其本质是使用了System.Delegate.Combine方法SayDele += new SaySomeDele(SayhelloMethod); SayDele += new SaySomeDele(sayFuckMethod);//SayDele = (SaySomeDele)System.Delegate.Combine原创 2013-07-10 17:35:35 · 6541 阅读 · 0 评论 -
Visual Studio 2012 如何打开MVC1.0 MVC2.0的项目
http://stackoverflow.com/questions/13424079/how-do-i-open-an-mvc-2-project-in-visual-studio-2012直接使用Visual Studio 2012 无法打开MVC1.0 及MVC2.0的项目,需要手工编辑网站项目文件,删除.csproj文件中 ProjectTypeGuids 字段中的第一个点如下:删转载 2013-09-30 15:01:49 · 3804 阅读 · 0 评论 -
C# 非网站项目使用URLDecode及URLEncode
Uri.UnescapeDataString(s);在System 命名空间中,不需要额外的Dll引用转载 2013-11-21 13:44:48 · 4651 阅读 · 0 评论 -
c#不修改Host文件,指定IP地址
当负载均衡中一个域名对应有多台服务器,需要轮询所有服务器时候,一个方法是修改 Host文件,但不方便,网上找到了一个简单的方法,不需要修改本地Host文件,使用HttpWebRequest 的Proxy属性WebRequest req = WebRequest.Create("http://www.test.com"); req.Proxy原创 2013-11-28 09:27:54 · 4439 阅读 · 0 评论 -
Moq是最流行的mock框架
在实践单元测试的人之中,大约75%(占所有回应者的60%)使用某种模拟框架(mocking framework)。Moq是最流行的选择,占据70%的份额转载 2012-12-21 17:46:45 · 1474 阅读 · 0 评论 -
AssemblyInfo.cs 文件的 InternalsVisibleTo 使得其它DLL文件可见internal 类
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(" ")]原创 2012-12-21 10:26:31 · 978 阅读 · 0 评论 -
BuildManager.CreateInstanceFromVirtualPath调用aspx 页面嵌入方法
var a = BuildManager.CreateInstanceFromVirtualPath("/BB.aspx", typeof(Page)); var t = a.GetType(); var m = t.GetMethod("SayHello", BindingFlags.Public | BindingFlags.Stat原创 2012-08-09 16:00:46 · 1719 阅读 · 0 评论 -
C#双问号运算符
int? ii = 1;int z = ii ?? 0;双问号??会被翻译为 ?:运算符 int z = CS$0$0000..HasValue { ... }CTRL+Click to open in new tab.">HasValue ? CS$0$0000..GetValueOrDefault();CTRL+Click to open in new tab.">GetVal原创 2012-08-21 15:05:19 · 2121 阅读 · 0 评论 -
#pragma warning disable/restore 警告号码的查找,在输出中可以看到
编译完成 -- 0 个错误,2 个警告 警告 CS0618:原创 2012-08-21 15:15:39 · 1292 阅读 · 0 评论 -
debug 为true 导致 executionTimeout 无效
The ScriptTimeout property can be set in the Web.config file by setting the executionTimeout attribute of the httpRuntime element. Setting the time-out programmatically with the ScriptTimeout proper原创 2012-09-12 15:47:23 · 2584 阅读 · 0 评论 -
.net 单元从测试 Ignore 忽略特定测试
设置为ignore 则单元测试不运行这应该用于在运行一组测试时暂时排除其中的特定测试。 如果由于代码中存在错误,某个测试使其他测试无法运行,则可以使用它来阻止该测试的运行。 因为测试仍在编译,所以与注释掉代码相比,这种方法更好。它将测试的“已启用测试”属性设置为 false。可以在测试类或方法上指定此属性。 一个方法或类上只能有此属性的一个实例。http://t原创 2012-09-14 10:09:02 · 971 阅读 · 0 评论 -
mvc 1.0 SourceCode 源代码 调试
操作步骤参见http://www.appetere.com/Blogs/SteveM/January-2010/How-to-debug-ASP-NET-MVC-using-source-code1.下载源代码 http://www.microsoft.com/en-us/download/details.aspx?id=53882.修改引用 publickeyt转载 2012-12-05 18:19:30 · 381 阅读 · 0 评论 -
IList NotSupportedException IsReadOnly:是否只读
在 .NET Framework 2.0 版中,Array 类实现 System.Collections.Generic.IList、System.Collections.Generic.ICollection 和System.Collections.Generic.IEnumerable 泛型接口。由于实现是在运行时提供给数组的,因而对于文档生成工具不可见。因此,泛型接口不会出现在Arr原创 2012-12-24 17:44:53 · 668 阅读 · 0 评论 -
Console.Read() 的 Snippet
经常用到Console.Read() 于是写了一个Snippet 命令为crdcrdcrdConsole.Read 的代码段Microsoft CorporationExpansionSystemConsoleSimpleTypeName(global::System.Console)原创 2012-12-13 10:03:34 · 365 阅读 · 0 评论 -
指定CVS 文件的格式 Schema.ini
[需要指定的文件名csv] ColNameHeader=True Col1="列名称" Text Text 指定这一列是数字类型型在做单元测试时候DeploymentItem 数据源为CVS,如不指定列类型可能有问题创建Schema.ini 后 testContextInstance.DataRow 则返回字符串类型参考文档http://m原创 2012-12-14 15:39:58 · 1493 阅读 · 0 评论 -
EntityFrame 超时时间设置 ObjectContext.CommandTimeout
超时时间分为两种1.连接超时 :通过连接字符串中的 Connection Timeout=999 设置 999秒 (默认15秒)2.执行超时 : ObjectContext.CommandTimeout= 999 设置执行时间最长999秒(默认可能是数据库执行超时 默认超时由基础连接提供程序定义)当执行非常耗时的SQL 时候,很好用参考文件:http://te转载 2012-12-28 10:55:13 · 3941 阅读 · 0 评论 -
深拷贝、浅拷贝、ICloneable接口
使用微软企业库缓存,发现串缓存情况因此需要封装一层,进行深拷贝之后再用,防止一个地方不小心修改了缓存的内容,其它地方受到影响所有Model 继承ICloneable实现深度拷贝 public object Clone { MemoryStream stream = new MemoryStream(); Binar原创 2012-12-31 09:45:12 · 726 阅读 · 0 评论 -
lucence .net 3.0 测试分词的方法
Analyzer aStandardAnalyzer = new CJKAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT); TokenStream ts = aStandardAnalyzer.TokenStream("", new System.IO.StringReader("密云的门票"));原创 2013-11-14 16:15:18 · 904 阅读 · 0 评论