Tag: C#的

我怎样才能在直接窗口中轻松查看数据表或数据视图的内容

有时我会在我的代码断点,我想查看一个数据variables(或数据集中的数据表)的内容。 快速的手表并没有给你一个非常清晰的内容。 我如何轻松查看它们?

在不知道命名空间的情况下使用LINQsearchXDocument

有没有办法在不知道命名空间的情况下searchXDocument? 我有一个logging所有SOAP请求并encryption敏感数据的进程。 我想find任何基于名称的元素。 就像给我所有的名字是CreditCard的元素。 我不在乎命名空间是什么。 我的问题似乎与LINQ和需要一个XML命名空间。 我有其他进程从XML检索值,但我知道这些其他进程的命名空间。 XDocument xDocument = XDocument.Load(@"C:\temp\Packet.xml"); XNamespace xNamespace = "http://CompanyName.AppName.Service.Contracts"; var elements = xDocument.Root .DescendantsAndSelf() .Elements() .Where(d => d.Name == xNamespace + "CreditCardNumber"); 我真的想有能力searchXML不知道命名空间,如下所示: XDocument xDocument = XDocument.Load(@"C:\temp\Packet.xml"); var elements = xDocument.Root .DescendantsAndSelf() .Elements() .Where(d => d.Name == "CreditCardNumber") 这是行不通的,因为我不知道编译时的命名空间。 如何才能做到这一点? <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Request xmlns="http://CompanyName.AppName.Service.ContractA"> <Person> <CreditCardNumber>83838</CreditCardNumber> […]

如何将相对path转换为Windows应用程序中的绝对path?

如何将相对path转换为Windows应用程序中的绝对path? 我知道我们可以在ASP.NET中使用server.MapPath()。 但是,我们可以在Windows应用程序中做什么? 我的意思是,如果有一个.NET内置函数可以处理…

如何使用CMake的CCache?

我想这样做:如果CCache存在于PATH中,请使用“ccache g ++”进行编译,否则使用g ++。 我试图写一个小的my-cmake脚本包含 CC="ccache gcc" CXX="ccache g++" cmake $* 但它似乎并没有工作(运行make仍然不使用ccache;我检查了这个使用CMAKE_VERBOSE_MAKEFILE)。 更新: 按照这个链接,我尝试改变我的脚本 cmake -D CMAKE_CXX_COMPILER="ccache" -D CMAKE_CXX_COMPILER_ARG1="g++" -D CMAKE_C_COMPILER="ccache" -D CMAKE_C_COMPILER_ARG1="gcc" $* 但cmake救了抱怨,使用编译器ccachetesting失败(可以预料)。

System.Net.Http:缺less命名空间? (使用.net 4.5)

TL; DR:我是这个语言的新手,不知道自己在做什么 这是我的课到目前为止: using System; using System.Collections.Generic; using System.Net.Http; using System.Web; using System.Net; using System.IO; public class MyClass { private const string URL = "https://sub.domain.com/objects.json?api_key=123"; private const string data = @"{""object"":{""name"":""Title""}}"; public static void CreateObject() { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL); request.Method = "POST"; request.ContentType = "application/json"; request.ContentLength = data.Length; StreamWriter requestWriter = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII); […]

使用零填充(前导零)将int转换为QString

我想“串”一个数字,并添加零填充,如printf("%05d")如果数字小于5位数字将添加前导零。

我如何确保FirstOrDefault <KeyValuePair>返回了一个值

这里是我想要做的简化版本: var days = new Dictionary<int, string>(); days.Add(1, "Monday"); days.Add(2, "Tuesday"); … days.Add(7, "Sunday"); var sampleText = "My favorite day of the week is 'xyz'"; var day = days.FirstOrDefault(x => sampleText.Contains(x.Value)); 由于'xyz'不存在于KeyValuePairvariables中,所以FirstOrDefault方法不会返回有效的值。 我想能够检查这种情况,但我意识到,我不能比较结果为“空”,因为KeyValuePair是一个结构。 以下代码无效: if (day == null) { System.Diagnotics.Debug.Write("Couldn't find day of week"); } 我们尝试编译代码,Visual Studio引发以下错误: Operator '==' cannot be applied to operands of […]

IUnityContainer.Resolve <T>抛出声明它不能用于types参数的错误

昨天我已经实现了代码: CustomerProductManager productsManager = container.Resolve<CustomerProductManager>(); 这是可编译和工作。 今天(可能我已经修改了一些东西)我不断得到错误: 非generics方法'Microsoft.Practices.Unity.IUnityContainer.Resolve(System.Type,string,params Microsoft.Practices.Unity.ResolverOverride [])'不能与types参数一起使用 我的同事有相同的源代码,并没有相同的错误。 为什么? 如何解决这个问题? PS 行“使用Microsoft.Practices.Unity;” 存在于使用部分中。 我试图用非通用版本replace通用版本: CustomerProductManager productsManager = (CustomerProductManager)container.Resolve(typeof(CustomerProductManager)); 并得到另一个错误: 方法'Resolve'没有重载需要'1'参数 看起来像其中一个组件没有引用..但是哪一个? 我有其中2引用:1. Microsoft.Practices.Unity.dll 2. Microsoft.Practices.ServiceLocation.dll PPS我看到类似的问题http://unity.codeplex.com/WorkItem/View.aspx?WorkItemId=8205,但它被parsing为“不是一个错误” 任何想法都会有所帮助

如何获取特定属性的PropertyInfo?

我想获取PropertyInfo的一个特定的属性。 我可以使用: foreach(PropertyInfo p in typeof(MyObject).GetProperties()) { if ( p.Name == "MyProperty") { return p } } 但是必须有办法做类似的事情 typeof(MyProperty) as PropertyInfo 在那儿? 或者我坚持做一个types不安全的string比较? 干杯。

entity framework代码First Fluent Api:向列添加索引

我正在运行EF 4.2 CF,并希望在我的POCO对象的某些列上创build索引。 举一个例子,让我们说我们有这个雇员类: public class Employee { public int EmployeeID { get; set; } public string EmployeeCode { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public DateTime HireDate { get; set; } } 我们经常通过他们的EmployeeCode来search雇员,而且由于有很多雇员,为了性能原因,这样做会很好。 我们可以用stream利的API做些什么吗? 或者可能是数据注释? 我知道可以执行这样的sql命令: context.Database.ExecuteSqlCommand("CREATE INDEX IX_NAME ON …"); 我非常想避免这样的原始SQL。 我知道这不存在,但寻找的东西沿着这些线路: […]