小编Bry*_*her的帖子

foreach vs someList.ForEach(){}

显然有很多方法可以迭代集合.好奇,如果有任何差异,或为什么你使用一种方式而不是另一种方式.

第一种:

List<string> someList = <some way to init>
foreach(string s in someList) {
   <process the string>
}
Run Code Online (Sandbox Code Playgroud)

另一种方式:

List<string> someList = <some way to init>
someList.ForEach(delegate(string s) {
    <process the string>
});
Run Code Online (Sandbox Code Playgroud)

我认为,除了我上面使用的匿名代表之外,我还有一个你可以指定的可重用代理......

.net c# generics loops enumeration

152
推荐指数
8
解决办法
21万
查看次数

Java中的"this"可以为null吗?

在一个类方法中看到这一行,我的第一反应是嘲笑编写它的开发人员..但是,我认为我应该确保我是对的.

public void dataViewActivated(DataViewEvent e) {
    if (this != null)
        // Do some work
}
Run Code Online (Sandbox Code Playgroud)

那条线路会被评估为假吗?

java this

108
推荐指数
4
解决办法
2万
查看次数

Backbone.js模型与集合

我有2个模型和一个集合.JobSummary是一个模型,JobSummaryList是一个JobSummary项目的集合,然后我有一个JobSummarySnapshot模型,其中包含JobSummaryList:

JobSummary = Backbone.Model.extend({});

JobSummaryList = Backbone.Collection.extend({
    model: JobSummary
});

JobSummarySnapshot = Backbone.Model.extend({
    url: '/JobSummaryList',

    defaults: {
        pageNumber: 1,
        summaryList: new JobSummaryList()
    }
});
Run Code Online (Sandbox Code Playgroud)

当我调用fetchJobSummarySnapshot对象时,它会获得所有内容......除非我在summaryList集合中移动它们都是类型object而不是JobSummary.

我认为这是有道理的,因为除了defaults对象之外,它不知道summaryList应该是类型JobSummaryList.我可以浏览每个项目并将其转换为JobSummary对象,但我希望有一种方法可以在不必手动操作的情况下完成.

这是我的测试代码(在这里工作jsfiddle):

var returnData = {
    pageNumber: 3,
    summaryList: [
        {
        id: 5,
        name: 'name1'},
    {
        id: 6,
        name: 'name2'}
    ]
}; 

var …
Run Code Online (Sandbox Code Playgroud)

javascript ajax json backbone.js

37
推荐指数
1
解决办法
3万
查看次数

asp.net CustomValidator永远不会触发OnServerValidate

我有以下ASP页面:

<asp:Content ID="Content2" ContentPlaceHolderID="ShellContent" runat="server">
    <form runat="server" id="AddNewNoteForm" method="post"">

        <fieldset id="NoteContainer">
            <legend>Add New Note</legend>
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
            <div class="ctrlHolder">
                <asp:Label ID="LabelNoteDate" runat="server" Text="Note Date" 
                    AssociatedControlID="NoteDateTextBox"></asp:Label>
                <asp:TextBox ID="NoteDateTextBox" runat="server" class="textInput" 
                    CausesValidation="True" ></asp:TextBox>
                <asp:CustomValidator 
                        ID="CustomValidator1" 
                        runat="server" 
                        ErrorMessage="CustomValidator" 
                        ControlToValidate="NoteDateTextBox" 
                        OnServerValidate="CustomValidator1_ServerValidate" 
                        Display="Dynamic" 
                        >*</asp:CustomValidator>
            </div>
            <div class="ctrlHolder">
                <asp:Label ID="LabelNoteText" AssociatedControlID="NoteTextTextBox" runat="server" Text="Note"></asp:Label>
                <asp:TextBox ID="NoteTextTextBox" runat="server" Height="102px" 
                    TextMode="MultiLine" class="textInput" ></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                    ErrorMessage="Note Text is Required" ControlToValidate="NoteTextTextBox">*</asp:RequiredFieldValidator>   

            </div>
            <div class="buttonHolder">
                <asp:Button ID="OkButton" runat="server" Text="Add New Note"  
                    CssClass="primaryAction" onclick="OkButton_Click"/>
                <asp:HyperLink ID="HyperLink1" runat="server">Cancel</asp:HyperLink>
            </div>
        </fieldset>
    </form> …
Run Code Online (Sandbox Code Playgroud)

asp.net validation webforms .net-2.0

13
推荐指数
3
解决办法
1万
查看次数

JQuery:Visual studio,错误CS1056:意外字符'$'

试图在ASP.NET应用程序中包含ThickBox(来自http://jquery.com/demo/thickbox/).

当我尝试运行带有错误的应用程序时,Visual Studio失败:js\ThickBox\jquery-1.2.6.min.js(11):错误CS1056:意外字符'$'

使用Visual Studio 2008和jquery 1.2.6

asp.net jquery visual-studio-2008

7
推荐指数
2
解决办法
1万
查看次数

css背景图像定位(负面位置?)

我正在尝试添加一个位于边框顶部的图标,将其分成两半.

这是我到目前为止:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <style type="text/css">
        body {
            background-color:#26140C;
        }

        .box {
            width: 800px;
            margin: 0 auto;
            margin-top: 40px;
            padding: 10px;
            border: 3px solid #A5927C;

            background-color: #3D2216;
            background-image: url(Contents/img/icon_neutral.png);
            background-repeat: no-repeat;
            background-position:10px -20px;
        }
    </style>
</head>
<body>
    <div class="box">
        <h1>This is a test!</h1>
    </div>
</body>
Run Code Online (Sandbox Code Playgroud)

而不是像我希望的那样,图像越过边界,而是在它之下.

html css

6
推荐指数
3
解决办法
5万
查看次数

Backbone.js和Jasmine Spys没有被调用

我试图测试单击一个元素时,调用一个函数.它似乎很容易,但我必须错过一些愚蠢的东西,因为我似乎无法让这个简单的例子起作用.

这是我的观点

(function($) {
    window.LaserMonitor = {
        Views: {}
    };

    window.LaserMonitor.Views.WorkstationSummary = Backbone.View.extend({
        tagName: 'li',
        className: 'StationItem',

        initialize: function() {
            _.bindAll(this, 'showDetails');
            this.template = _.template($("#WorkstationSummary").html());
        },

        events: {
            'click h3' : 'showDetails'
        },

        showDetails: function() {
        },

        render: function() {
            var renderedTmpl = this.template(this.model.toJSON());

            $(this.el).append(renderedTmpl);

            return this;
        }
    });
})(jQuery);
Run Code Online (Sandbox Code Playgroud)

这是我的茉莉花测试:

describe('WorkstationSummary Item', function() {
    beforeEach(function() {
        _.templateSettings = {
          interpolate: /\{\{(.+?)\}\}/g,
          evaluate: /\{\{(.+?)\}\}/g
        };      

        loadFixtures('LaserMonitorFixture.html');

        this.model = new Backbone.Model({
            id: 1,
            name: 'D8',
            assigned: 1900,
            inProgress: 4,
            completed: 5 …
Run Code Online (Sandbox Code Playgroud)

backbone.js jasmine

4
推荐指数
1
解决办法
1983
查看次数

Rhino Mocks约束和Dictionary参数

如何检查接受字典的函数的参数?

IDictionary<string, string> someDictionary = new Dictionary<string, string> {
  {"Key1", "Value1"},
  {"Key2", "Value2"}
};

Expect.Call(delegate {someService.GetCodes(someDictionary);}).Constraints(...);
Run Code Online (Sandbox Code Playgroud)

基本上,我想验证GetCodes的参数是否与变量"someDictionary"具有相同的值.

我忘了提到正在测试的方法构建字典并将其传递给someService.GetCodes()方法.

public void SomeOtherMethod() {
  IDictionary<string, string> dict = new Dictionary<string, string> {
    {"Key 1", "Value 1"},
    {"Key 2", "Value 2"}
  };

  someService.GetCodes(dict); // This would pass!

  IDictionary<string, string> dict2 = new Dictionary<string, string> {
    {"Key 1", "Value 1a"},
    {"Key 2a", "Value 2"}
  };

  someService.GetCodes(dict2); // This would fail!

}
Run Code Online (Sandbox Code Playgroud)

所以,我想确保传递给GetCodes方法的字典包含与Expect.Call ...方法中指定的字典相同的字典.

另一个用例是,我可能只想查看字典中的键是否包含"键1"和"键2",但不关心值......或者其他用途.

.net c# unit-testing rhino-mocks mocking

3
推荐指数
1
解决办法
2137
查看次数

早午餐配置:javascript文件排除*.min.js文件

我理解brunch如何处理javascript文件,将它们组合成单独的输出文件:

  files:
    javascripts:
      joinTo:
        'javascripts/app.js': /^app/
        'javascripts/vendor.js': /^vendor/
        'test/javascripts/test.js': /^test(\/|\\)(?!vendor)/
        'test/javascripts/test-vendor.js': /^test(\/|\\)(?=vendor)/
Run Code Online (Sandbox Code Playgroud)

例如,第二行获取/ vendor /文件夹中的所有javascript文件并生成vendor.js

正则表达式(/ ^ vendor /)指定文件夹路径是否正确?有任何方法让正则表达式也适用于文件名吗?例如,如果有jquery.js和jquery.min.js,我只想包含jquery.js文件.这可能吗?

javascript node.js brunch

3
推荐指数
1
解决办法
2168
查看次数

从 PubSubIO 读取:fromTopic 与 fromSubscription

我在一些示例代码中看到似乎直接从主题中读取?

PubsubIO.readStrings().fromTopic(fullTopic))
Run Code Online (Sandbox Code Playgroud)

那和有区别吗

PubsubIO.readStrings().fromSubscription(fullTopic))
Run Code Online (Sandbox Code Playgroud)

(我一直觉得你必须订阅一个主题......)

编辑:使用 fromTopic添加到示例的链接

java google-cloud-pubsub google-cloud-dataflow apache-beam-io

2
推荐指数
1
解决办法
566
查看次数

JAX-WS客户端基本身份验证

我被迫从我的网络服务中删除CXF.为了删除对身份验证的任何依赖性,我设置了一个HttpAuthSupplier类来处理基本身份验证.

public class ExchangeAuthSupplier implements HttpAuthSupplier{
       @Override
       public boolean requiresRequestCaching() {
           return false;
       }

       @Override
       public String getAuthorization(AuthorizationPolicy authPolicy, URL url, Message message, String fullHeader) {
           // Lookup authentication information and return appropriate header
       }

}
Run Code Online (Sandbox Code Playgroud)

我正在试图弄清楚如何使用常规JAX-WS API和Spring来做类似的事情......

java spring jax-ws

1
推荐指数
2
解决办法
1万
查看次数