当我第一次在一个类中实现一个接口时,我希望resharper 6或visual studio 2010将我的属性实现为自动实现的属性,而不是put new nonImplementedException();的默认值.我怎样才能做到这一点?例如:
public interface IEmployee
{
// want this to stay just like this when implemented into class
ID { get; set; }
}
public class Employee : IEmployee
{
// I do not want the throw new NonImplemented exception
// I want it to just appear as an auto implemented property
// as I defined it in the interface
public int ID
{
get
{
throw new NotImplementedException();
}
set
{
throw new NotImplementedException();
} …Run Code Online (Sandbox Code Playgroud) 我有两个员工名单,我想从中获得唯一的记录,但这有一个扭曲.每个列表中都有一个Employee类:
public class Employee
{
// I want to completely ignore ID in the comparison
public int ID{ get; set; }
// I want to use FirstName and LastName in comparison
public string FirstName{ get; set; }
public string LastName{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想要匹配的唯一属性是FirstName和LastName.我想在比较中完全忽略ID.allFulltimeEmployees列表中有3名员工,allParttimeEmployees列表中有3名员工.名单上的两个项目的名字和姓氏相匹配 - 莎莉琼斯和弗雷德杰克逊.列表中有一个项不匹配,因为FirstName是相同的,但LastName不同:
emp.id = null; // not populated or used in comparison
emp.FirstName = "Joe"; // same
emp.LastName = "Smith"; // different
allFulltimeEmployees.Add(emp);
emp.id = 3; // not used in comparison
emp.FirstName = "Joe"; // …Run Code Online (Sandbox Code Playgroud) 以下代码显示警报消息,因为规则在map()函数中绑定.我不希望这种情况发生.相反,如何绑定onClick()到每个链接,以便当用户单击链接时,消息将显示?我认为这与放置bind(this)在map()代码中的某个地方有关,但无法弄明白.谢谢你的帮助!
const RuleResults = React.createClass({
showMessage: function (rule) {
if (rule.ShowMessageToUser == true) {
alert(rule.MessageToUser);
}
},
render: function () {
var rules = this.props.businessRules.map((rule) => {
return (
<tr>
<td>
<a href={rule.HREF} onClick={this.showMessage(rule)} target='_blank'>{rule.Name}</a>
</td>
</tr>
);
});
return (
<div>
<table>
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
{rules}
</tbody>
</table>
</div>
);
}
});
Run Code Online (Sandbox Code Playgroud) 我在MVC 3 Web应用程序中使用Simple Injector作为IOC.我正在使用RavenDB进行数据存储.在mvc 3应用程序中使用RavenDB有几个注意事项.我搜索了一些关于如何连接IoC以使用RavenDB,但还没有找到如何连接简单的注入器来使用RavenDB.任何人都可以解释如何连接简单的注入器在MVC 3 Web应用程序中使用RavenDB?
谢谢.
.net inversion-of-control ravendb asp.net-mvc-3 simple-injector
所有,
我正在开发dnn 6模块,似乎找不到使用JQuery获取ModuleID的任何方法。ModuleID不在查询字符串中,并且似乎存储在上下文中。如果有人没有在查询字符串中显示JQuery,有人知道如何使用ModuleID吗?
我尝试执行此操作的一种方法是使用asp:label控件,然后在页面加载中将ModuleID分配给标签,然后使用JQuery来获取该标签的.val()。但是,我不想让ModuleID仅显示在页面上-太傻了!:)
感谢您的提示!
我试图通过我称为DumpIt的以下IEnumerable扩展方法.调试器不会单步执行它.如何让调试器进入此扩展方法?
我的单元测试:
[Test]
public void TestDumpIt()
{
var words =
new string[] {" KOOKABURRA", "Frogmouth", "kingfisher ", "loon", "merganser"};
var result = words
.DumpIt(d => "original: " + d)
.Select(word => word.Trim())
.DumpIt(d => "trimmed: " + d)
.Select(word => word.ToLower())
.DumpIt(d => "lower cased: " + d)
.Where(word => word.StartsWith("k"))
.DumpIt(d => "starts with k: " + d)
.OrderBy(word => word)
.DumpIt(d => "orderd: " + d);
}
Run Code Online (Sandbox Code Playgroud)
扩展方法:
public static IEnumerable<T> DumpIt<T>(this IEnumerable<T> input,
Func<T, string> toString
) …Run Code Online (Sandbox Code Playgroud) 我循环遍历几个Huncel excel文件的目录,并尝试一次刷新一个excel文件.我不断收到此错误,表示刷新操作仍在文件A上运行,例如,FileB正在尝试启动刷新操作.循环是快速的,不知怎的,我必须等待文件A上的先前刷新操作完成,然后才开始刷新文件B.
未处理的异常:System.Runtime.InteropServices.COMException:消息过滤器指示应用程序正忙.(来自HRESULT的异常:0x8001010A(RPC_E_SERVERCALL_RETRYLATER))位于RefreshExcelFiles.Program.RefreshFile(String fileName)的Microsoft.Office.Interop.Excel._Workbook.RefreshAll()
这是我的代码.在循环中开始处理新文件之前,如何等待刷新操作完成?或者,在开始新文件之前,等待wb对象上的编组释放操作完成?
using System;
using System.Configuration;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Excel;
namespace RefreshExcelFiles
{
internal class Program
{
private static string _fileDirectory;
private static Application _excelApp;
private static void Main(string[] args)
{
_fileDirectory = ConfigurationManager.AppSettings["FileDirectory"];
_excelApp = new Application();
_excelApp.DisplayAlerts = false;
Console.WriteLine("starting to refresh files");
int i = 0;
int total = Directory.GetFiles(_fileDirectory).Length;
foreach (string file in Directory.GetFiles(_fileDirectory))
{
i += 1;
Console.WriteLine("File " + file + " " + i.ToString() + "/" + total.ToString()); …Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多这个问题的解决方案,并尝试了所有这些解决方案,但无法找到完成此任务的正确方法.我的代码是:
p.StartInfo.Arguments = path;
Run Code Online (Sandbox Code Playgroud)
我需要路径变量被"标记包围,因为它是一个文件的路径,在目录名和文件名中有空格.我怎么能在路径变量的开头和结尾附近放一个?Psudo代码将是:
p.StartInfo.Arguments = DoubleQuote + path + DoubleQuote;
Run Code Online (Sandbox Code Playgroud)
作为这种情况的后续 - 一旦我的.exe文件收到路径 - 路径完全遵循"\""建议.但是,我必须将路径包含在.exe"中的.exe文件代码中它也可以找到.xlsx文件,因为路径和文件名中有空格.只是想对其他任何有这种情况的人进行跟进,并想知道为什么命令行参数没问题,但.exe文件没有找到文件 - 两个应用程序都需要用"\""括起来.
我有这个javascript代码.当它呈现时,它会在链接文本周围显示引号,而不仅仅是文本.正确连接链接文本的语法是什么?我的报价搞砸了,但我无法弄清楚.
var link = "<a id=\"myLink\" href=\"\" target=\"_blank\">\"" + text + "\"</a>";
Run Code Online (Sandbox Code Playgroud) 我需要将一个父列表和两个子列表合并为一个列表。我如何使用 C# 和 linq 来做到这一点?
这是我的代码...
public class Customer
{
public string FirstName { get; set;}
public string LastName { get; set;}
// need to flatten these lists
public List<CreditCard> CreditCards { get; set;}
public List<Address> Addresses{ get; set;}
}
// Customer has CreditCards list and Addresses list
List<Customer> allCustomers = _db.GetAllCustomers();
// how to flatten Customer, CreditCards list, and Addresses list into one flattened record/list?
var result = allCustomers.GroupBy().SelectMany(); // how to flatten nested lists?
Run Code Online (Sandbox Code Playgroud)
因此,结果列表将包含看起来扁平化的项目,如下所示:
Joe, Blow, Visa, …
我有一个类的集合,集合中的每个类都有三个属性,但需要通过类集合中的两个属性来区分.令人困惑的部分是我只需要两个属性后就需要所有三个属性.最常见的例子是使用你想要区分的属性来创建一个不同类型,但这将摆脱我的第三个属性,我需要在不同操作之后的项目集合中.如何区分三个属性中的两个,但最终结果是包含所有三个属性的类的集合?课程是:
public class Foo
{
public int PropertyOne {get; set;}
public int PropertyTwo {get; set;}
public string PropertyThree {get; set;}
}
// fake example of what I want but
// final result has all three properties in the collection still
var finalResult = allItems.DistinctBy(i => i.PropertyOne, i.PropertyTwo).ToArray();
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我根据页面上的下拉选项显示/隐藏了一个复选框.
$("#Units").change(function () {
if ($(this).val() == "D") {
$('#chkSkipSatSun').css('display', 'inline');
} else {
$('#chkSkipSatSun').css('display', 'none');
}
});
Run Code Online (Sandbox Code Playgroud)
在页面加载时,隐藏复选框.我使用下拉菜单打开并提交页面,此测试仍然失败:
if ($('#chkSatSun').css('display') == 'inline') {
alert('in');
}
Run Code Online (Sandbox Code Playgroud)
我在浏览器中查看HTML并且显示内容肯定设置为内联,但此测试仍然失败.如何让这个测试工作并在DOM中查看内联的CSS值?
c# ×8
jquery ×3
linq ×2
list ×2
.net ×1
asp.net ×1
class ×1
collections ×1
command-line ×1
comparison ×1
css ×1
debugging ×1
distinct ×1
dotnetnuke ×1
excel ×1
generics ×1
html ×1
interface ×1
interop ×1
javascript ×1
marshalling ×1
parameters ×1
properties ×1
ravendb ×1
reactjs ×1