Tag: C#的

如何在MVC4中的UserProfile中创build自定义附加字段

我面临着新的ASP MVC 4function,它附带了新的成员资格数据库模式和新的初始化。 在mvc 3和旧版本中,开发人员能够使用web.config中的规范创build自定义用户configuration文件字段,但现在我面临默认mvc 4项目中的filter名称空间中的方法: WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true); 和用户configuration文件表: [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } public string UserName { get; set; } } 但是,方法InitializeDatabaseConnection只生成UserName和UserId我需要生成其他额外的字段。 我在EF codeFirst方法有很好的经验,在这种情况下,我尝试编辑UserProfile类: [Table("UserProfile")] public class UserProfile { [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] public int UserId { get; set; } [Column] [Required] public […]

扩展LINQ接受可枚举枚举

在使用Linq扩展时,看到这样的代码是正常的: IEnumerable<int> enumerable = GetEnumerable(); int sum = 0; if (enumerable != null) { sum = enumerable.Sum(); } 为了提高代码质量,我编写了下面的扩展方法来检查可空的枚举types并打断linq的执行。 public static IEnumerable<T> IgnoreIfEmpty<T>(this IEnumerable<T> enumerable) { if (enumerable == null) yield break; foreach (var item in enumerable) { yield return item; } } 所以,我可以重构代码是这样的: var sum = GetEnumerable().IgnoreIfEmpty().Sum(); 我现在的问题是: 我的扩展方法在运行时会受到哪些处罚? 以这种方式扩展linq是一个好习惯吗? 更新:我的目标框架是:3.5

获取数组中的特定项目的索引

我想检索一个数组的索引,但我知道只有一部分的实际价值的数组例如我存储在数组中的作者姓名dynamic地说“author ='xyz'”我想find数组项的索引包含像作者的东西,因为我不知道如何做到这一点的价值部分。

如何计算图表的趋势线?

Google不是我的朋友 – 从我在大学的统计课程开始已经很长时间了…我需要在图表上计算趋势线的开始点和结束点 – 是否有一个简单的方法可以做到这一点? (用C#工作,但是任何语言都适合你)

是否有可能放弃一个任务,如中止一个线程(Thread.Abort方法)?

我们可以放弃这样的线程: Thread thread = new Thread(SomeMethod); . . . thread.Abort(); 但是我可以用相同的方式中止任务(在.Net 4.0中)而不是通过取消机制。 我想马上杀掉这个任务

C#“必须声明一个主体,因为它没有被标记为抽象的,外部的或者部分的”

我不知道为什么我得到这个错误是诚实的。 private int hour { get; set { //make sure hour is positive if (value < MIN_HOUR) { hour = 0; MessageBox.Show("Hour value " + value.ToString() + " cannot be negative. Reset to " + MIN_HOUR.ToString(), "Invalid Hour", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { //take the modulus to ensure always less than 24 hours //works even […]

如何configurationlog4net以debugging模式打印到控制台

有没有办法将log4netconfiguration为在debugging期间将日志打印到控制台和文件? 我试图find一种方法,通过在发生日志时立即观察日志来高效地debugging我的软件。 写入文件对我来说是有问题的,因为我不想等到文件刷新到磁盘然后打开它。 所以我更喜欢把它写入控制台。 你有什么build议? 我添加了附加的app.config文件,但是我无法显示结果控制台。 以下是我的app.configconfiguration: <?xml version="1.0"?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <system.serviceModel> <bindings> <wsHttpBinding> <binding name="WSHttpBinding_IProviderService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/> <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/> <security mode="Message"> <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/> <message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default"/> […]

Moq,SetupGet,嘲弄一个属性

我试图嘲笑一个名为UserInputEntity的类,它包含一个名为ColumnNames的属性:(它包含其他属性,我已经简化了它的问题) namespace CsvImporter.Entity { public interface IUserInputEntity { List<String> ColumnNames { get; set; } } public class UserInputEntity : IUserInputEntity { public UserInputEntity(List<String> columnNameInputs) { ColumnNames = columnNameInputs; } public List<String> ColumnNames { get; set; } } } 我有一个主持人class: namespace CsvImporter.UserInterface { public interface IMainPresenterHelper { //… } public class MainPresenterHelper:IMainPresenterHelper { //…. } public […]

使用MSVC 14.0编译Boost时的未知编译器版本(VS 2015)

当我试图在我的电脑上编译Boost库时,我得到“未知的编译器版本 – 请运行configuretesting并报告结果”。 我有最近的升压(截至date) – 1.58.0。 不提升支持MSVC 14.0呢? 我如何“运行configurationtesting”? 截图 。

无法findsn.exe签署大会

我看着C:\Program Files\Microsoft.NET ,我看不到任何SN.exe文件。 我有.NET 3.5运行时安装; 这不够吗?