草庐IT

false_type

全部标签

c# - 通用扩展方法 : Type argument cannot be inferred from the usage

我正在尝试创建一个适用于类型化数据表的通用扩展方法:publicstaticclassExtensions{publicstaticTableTypeDoSomething(thisTableTypetable,paramExpression>[]predicates)whereTableType:TypedTableBasewhereRowType:DataRow{//dosomethingtoeachrowofthetablewheretherowmatchesthepredicatesreturntable;}[STAThread]publicstaticvoidmain(){M

c# - PrincipalContext.ValidateCredentials 总是返回 FALSE

我有一个MVC应用程序需要根据ActiveDirectory登录和验证用户。我正在使用PrincipalContext.ValidateCredentials方法,但始终获得false的身份验证。连接到服务器没问题。问题似乎出现在ValidateCredentials中。这是我的代码:publicstaticboolIsAuthenticated(stringdomain,stringusername,stringpwd){boolIsAuthenticated=false;try{PrincipalContextinsPrincipalContext=newPrincipalCont

c# - int.TryParse() 为 "#.##"返回 false

我有一个接收字符串参数并将它们转换为整数的函数。为了安全转换,使用了int.TryParse()。publicIEnumerableReportView(stringparam1,stringparam2){intstoreId=int.TryParse(param1,outstoreId)?storeId:0;inttitleId=int.TryParse(param2,outtitleId)?titleId:0;IEnumerabledetailView=newReport().GetData(storeId,titleId);returndetailView;}函数调用Repor

c# - "Possible multiple enumeration of IEnumerable"与 "Parameter can be declared with base type"

在Resharper5中,以下代码导致list出现警告“Parametercanbedeclaredwithbasetype”:publicvoidDoSomething(Listlist){if(list.Any()){//...}foreach(variteminlist){//...}}在Resharper6中,情况并非如此。但是,如果我将方法更改为以下内容,我仍然会收到该警告:publicvoidDoSomething(Listlist){foreach(variteminlist){//...}}原因是,在这个版本中,list只枚举一次,所以改成IEnumerable不会自动

c# - 为什么 Double.TryParse() 对于包含 double.MaxValue 或 double.MinValue 的字符串返回 false?

我有一个静态方法,它接受一个字符串作为输入,如果该字符串代表一个数字,则返回原始输入字符串。如果字符串不代表数字,则处理输入字符串并返回转换后的字符串。我在写测试用例。我正在尝试验证包含double.MinValue或double.MaxValue的输入字符串是否原样返回。我已经阅读了许多论坛,包括StackOverflow,并提出了以下逻辑:stringdoubleMax=double.MaxValue.ToString();doubled;CultureInfocultureInfo=newCultureInfo("en-US",true);if(Double.TryParse(d

c# - 当路径太长时,File.Exists() 错误地返回 false

我目前正在开发一个遍历各种目录的程序,以确保使用File.Exists()存在特定文件。应用程序一直声称某些文件不存在,而实际存在,我最近发现这个错误是由于路径太长造成的。我知道有一些关于SO的问题可以解决File.Exists()返回不正确的值,但似乎没有一个可以解决这个特定问题。重命名目录和文件以缩短路径并不是一个真正的选择,所以我现在不确定该怎么做。是否有解决此问题的变通方法?正在使用的代码没什么特别的(我删除了一些不相关的代码),但我会在下面包含它以防万一。privatevoidcheckFile(stringpath){if(!File.Exists(path))Consol

c# - 如何解决 '...is a ' type', which is not valid in the given context'? (C#)

以下代码会产生错误:Error:'CERas.CERAS'isa'type',whichisnotvalidinthegivencontext为什么会出现这个错误?usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceWinApp_WMI2{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){

c# - 没有无参数构造函数的类型的 Activator.CreateInstance(Type)

这个问题在这里已经有了答案:CreatinginstanceoftypewithoutdefaultconstructorinC#usingreflection(4个答案)关闭9年前。阅读工作中的现有代码,我想知道这怎么能行得通。我在程序集中定义了一个类:[Serializable]publicclassA{privatereadonlystring_name;privateA(stringname){_name=name;}}在另一个程序集中:publicvoidf(Typet){objecto=Activator.CreateInstance(t);}和那个简单的调用f(typeo

c# - 如何解决错误 :the type does not appear to implement microsoft. practices.servicelocation.iservicelocator?

我是MVC的新手,我正在关注“AdamFreeman的PROASP.NETMVC4”。我目前正在研究它的第6章。我正在学习如何使用MVC4中的Ninject进行依赖注入(inject)。我已经按照书中的描述创建了应用程序。现在我不明白为什么会出现以下错误:该类型似乎没有实现microsoft.practices.servicelocation.iservicelocator这是我的Controller代码:publicclassHomeController:Controller{privateProduct[]products={newProduct{Name="Kayak",Cate

c# - 错误 : Cannot implicitly convert type 'void' to 'System.Collections.Generic.List'

我正在尝试使用该控件从.ascx设置我的.ascx控件的属性。所以在我的一个包含此控件的.aspx中,我有以下代码试图设置我的嵌入式.ascx的ItemsList属性:Itemitem=GetItem(itemID);myUsercontrol.ItemList=newList().Add(item);我尝试设置的.ascx中的属性如下所示:publicListItemsList{get{returnthis.itemsList;}set{this.itemsList=value;}}错误:无法将类型“void”隐式转换为“System.Collections.Generic.List