草庐IT

type_of_amount

全部标签

c# - 如何使用局部变量作为类型?编译器说 "it is a variable but is used like a type"

在运行时,我不知道什么类型的变量v1是。为此,我写了很多ifelse声明:if(v1isShellProperty){v2=(v1asShellProperty).Value;}elseif(v1isShellProperty){v2=(v1asShellProperty).Value;}elseif(v1isShellProperty){v2=(v1asShellProperty).Value;}elseif(v1isShellProperty){v2=(v1asShellProperty).Value;}唯一的区别在于ShellProperty.所以不要用很多ifelse来写这篇文

c# - PropertyInfo 实例上的 SetValue 错误 "Object does not match target type"c#

在以前的项目中的不同地方使用了带有这段代码的Copy方法(处理具有相同命名属性但不派生自公共(public)基类或实现公共(public)接口(interface)的对象)。新的工作地点,新的代码库-现在即使在非常简单的示例中,它也会在SetValue处失败并显示“对象与目标类型不匹配”......并且它在上周工作......publicstaticvoidCopy(objectfromObj,objecttoObj){TypefromObjectType=fromObj.GetType();TypetoObjectType=toObj.GetType();foreach(System

c# - 设置 ViewStateUserKey 给我一个 "Validation of viewstate MAC failed"错误

我的BasePage类中有以下内容,我的所有ASPX页面都派生自该类:protectedoverridevoidOnInit(EventArgse){base.OnInit(e);ViewStateUserKey=Session.SessionID;}我还在Web.config中设置了一个machineKey。我不认为这个错误是由网络场引起的,因为这也发生在我的开发机器上。我的主机现已升级到.NET3.5SP1。此次更新后,每次我使用上面的ViewStateUserKey设置进行编译时,我都会在每次回发时不断收到“ValidationofviewstateMACfailed”错误。我在

c# - "Could not find a part of the path"错误信息

我正在用C#编程,想从闪存盘复制一个文件夹和子文件夹以启动。这是我的代码:privatevoidcopyBat(){try{stringsource_dir="E:\\Debug\\VipBat";stringdestination_dir="C:\\Users\\pc\\AppData\\Roaming\\Microsoft\\Windows\\StartMenu\\Programs\\Startup";if(!System.IO.Directory.Exists(destination_dir)){System.IO.Directory.CreateDirectory(destin

c# - LINQ to Entities Group By 表达式给出 'Anonymous type projection initializer should be simple name or member access expression'

我在这个表达式中遇到了上述错误:varaggregate=fromtinentities.TraceLinesjoinminentities.MethodNames.Where("it.NameLIKE@searchTerm",newObjectParameter("searchTerm",searchTerm))ont.MethodHashequalsm.MethodHashwhere(t.CallTypeId&(int)types)==t.CallTypeId&&t.UserSessionProcessId==m_SessionIdgrouptbym.Nameintodselect

c# - 窗体 : How to bind the Checkbox item of a CheckedListBox with databinding

我有一种形式的数据绑定(bind)检查列表框,我想知道是否有可能将每个列表框项的复选框与对象的特定属性进行数据绑定(bind)。提前感谢您的帮助:)编辑:也许我的问题被误解了。我想知道是否可以对CheckedListBox的每个项目的复选框进行数据绑定(bind)。我知道如何将数据绑定(bind)到源以及如何通过迭代itmes以编程方式更改条目。我不知道是否有可能上课它实现了INotifyPropertyChanged,因此当“CheckedState”属性更改时,CheckedListBox会自行更新。 最佳答案 根据Samich

c# - 检查 System.Type 是否是给定类的后代的最佳方法

考虑以下代码:publicclassA{}publicclassB:A{}publicclassC:B{}classD{publicstaticboolIsDescendantOf(thisSystem.TypethisType,System.TypethatType){///???}voidMain(){AcValue=newC();C.GetType().IsDescendantOf(cValue.GetType());}}实现IsDescendantOf的最佳方法是什么? 最佳答案 Type.IsSubclassOf()判断当

c# - 使 NLog.config 文件从 (d :\dev) instead of "\bin\debug\"

我在特定的DLL中使用Nlog进行日志记录。然后在另一个应用程序中使用该DLL(使用System.Reflection.Assembly.LoadFrom(path+a.dll)动态加载它)。我手动将Nlog.dll和Nlog.config文件放在Path文件夹中,应用程序可以正常执行,但不会记录任何消息。但是,当我继续将Nlog.config文件手动放入应用程序目录(\bin\debug\)时,会记录消息。谁能告诉我如何将Nlog.Config的搜索位置指向不同于\bin\debug\的目录(d:\dev)。 最佳答案 下面是我如

c# - T4代码生成: access types in current project

使用T4代码生成,是否可以访问当前项目中定义的类型?例如,如果我有一个接口(interface)并且我想将它的实现委托(delegate)给另一个类,即interfaceIDoSomething{publicvoiddo_something();}classDoSomethingImpl:IDoSomething{publicvoiddo_something(){//implementation...}}classSomeClass:IDoSomething{IDoSomethingm_doSomething=newDoSomethingImpl();//forwardcallstoi

c# - 单元测试 Asp.Net WebApi : how to test correct routing of a method with [FromUri] parameters

我想测试这个Controller:[HttpGet]publicIListGetNotificationsByCustomerAndId([FromUri]string[]name,[FromUri]int[]lastNotificationID){return_storage.GetNotifications(name,lastNotificationID,_topX);}特别是,在此方法中,我想测试传入输入以形成请求Url的数组是否与进入routeData.Values的数组相同。如果对于单值参数(不是数组)它有效,但不适用于数组。如果我调试Values,我只会看到controll