草庐IT

types_and_classes

全部标签

c# - 使用 OR 而不是 AND 的 MultiDataTrigger

我正在尝试在我的Button上设置多个DataTriggers。我做了一些研究,发现MultiDataTrigger允许您执行此操作。如果CCTVPath==string.Empty或PermissionsFlag==false,我希望将Button的Visibility属性设置为false。这是我目前所拥有的;在我的代码隐藏中,我像这样设置了PermissionsFlag;publicboolPermissionsFlag{get;set;}privatevoidOnPageLoaded(objectsender,RoutedEventArgse){PermissionsFlag=f

c# - 在 C# 中使用 Type.GetType() 返回的类型

我有一个关于如何可能的问题(如果可能的话:)例如,使用Type.GetType()返回的类型引用来创建该类型的IList?这里是示例代码:Typecustomer=Type.GetType("myapp.Customer");IListcustomerList=newList();//gotanerrorhere=[提前致谢! 最佳答案 像这样:TypelistType=typeof(List).MakeGenericType(customer);IListcustomerList=(IList)Activator.CreateIn

c# - 使用 MultipartFormDataContent 生成错误的 Content-Type header

我有以下代码:privatestaticstringboundary="----CustomBoundary"+DateTime.Now.Ticks.ToString("x");privatestaticasyncTaskPostTest(){stringservResp="";using(varcontent=newMultipartFormDataContent(boundary)){content.Add(newStringContent("105212"),"case-id");content.Add(newStringContent("1/14/2014"),"dateFro

c# - 序列化异常 : Type is not resolved for member "..."

我一直在尝试将程序集动态加载到AppDomain。我需要这样做是因为我想动态调用一个方法,但在我的应用程序运行时不要保留DLL的句柄,以便在需要时可以替换它。但我收到此SerializationException异常:类型未解析成员“...”这是我的代码:AppDomaindomain=AppDomain.CreateDomain("TempAppDomain",null,AppDomain.CurrentDomain.SetupInformation);try{objectobj=domain.CreateInstanceFromAndUnwrap(dllPath,typeName)

c# - "Class of <T> where T : Enum"不工作

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:CreateGenericmethodconstrainingTtoanEnum为什么我们不能在C#中执行此操作?而且,如果可能的话,我怎样才能做类似的事情!我想要什么:publicclassATagwhereT:enum{[Somecode..]}publicclassclassBasewhereT:enum{publicIDictionarytags{get;set;}}因此,当需要调用它时,我很确定只会获得我的枚举值之一。publicclassAClassUsingTag:classBase{publi

c# - 将 List<object> 转换为 List<Type>,类型在运行时已知

我正在实现某种反序列化并遇到下一个问题:我有List和System.Reflection.Field,它是FieldType可以是List,List或List,所以我需要从List转换到那种类型。publicstaticobjectConvertList(Listvalue,Typetype){//typemaybeList,List,List}我可以单独写每个案例,但应该有更好的方法使用反射。 最佳答案 我相信你想要的是:publicstaticobjectConvertList(Listvalue,Typetype){varco

c# - NaoQi 和 Leap 问题 : An unhandled exception of type 'System.BadImageFormatException' . .. 并且无法加载文件或程序集

目前,我遇到了一个问题,我无法通过Google上的解决方案解决这个问题。到目前为止没有任何效果。当我编译LeapMotion代码并导入NaoqiC#库时,它工作正常。当我实际尝试使用一行代码连接到机器人时,我的程序崩溃了。我的程序设置为为任何CPU构建。.dll被Leap库和NaoQi库引用,并且.dll被放置在调试文件夹和项目文件夹中以备不时之需。目前我还不知道问题出在哪里。这里有人能弄清楚吗?我会很高兴让这个工作。这是第一条错误信息,然后它要求我中断或继续:Anunhandledexceptionoftype'System.BadImageFormatException'occur

c# - 公开课 - "is inaccessible due to its protection level. Only public types can be processed."

我正在做一个测试项目来了解对象的XML序列化,但我遇到了一个奇怪的运行时错误:namespaceSerializeTest{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse){}privatevoidserializeConnection(Connconnection){XmlSerializerserializer=newXmlSerializer(typeof(Conn));TextWritertextWrit

c# - 无法加载文件或程序集 ':This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded

我在我的解决方案中有3个项目:BL、DL和UI。这三个项目的目标框架都是>NET4;我通过查看每个项目的属性页仔细检查了这一点。当我尝试在托管环境中运行网站时收到以下错误消息,但在本地运行时却没有。Couldnotloadfileorassembly'BL'oroneofitsdependencies.Thisassemblyisbuiltbyaruntimenewerthanthecurrentlyloadedruntimeandcannotbeloaded.提前致谢! 最佳答案 -转到IIS。-DefaultWebSite->Y

c# - Join List<string> 连同最后一个元素的逗号加 "and"

我知道我可以找到出路,但我想知道是否有更简洁的解决方案。总是有String.Join(",",lList)和lList.Aggregate((a,b)=>a+","+b);但我想要为最后一个将"和"作为其连接字符串添加异常(exception)。Aggregate()是否有一些我可以使用的索引值?谢谢。 最佳答案 你可以这样做stringfinalString=String.Join(",",myList.ToArray(),0,myList.Count-1)+",and"+myList.LastOrDefault();