草庐IT

this_and_that

全部标签

c# - 通过反射调用 this[int index]

我尝试为MicrosoftOffice实现一个基于反射的后期绑定(bind)库。OfficeCOM对象的属性和方法调用方式如下:Typetype=Type.GetTypeFromProgID("Word.Application");objectcomObject=Activator.CreateInstance(type);type.InvokeMember(,,null,comObject,newobject[]{});InvokeMember是唯一可能的方法,因为Type.GetMethod/GetProperty无法正确处理COM对象。可以使用InvokeMember调用方法和属

c# - 为什么 Visual Studio IDE 有时会初始化“this.components 对象 : and other times not?

我最近注意到VisualStudioDesigner(C#)的一些我不理解的行为,想知道是否有人可以澄清...在我的一些Windows窗体中,设计器生成的代码的第一行是这样的;this.components=newSystem.ComponentModel.Container();在这种情况下,dispose方法在同一个设计器文件中,dispose方法在case“if”条件下放置两个“Dispose”调用,如下所示;protectedoverridevoidDispose(booldisposing){if(disposing&&(components!=null)){componen

c# - 错误 : ExecuteReader requires an open and available Connection. 连接的当前状态为打开

我有下面带有DataHelperClass的mvc4网站来执行查询。我的问题有时是,网站以异常为标题。我使用block来处理SqlCommand和SqlDataAdapter但没有成功。请帮助我,对不起我的英语。try{if(_conn.State==ConnectionState.Closed)_conn.Open();using(SqlCommandsqlCommand=newSqlCommand(query,_conn)){sqlCommand.CommandType=CommandType.StoredProcedure;if(parameters!=null)sqlComma

c# - 统一: Change default lifetime manager for implicit registrations and/or disable them

Unity容器将自动解析它可以自行识别的任何类型,无需手动注册。这在某些方面很好,但我遇到的问题是它使用TransientLifetimeManager来解决这种类型的问题,而我几乎总是想要一个ContainerControlledLifetimeManager。当然,我仍然可以手动将我的类型注册为单例,但如果我忘记了,应用程序将成功启动,而不是在启动时出现未处理的异常,并且一切似乎都正常工作。但最终会出现错误,可能非常微妙,难以诊断,因为存在一个类型的多个实例,这意味着是一个单例。所以我的问题是:有没有一种方法可以指定不同的默认生命周期管理器或完全禁用默认的自动解析行为并将容器限制为

c# - IoC/DI 框架与智能客户端 Winform 应用程序 : How should I approach this?

我正在启动一个新的Winforms应用程序,我打算使用IoC/DI框架(可能是Ninject,但我也在考虑StructureMap和LinFu)。似乎几乎所有使用IoC/DI的人都是在基于Web的环境中这样做,并且几乎没有发现任何与它一起使用Winforms的东西。我想知道是否有人在Winforms中使用IoC/DI以及您使用什么方法来处理Winforms相关问题(例如,您如何使容器在应用程序的各个部分可用,您是否使用实例化表单等的框架。)如果有人知道任何使用IoC/DI的基于Winforms的开源项目(无论哪个框架,我都应该能够翻译概念)我也想要这些链接。编辑:人们不再编写智能客户端

c# - "Both use the XML type name X, use XML attributes to specify a unique XML name and/or namespace for the type"怎么解决?

我有以下枚举定义...namespaceItemTable{publicenumDisplayMode{Tiles,Default}}namespaceEffectiveItemPermissionTable{publicenumDisplayMode{Tree,FullPaths}}...然后我有以下类(class)...publicclassTablewhereTDisplayMode:struct{//publicpublicTDisplayModeDisplayMode{get{returnmDisplayMode;}set{mDisplayMode=value;}}//pri

c# - 类型 'TestClassAttribute' 存在于 'Microsoft.VisualStudio.QualityTools.UnitTestFramework and ' Microsoft.VisualStudio.TestPlatform.TestFramework

更新测试项目NuGet后出现此错误:Thetype'TestClassAttribute'existsinboth'Microsoft.VisualStudio.QualityTools.UnitTestFramework,Version=10.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a'and'Microsoft.VisualStudio.TestPlatform.TestFramework,Version=14.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a'

c# - GetMonthName : Valid values are between 1 and 13, 包括在内。为什么?

我不小心将0传递给DateTimeFormatInfo的GetMonthName方法:DateTimeFormatInfoinfo=newDateTimeFormatInfo();varmonthName=info.GetMonthName(0);并得到一个System.ArgumentOutOfRangeException错误消息:有效值在1到13之间,包括在内。传入1到12将返回“January”到“December”,但传入13将返回一个空字符串。我明白为什么月份数字不是零索引的,但是第13个月是做什么用的? 最佳答案 这是因

c# - 使用 "Expression Bodied Functions and Properties"有什么好处

这个问题在这里已经有了答案:Expression-bodiedfunctionmembersefficiencyandperformanceinC#6.0(2个答案)关闭6年前。我确实看到很多人使用该新功能,但使用这些表达式有什么好处?Examples:publicoverridestringToString()=>string.Format("{0},{1}",First,Second);publicstringText=>string.Format("{0}:{1}-{2}({3})",TimeStamp,Process,Config,User);这个问题不同于thisone,因为

c# - IDisposable GC.SuppressFinalize(this) 位置

我为我的代码使用默认的IDisposable实现模板(模式)。片段:publicvoidDispose(){Dispose(true);GC.SuppressFinalize(this);}protectedvirtualvoidDispose(boolisDisposing){if(!this.disposed){if(isDisposing){//cleanupmanagedresources}//cleanupunmanagedresourcesthis.disposed=true;}}我的问题:为什么在Dispose公共(public)方法中调用“GC.SuppressFina