小编Ale*_*dre的帖子

使用goto的最佳实践

goto在这段代码中使用是否正确?还有其他选择吗?

return ExecuteReader(cmd, reader =>
{
    List<BEPartnership> partnerhip = null;

    //Partnership
    if (!((SqlDataReader) reader).HasRows)
        goto exit;

    partnerhip = 
        new List<BEPartnership>{new BEPartnership().GetFromReader(reader)};

    //Customers
    if (!reader.NextResult() && !((SqlDataReader) reader).HasRows)
        goto exit;

    foreach (BEPartnership p in partnerhip)
        p.Partner = new BECustomer().GetFromReader(reader);

    //Contracts
    if (!reader.NextResult() && !((SqlDataReader) reader).HasRows)
        goto exit;

    List<BEContractB2B> contracts = new List<BEContractB2B>();
    contracts.Add(new BEContractB2B().GetFromReader(reader));
    // contracts = new BEContractB2B().GetFromReader2(reader).ToList();

    exit:
    return partnerhip;
});
Run Code Online (Sandbox Code Playgroud)

.net c# goto

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

参考类型

 var a = MyClassInstance;
    MyClassInstance = null;
    //if (a !=null){ //why }
Run Code Online (Sandbox Code Playgroud)

我认为a指向MyClassInstanceMyClassInstance等于null,那么也a必须等于null.但a不是空的,我不明白为什么.

.net

6
推荐指数
2
解决办法
90
查看次数

在 C# 中组合两个音频文件

有 2 个音频(mp3 或 wav)文件。第一个文件是我的声音,第二个文件是我朋友的声音。他们每个人都有10 秒的持续时间。我想将它们结合起来得到一个文件,它也应该有 10 秒的持续时间。

我应该使用哪些工具或实用程序来解决这个问题?

更新:我使用了 lame.exe,但它连接了它们并创建了持续时间为 20 秒的文件。

c# audio c#-4.0

5
推荐指数
1
解决办法
5154
查看次数

如何将图标添加到System.Windows.Forms.MenuItem?

我试图在我的一个上下文菜单项中添加一个图标,但我无法做到.有谁能够帮我?

这是我写的代码:

 private System.Windows.Forms.ContextMenu notifyContextMenu;
 private void foo() {
            if (notifyIcon == null) {
                notifyIcon = new System.Windows.Forms.NotifyIcon();   
            }

           if (notifyContextMenu == null) {
               notifyContextMenu = new System.Windows.Forms.ContextMenu();
               notifyContextMenu.MenuItems.Add("Exit");
               // How do I add an icon to this context menu item?
             }
            notifyIcon.ContextMenu =  notifyContextMenu;
          }
     }
Run Code Online (Sandbox Code Playgroud)

.net contextmenu menu winforms

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

Ruby和Ruby on Rails中的三层体系结构

我是一名ASP.NET MVC开发人员,他决定学习Ruby和Ruby on Rails.我已经知道了什么,并在RoR上创建了一个网站.在ASP.NET MVC上开发,我一直使用三层架构:数据层,业务层和UI(或表示)层.

试图在Ruby on Rails应用程序中使用这种方法,我发现没有关于它的信息(或者我可能找不到它?).

也许有人可以建议我如何在Ruby on Rails上创建或使用三层架构?

PS我使用ruby 1.9.3和Ruby on Rails 3.2.3.

ruby ruby-on-rails-3

5
推荐指数
2
解决办法
2708
查看次数

Rails - 在哪里存储配置值?

在 Ruby on Rails 应用程序中存储配置值(密钥、密码或仅配置值)的最佳位置在哪里?我搜索了很多,但没有找到我认为正确的答案。

ruby-on-rails-3

5
推荐指数
1
解决办法
2415
查看次数

Rails和类变量

class MainController < ApplicationController

  @my_var = 123
   def index
    var1 = @my_var
   end

   def index2
    var2 = @my_var
   end
end
Run Code Online (Sandbox Code Playgroud)

为什么两者var1都不var2相等123

ruby

5
推荐指数
1
解决办法
8115
查看次数

在RoR应用程序中使用RSpec进行测试 - 未初始化的常量

我正在尝试通过RSpec测试我的Rails 3.2.3应用程序.它已安装(我已经测试了另一个应用程序并且运行良好)但它在Gemfile中不存在.这是代码spec/application_controller_spec.rb

    require "rspec"
    require_relative "../app/controllers/application_controller"

    describe ApplicationController do
      it "current_cart does something" do
        #app_controller  = ApplicationController.new
        pending
      end
    end
Run Code Online (Sandbox Code Playgroud)

以下命令返回错误:

alex@ubuntu:~/RubymineProjects/psg$ rspec spec
/home/alex/RubymineProjects/psg/app/controllers/application_controller.rb:1:in `<top (required)>': uninitialized constant ActionController (NameError)
    from /home/alex/RubymineProjects/psg/spec/application_controller_spec.rb:2:in `require_relative'
    from /home/alex/RubymineProjects/psg/spec/application_controller_spec.rb:2:in `<top (required)>'
    from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load'
    from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
    from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
    from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
    from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
    from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run'
    from /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'
Run Code Online (Sandbox Code Playgroud)

文件ApplicationController.rb

 class ApplicationController < ActionController::Base
   def some_action
     #............
   end
Run Code Online (Sandbox Code Playgroud)

结束

即使我添加gem 'rspec'Gemfile也不会改变任何内容,错误仍然存​​在.

有什么想法吗?

rspec ruby-on-rails

5
推荐指数
2
解决办法
5564
查看次数

在Mongoid中Upsert

在Mongoid中是否有内置的方法来进行upsert(如果不存在则插入)?或者我应该先检查一个项目是否存在,并且只有在那之后才能进行插入/更新?

ruby upsert mongodb mongoid

5
推荐指数
1
解决办法
4352
查看次数

在尝试安装cms时Bundler :: GemfileNotFound

我在尝试安装CMS时出错.它说Bundler::GemfileNotFound

此外,我跑的bundle时候也说Bundler::GemfileNotFound

我该如何解决?

ruby gem ruby-on-rails bundler

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