2008年7月29日

假设你有一个类型SomeImplementation,它显示的实现了ISomeInterface接口的方法SomeMethod(),那么如何才能取到这个SomeImplementation.SomeMethod()的MethodInfo呢? 

一些程序员使用下面的方法来获取MethodInfo:  

MethodInfo mi = typeof(SomeImplementation).GetMethod(
    
"VBLib.ISomeInterface.SomeMethod"
    BindingFlags.Instance 
| BindingFlags.NonPublic | BindingFlags.Public);

但是有些时候这样做是错误的,它并不能取得方法的MethodInfo。原因是上面代码使用的私有方法的名字是编译器在编译代码时使用的实现细节。C#语言开发的代码可以使用这种方法获取到,但如果是其它语言(如,VB.NET)就不一定能成功了。 

试一下对下面的代码,在C#中使用上面的代码看是否能取到MethodInfo。 

Public Interface ISomeInterface
    
Function SomeMethod() As String
End Interface

Public Class SomeImplementation
    
Implements ISomeInterface

    
Private Function SomeMethod() As String Implements ISomeInterface.SomeMethod
        
Return "hello"
    
End Function
End Class

你会发现对于上面用VB.NET开发的代码,你无法使用前面的代码取到MethodInfo. 

正确的方法

下面是取得MethodInfo的正确方法:  

MethodInfo imi = typeof(ISomeInterface).GetMethod("SomeMethod");
InterfaceMapping map 
= typeof(SomeImplementation).GetInterfaceMap(
    
typeof(ISomeInterface));
int index = Array.IndexOf(map.InterfaceMethods, imi);
MethodInfo result 
= map.TargetMethods[index];


posted @ 2008-07-29 20:55 Easy Company 阅读(1024) 评论(0) 编辑

2008年6月17日

在迁移至SQL Server 2008之前了解那些反对和放弃的功能的具体情况非常重要。

以下是几个主要功能在兼容性上的问题列表:
  1. SQL Server Database Engine Backward Compatibility
  2. SQL Server Analysis Services Backward Compatibility
  3. Integration Services Backward Compatibility
  4. Reporting Services Backward Compatibility
  5. Replication Backward Compatibility
  6. Full-Text Search Backward Compatibility
升级前使用Upgrade Advisor to Prepare工具可以分析当前SQL Server的安装情况,可以生成一个提示升级前后需要修补的问题的报表。




posted @ 2008-06-17 14:28 Easy Company 阅读(420) 评论(0) 编辑

2008年6月12日

Colin Mackay讲述mock的论文 中列出了一些常见的使用mock的场景: K Scott AllenMocks - It's A Question Of When 认为,即使是上面列表中的内容也稍显肤浅,从更深刻、更普遍的意义而言,应该是”在你想把被测试的代码分离的时候,martin fowlertest doubles[mocks]就显出了作用。“简而言之,按照Allen的观点,用了mock对象,业务组件的测试代码就可以不依赖其它组件了;试举一例来看,A依赖于B,但A的单元测试只会因为A的问题而出现问题,跟B的状态无干。

"Mock Roles, Not Objects" 的作者们写到,mock技术:
"……在基于对象角色构建的系统中,可以识别出各种角色类型……尤其是,我们已经知道了Mock Object可以为我们带来的最大好处——曾被称为接口识别的概念"。



posted @ 2008-06-12 10:39 Easy Company 阅读(199) 评论(0) 编辑

2008年5月24日

最近Michael C. Kennedy在它的博客上写了一些关于.Net 2.0 SP1中ThreadPool的文章。

.NET 3.5 Brings Breaking Changes to ThreadPool中他介绍了一个对他影响很大的变化,新的.NET 2.0 SP1(随.NET 3.5 发布)忽略了ThreadPool.SetMinThreads导致他的程序停止运行。如果你的应用需要立即使用大量的线程池线程时,你必须通过ThreadPool.SetMinThreads提高最小线程数量,否则ThreadPool会尽快在线程池中分配最少数量的线程,接着每秒钟创建最多2个线程,直到达到最大线程数量的方法启动线程,它可能需要几秒钟才能完成。在文章中Michael给出了100个线程的测试示例,并在2008年2月26日提供了视频和相应的新的测试代码

另外Michael发现当太多线程等待其他任务结束时就会出现死锁,他通过向Vance Morrison(a .NET Runtime Performance Architect at Microsoft)确认那是一个Bug,他们将在.Net 2.0 SP2中修复。并且Vance给了Michael一个解决这个问题的策略,如下:

Take this "broken" code:
private static void UseThreadPool(int count)
        
{
            
for ( int i = 0; i < count; i++ )
            
{
                ThreadPool.QueueUserWorkItem(
                    
delegate { SlowMethod(); } );
            }

        }
And add a strategic Thread.Sleep and it's fixed:
        private static void UseThreadPool(int count)
        
{
            
for ( int i = 0; i < count; i++ )
            
{
                ThreadPool.QueueUserWorkItem(
                    
delegate { SlowMethod(); } );
                Thread.Sleep(
1);
            }

        }




posted @ 2008-05-24 12:03 Easy Company 阅读(517) 评论(0) 编辑

2008年4月26日

今天试着将Team Foundation Server 2008装在Windows Server 2008 Enterprise RTM上。在TFS 2008 进行“系统状况检查”时失败,提示SQL全文搜索服务未安装。因为SQL全文搜索已经无缝集成到了SQL Server 2008 CTP February 2008的数据库引擎中,所以在我安装了带有全文搜索功能的SQL Server 2008 CTP February 2008后,在Windows服务列表中也是找不到SQL Server FullText Search服务的。为了解决这个问题我在网上开始查找解决方案,最后在这里找到了。呵呵,很不幸,目前TFS 2008还无法和SQL 2008一起工作。

解决办法有两个:
1、等到TFS 2008 SP1发布后再装
2、使用SQL Server 2005

呵呵,我选择了后者。希望对大家有帮助,毕竟装Team Foundation Server是很耗时的事儿。


下面是Team Foundation Server 2008系统检测的结果:

The System Health Check has detected a problem that will cause Setup to fail. 

Description
The SQL Full Text Search service is not installed.

Workaround / Remedy
The SQL Full Text Search service is not installed. To install this service, you must run Microsoft SQL Server setup and install this component.

More information
For additional information and help please refer to:
http://go.microsoft.com/fwlink/?LinkId=79226

The System Health Check has detected a problem that will cause Setup to fail. 

Description
The SQL Full Text Search service is stopped.

Workaround / Remedy
The SQL Full Text Search service is in a stopped state. In Control Panel, double-click Administrative Tools, double-click Services, and then look for the service. If the service is not running, start it by right-clicking the service and then clicking Start.

More information
For additional information and help please refer to:
http://go.microsoft.com/fwlink/?LinkId=79226  

The System Health Check has detected a problem that will cause Setup to fail. 

Description
The SQL Full Text Search service is not configured to start automatically.

Workaround / Remedy
The SQL Full Text Search service is not configured to start automatically when the computer starts. In Control Panel, double-click Administrative Tools, double-click Services, and then look for the service. Double-click the service to view the service properties. In the Startup type list, click Automatic, and then click OK.

More information
For additional information and help please refer to:
http://go.microsoft.com/fwlink/?LinkId=79226





posted @ 2008-04-26 21:20 Easy Company 阅读(366) 评论(0) 编辑

2008年2月18日

posted @ 2008-02-18 12:28 Easy Company 阅读(416) 评论(2) 编辑

2008年1月24日

posted @ 2008-01-24 16:09 Easy Company 阅读(151) 评论(0) 编辑

2007年12月27日

摘要: 今天读了 Steve Yegge的Code's Worst Enemy 触动了我,将自己的看法也记录下来。 Steve Yegge 说“......I believe, quite staunchly I might add, that the worst thing that can happen to a code base is size.”。 我觉得庞大的代码库是极...阅读全文
posted @ 2007-12-27 14:24 Easy Company 阅读(110) 评论(0) 编辑

2007年11月7日

摘要: 好久没有写东西了,今天将以前给同事写的一段代码改了一下共享出来。这段代码用于实现在点击按钮后禁用它直到操作完成。有更好的方法大家可以讨论!Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><%@PageLanguage="C#"%><!...阅读全文
posted @ 2007-11-07 11:35 Easy Company 阅读(429) 评论(0) 编辑

2007年9月21日

摘要: ASP.NET 2.0 中增加了一个 IButtonControl 接口(Button、ImageButton、LinkButton控件实现了此接口),在这个接口中定义了一个 PostBackUrl 属性,使用这个属性可以实现在用户点击按钮时将页面的内容回发到另外一个页面。并且在另一个页面中可以使用 Page.PreviousPage 属性获取到前一个页面的实例,通过 PreviousPage.F...阅读全文
posted @ 2007-09-21 17:20 Easy Company 阅读(1108) 评论(0) 编辑
仅列出标题  下一页

导航

公告