I'm looking for some pros and cons for using extension methods over static utility classes in a C# app. For instance, a plus in the extension methods column is the convinience of calling by the class name rather than something like "StringUtils". But a con would be that it can blur the lines between what is in the framework and what isn't. I would say that a pro is that it
我正在寻找一些优点和缺点,以便在C#应用程序中使用静态工具类的扩展方法。 例如,扩展方法列中的加号是通过类名调用而非类似“StringUtils”的方便。 但是,con会是它可以模糊框架内部和非框架之间的界限。 我想说的是,一个专业人士会模糊框架和非框架之间的界限:您可以自己使用自己的代码作为框架代码,使用框架类型。 扩展方法当然不应该被任意使用 - 它不像所有的静态方法都应该成为扩展方法。 我试图将其看作是该
I've written a Windows Application to test a connection to a clients SAP web services. The web service call requires X509 certificate security. After reading various articles on the internet I've come up with three ways to attach the X509 certificate to the web service call. Unfortunately all of these attempts return a '401 Unauthorised Access'. However, I can connect to the
我编写了一个Windows应用程序来测试与客户端SAP Web服务的连接。 Web服务调用需要X509证书安全性。 在阅读了互联网上的各种文章后,我想出了三种方法将X509证书附加到Web服务调用中。 不幸的是,所有这些尝试都会返回“401未授权访问”。 但是,我可以通过IE中的URL连接到Web服务。 有没有人对我可能做错的事有什么要求? 我正在使用WSE 3.0,并且我正在使用三种方法来附加证书,如下所示: - 证书 X509Certificate2 oC
验证字符串是否为有效的电子邮件地址的最优雅的代码是什么? This is an old question, but all the answers I've found on SO, including more recent ones, are answered similarly to this one. However, in .Net 4.5 / MVC 4 you can add email address validation to a form by adding the [EmailAddress] annotation from System.ComponentModel.DataAnnotations, so I was wondering why I couldn't just use the
验证字符串是否为有效的电子邮件地址的最优雅的代码是什么? 这是一个古老的问题,但我在SO上发现的所有答案,包括最近的答案,都与此类似。 但是,在.Net 4.5 / MVC 4中,您可以通过添加来自System.ComponentModel.DataAnnotations的[EmailAddress]注释来将电子邮件地址验证添加到表单,所以我想知道为什么我不能只使用内置的功能。一般网。 这看起来很有效,在我看来相当优雅: using System.ComponentModel.DataAnnotation
Possible Duplicates: Email Validation - Regular Expression What is the best regular expression for validating email addresses? Hi All, I have an email address roughly like this, firstname.lastname@4domain.co.nz Which doesn't work with the regex I have here for email addresses. It doesn't seem to like the 4 at the start of the domain. private const string MatchEmailPattern =
可能重复: 电子邮件验证 - 正则表达式 验证电子邮件地址的最佳正则表达式是什么? 大家好, 我有一个大致像这样的电子邮件地址, firstname.lastname@4domain.co.nz 这不适用于我在这里用于电子邮件地址的正则表达式。 它似乎并不喜欢域名开头的4。 private const string MatchEmailPattern = @"^(([w-]+.)+[w-]+|([a-zA-Z]{1}|[w-]{2,}))@" + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9]).([0-1]
I have a class called Questions (plural). In this class there is an enum called Question (singular) which looks like this. public enum Question { Role = 2, ProjectFunding = 3, TotalEmployee = 4, NumberOfServers = 5, TopBusinessConcern = 6 } In the Questions class, I have a get(int foo) function that returns a Questions object for that foo . Is there an easy way to get the
我有一个叫做Questions (复数)的课。 在这个类中有一个名为Question (单数)的枚举,看起来像这样。 public enum Question { Role = 2, ProjectFunding = 3, TotalEmployee = 4, NumberOfServers = 5, TopBusinessConcern = 6 } 在Questions类中,我有一个get(int foo)函数,它返回该foo一个Questions对象。 有没有一种简单的方法从枚举中获得整数值,所以我可以做一些像Questions.Get(Question.Role
This question already has an answer here: How to enumerate an enum? 14 answers public enum Foos { A, B, C } Is there a way to loop through the possible values of Foos ? Basically? foreach(Foo in Foos) Yes you can use the GetValues method: var values = Enum.GetValues(typeof(Foos)); Or the typed version: var values = Enum.GetValues(typeof(Foos)).Cast<Foos>(); I l
这个问题在这里已经有了答案: 如何枚举枚举? 14个答案 public enum Foos { A, B, C } 有没有办法循环Foos的可能值? 基本上? foreach(Foo in Foos) 是的,你可以使用GetValues方法: var values = Enum.GetValues(typeof(Foos)); 或者键入的版本: var values = Enum.GetValues(typeof(Foos)).Cast<Foos>(); 我很久以前就向我的私人图书馆添加了一个辅助函数, public static class EnumUt
What are the best practices for database refactoring with codefirst EF4? I am interested to hear how people change the classes and the database when the RecreateDatabaseIfModelChanges option is not feasible. Migration of data will need to occur. Currently Microsoft has a solution for doing this with model first: http://blogs.msdn.com/b/adonet/archive/2010/02/08/entity-designer-database-gen
使用codefirst EF4进行数据库重构的最佳做法是什么? 我很想知道当RecreateDatabaseIfModelChanges选项不可行时人们如何更改类和数据库。 数据迁移将需要发生。 目前微软有一个解决方案,首先使用模型进行此操作: http://blogs.msdn.com/b/adonet/archive/2010/02/08/entity-designer-database-generation-power-pack.aspx?PageIndex=2#comments 有没有人有第一个好的代码策略? EF团队一直致力于EF的迁移功能,以解
We have a web service that does a fairly high volume of traffic that helps you figure out what are your preferred contacts based on the e-mails you receive. This service was initially implemented in C# /.NET in order to leverage some code we already have running on Windows hosts. This service does not uses ASP.NET but it's a simple C# service using a base HTTP Listener from .NET. The ser
我们有一个网络服务,可以提供相当高的流量,帮助您根据收到的电子邮件找出您的首选联系人。 该服务最初是在C#/ .NET中实现的,目的是利用我们已经在Windows主机上运行的一些代码。 此服务不使用ASP.NET,但它是使用.NET的基本HTTP侦听器的简单C#服务。 该服务正在执行,但偶尔MONO将完全阻止并停止响应任何请求。 虽然性能不错,但效果并不好,我们花费了大量的时间来研究MONO CLR和Windows CLR之间的差异。 我必须承
I'm trying to create a not in clause with the NHibernate Criteria API using NHLambdaExtensions. Reading the documentation I was able to implement the in clause by doing .Add(SqlExpression.In<Zone>(z => zoneAlias.ZoneId, new int[] { 1008, 1010 })) However, when I wrap it around SqlExpression.Not I get the error Error 5 The best overloaded method match for 'NHibernate.LambdaExt
我试图用NHLambdaExtensions在NHibernate Criteria API中创建一个not in子句。 阅读文档,我能够通过做实现in子句 .Add(SqlExpression.In<Zone>(z => zoneAlias.ZoneId, new int[] { 1008, 1010 })) 但是,当我将它包装在SqlExpression.Not不会收到错误消息 Error 5 The best overloaded method match for 'NHibernate.LambdaExtensions.SqlExpression.Not<oms_dal.Models.Zone>(System.Linq.Expressions.
I made a comment yesterday on an answer where someone had used [0123456789] in a regular expression rather than [0-9] or d . I said it was probably more efficient to use a range or digit specifier than a character set. I decided to test that out today and found out to my surprise that (in the C# regex engine at least) d appears to be less efficient than either of the other two which don't
我昨天对某个人在正则表达式中使用[0123456789]而不是[0-9]或d的回答发表了评论。 我说使用范围或数字说明符可能比字符集更有效。 我决定今天测试一下,发现令我惊讶的是(至少在C#正则表达式引擎中) d看起来效率不如其他两种似乎差别不大的其他两种效率更高。 这是我的测试输出超过1000个随机字符的10000个随机字符串,其中5077实际上包含一个数字: Regular expression d took 00:00:00.2141226 result: 507