小编Sha*_*aun的帖子

在C#代码中分隔大数字的数字

在C++中,您可以使用撇号将数字中的数字与可读性分开:

int num = 1'000'000;
Run Code Online (Sandbox Code Playgroud)

在Ruby中,您可以使用下划线:

num = 1_000_000
Run Code Online (Sandbox Code Playgroud)

C#有类似的语法吗?我尝试了一些不同的搜索,但只提出了以特定格式输出或读取数字的结果.

c#

21
推荐指数
1
解决办法
1336
查看次数

TypeScript在RxJS定义中找不到名称IPromise

我正在使用typings导入类型定义和gulp-typescript运行TypeScript编译器.当我运行我的TypeScript任务时,我得到一些关于RxJS类型中使用的IPromiseIDisposable类型的警告:

typings/main/ambient/rx/index.d.ts(34,20): error TS2304: Cannot find name 'IPromise'.
typings/main/ambient/rx/index.d.ts(36,29): error TS2304: Cannot find name 'IPromise'.
typings/main/ambient/rx/index.d.ts(49,36): error TS2304: Cannot find name 'IDisposable'.
typings/main/ambient/rx/index.d.ts(51,22): error TS2304: Cannot find name 'IPromise'.
typings/main/ambient/rx/index.d.ts(53,19): error TS2304: Cannot find name 'IPromise'.
typings/main/ambient/rx/index.d.ts(55,36): error TS2304: Cannot find name 'IPromise'.
typings/main/ambient/rx/index.d.ts(57,33): error TS2304: Cannot find name 'IPromise'.
Run Code Online (Sandbox Code Playgroud)

我假设有一个RxJS依赖的另一个打字库,但是当我安装定义时没有指定.我添加了RxJS类型

typings install --save --ambient rx
Run Code Online (Sandbox Code Playgroud)

安装文件开头的注释rx/index.d.ts表示它适用于RxJS v2.5.3,即使RxJS现在已达到版本4.但据该报道,图书馆去年更新了typings search --ambient rx,所以我假设这只是过时的评论.

我需要什么样的其他类型定义,还有其他一些方法可以找到它而不仅仅是问这里吗?

rxjs typescript

10
推荐指数
1
解决办法
2556
查看次数

引用没有名称的类以在 TypeScript 的子类中使用不同的静态方法

在 ES6 中,您可以通过this.constructor以下方式引用静态方法:

class MainClass {
  static info() {
    return "This is some information";
  }
  constructor() {
    this.info = this.constructor.info(); // Allows subclass to define different '.info()' method.
  }
}

class ChildClass extends MainClass {
  static info() {
    return "This information is from the child";
  }

  constructor() {
    super();
  }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法在 TypeScript 中做到这一点?我希望能够覆盖超类的静态方法并从子类中使用它,而无需在实例方法中重新定义引用。现在,我知道如何在 TypeScript 中访问静态方法的唯一方法是使用类名。

MainClass.info();
Run Code Online (Sandbox Code Playgroud)

但是如果我这样做,子类将继续使用MainClass.info();而不是它自己的.info()方法。

typescript typescript1.8

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

ASP.NET MVC 5支持生命周期/生命终结

我正在MVC 5中开始一个新项目,我需要让我的团队估计微软将支持MVC 5多长时间.我查看了ASP.NET支持生命周期策略,其中说"支持策略将是支持当前版本和以前的版本." 然后它只列出5.x,我认为这意味着他们将.NET Core 1.x作为当前版本.这是否意味着一旦.NET Core 2.0发布,他们将放弃对MVC 5的支持?根据.NET核心路线图,.NET Core 2.0预计将于2017年第三季度发布.如果他们在此时提供"12个月通知",则表示对MVC 5的支持将于2018年第三季度结束.

这使得它仅比"主流"MVC 4支持多6个月,这与Visual Studio 2012支持相关,并于2014 年1月9日结束.扩展支持直到2012年1月10日才结束.如果MVC 5与Visual Studio 2015相关联,主流支持将在2020年结束并在2025年扩展支持.

有谁知道我在哪里可以找到更多关于MVC 5支持结束日期的确切信息?我知道ASP.NET Core MVC可以使用完整的.NET框架,而且我已经花了很多精力学习.NET Core.但在这种情况下,我真的能够使用MVC 5更快地发布.

更新:我阅读了很多文章,如评论中提到的文章,当地社区的人们通常建议使用.NET Core进行任何新项目.但是,当我亲自问人们是否正在使用.NET Core时,我从未听过有人说他们在生产中使用它.我知道有人在生产中使用它并且可以在完整的.NET框架中使用它,但它仍然缺少MVC 5具有的许多工具,功能,第三方库和文档.我承认,如果我更擅长C#和.NET,我可能会处理这些问题.文章建议可以随时提供12个月的MVC 5支持通知.如果真的如此,我不确定我能否在C#/ .NET上出售我的团队.

.net c# asp.net-mvc asp.net-mvc-5

6
推荐指数
0
解决办法
2695
查看次数

使用 TypeScript 通用接口

我有几种类型的对象,如文章、部门、个人资料等。我为每个对象定义了一个接口,基本上:

interface IArticle {
    title: string;
    body: string;
}

interface IProfile {
    name: string;
    email: string;
}

interface IDivision {
    name: string;
    leader: IProfile;
}
Run Code Online (Sandbox Code Playgroud)

现在,在某些情况下,我希望能够在formTitle显示表单的页面上使用这些属性时添加属性。我以为我可以做这样的事情:

// Failed
interface IForm<T> {
    formTitle: string;
}

function formDisplay(resource: IForm<IProfile>) { }
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,我收到一个错误,指示对象属性(nameemail,在这种情况下)不存在于类型IForm<IProfile>。所以我想这不是泛型的正确使用。来自 Ruby 和 JavaScript,我对整个静态类型仍然是新手。

为了解决这个问题,我一直在为每个对象编写单独的接口,如下所示:

// Not reusable
interface IArticleForm extends IArticle {
    formTitle: string;
}
Run Code Online (Sandbox Code Playgroud)

我能想到的另一种选择是向基本接口添加一个可选属性,然后从那里扩展常规对象接口。

// Does not provide helpful type checking
interface IBase {
    formTitle?: string;
}
interface IArticle extends …
Run Code Online (Sandbox Code Playgroud)

typescript

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

Capybara with RSpec - 选择框选项

我将 Capybara 2.4.3 与 Rspec-Rails 3.1.0、Ruby 2.1.5 和 Rails 4.1.8 一起使用。该测试仍然失败:

let(:attack_squad) { create :squad, user: attacker, name: 'Attack Squad' }

scenario 'attacker has available attack squad' do
  visit '/account/battles/new'
  save_and_open_page
  expect(page).to have_select 'Squad', options: [attack_squad.name]
end
Run Code Online (Sandbox Code Playgroud)

使用save_and_open_page,我可以看到正在生成此 HTML:

<select id="battle_squad_id" name="battle[squad_id]">
  <option value="194">Attack Squad</option>
  <option value="192">Default Squad</option>
</select>
Run Code Online (Sandbox Code Playgroud)

这是失败消息:

 Battle Management attacker has available attack squad
 Failure/Error: expect(page).to have_select 'Squad', options: [attack_squad.name]
   expected to find select box "Squad" with options ["Attack Squad"] but there were no matches. …
Run Code Online (Sandbox Code Playgroud)

ruby rspec ruby-on-rails capybara

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