在VS2015预览版中使用C#6.0,我们有一个新的运算符,?.
可以像这样使用:
public class A {
string PropertyOfA { get; set; }
}
...
var a = new A();
var foo = "bar";
if(a?.PropertyOfA != foo) {
//somecode
}
Run Code Online (Sandbox Code Playgroud)
它到底是做什么用的?
这是一件简单的事情,我很确定它的描述很好,但令人惊讶的是它并不那么明显.
在这里,我找到了设置文件的详细说明.因为它声明它应该是setting.json
文件位置%APPDATA%\Code\User\settings.json
,但在我的情况下,它不存在.
有人可以帮我恢复Visual Studio Code中的默认设置吗?我偶然隐藏了菜单栏,我找不到任何显示它的方法.
在C#中,我们可以根据构建类型区分代码执行.默认情况下,我们定义了Debug和Release类型.
我们可以使用#if
指令来做到这一点:
#if DEBUG
public void Foo()
{ ... }
#endif
Run Code Online (Sandbox Code Playgroud)
但我们也可以使用Conditional
属性:
[Conditional("DEBUG")]
public void Foo()
{ ... }
Run Code Online (Sandbox Code Playgroud)
第二种解决方案甚至声称更易于维护(参见:Bill Wagner的有效C#).
我的问题是 - 如何在Conditional
许多构建配置中使用该属性?有可能以某种方式使用or
运算符吗?我问,因为我希望在例如DEBUG和BAR构建配置中执行一些Foo方法.然后怎样呢?
在新的C#6.0中,我们可以使用lambda表达式定义方法和属性.
例如这个属性
public string Name { get { return First + " " + Last; } }
Run Code Online (Sandbox Code Playgroud)
现在可以定义如下:
public string Name => First + " " + Last;
Run Code Online (Sandbox Code Playgroud)
有关表达式函数成员的信息,请访问:http://blogs.msdn.com/b/csharpfaq/archive/2014/11/20/new-features-in-c-6.aspx
有没有人知道使用新语法时是否有任何开销?它可以减慢(或提高效率)应用程序,或者它可能没关系?
IServiceProvider
是一个单一方法的接口:
object GetService(Type serviceType);
Run Code Online (Sandbox Code Playgroud)
它用于创建在.NET Core本机DI容器中注册的类型的实例.
IServiceProvider
可以通过调用BuildServiceProvider
方法获得自身的实例IServiceCollection
.IServiceCollection
是类中ConfigureServices
方法的参数Startup
.它似乎被IServiceCollection
框架的一个实例神奇地调用.
我想创建一个IServiceProvider
没有Setup
方法的实例.我需要它来解决集成测试程序集中的依赖项.在这种情况下是否有可能获得它?
在TypeScript 手册中,描述了几种导入模块的技术:
import { ZipCodeValidator } from "./ZipCodeValidator";
import { ZipCodeValidator as ZCV } from "./ZipCodeValidator";
import * as validator from "./ZipCodeValidator";
我希望还有一个选择,但我无处可寻.是否可以从给定目录导入所有模块?
我想语法应该或多或少像这样:import * from "./Converters"
.
在Entity Framework 6中引入了AddRange方法.这对于大插入是很好的,因为DbSet.Add方法总是触发DetectChanges,这会极大地减慢进程.当我意识到它没有AddRange方法时,我只想使用一些基于IDbSet接口的现有代码.它仅存在于DbSet类中.
我google了一下,发现了这个讨论 - http://forums.asp.net/t/1978828.aspx?Why+is+there+no+AddRange+method+for+System+Data+Entity+IDbSet+T+ -但是在IDbSet接口中实际存在AddRange方法的原因还没有明确的结论.
这是一个错误还是有一些很好的理由让它不在那里?有任何想法吗?
UPDATE
在这里https://entityframework.codeplex.com/workitem/2781微软给了我一个答案:
这是设计的.接口方法对于DbSet来说不是一个好方法,因为添加成员会破坏任何实现接口的现有应用程序.
鉴于我们希望能够将成员添加到DbSet,我们交换到基类方法,其中DbSet是可以直接模拟或继承的基类.
以下是一些链接,显示如何使用DbSet而不是IDbSet:
我正在尝试在我的一个项目中安装Ninject,并给出确切的版本和项目名称.我正在使用本地托管的包存储库.我在包安装过程中面临以下问题:
PM> Install-Package Ninject -version 3.2.2.0 -project My.Project.Name
Installing 'Ninject 3.2.2.0'.
You are downloading Ninject from Ninject Project Contributors, the license agreement to which is available at https://github.com/ninject/ninject/raw/master/LICENSE.txt. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'Ninject 3.2.2.0'.
Adding 'Ninject 3.2.2.0' to …
Run Code Online (Sandbox Code Playgroud) 让我们在范围上定义简单的布尔值:
var mymodal = angular.module('mymodal', []);
mymodal.controller('MainCtrl', function ($scope) {
$scope.b = false;
});
Run Code Online (Sandbox Code Playgroud)
如何在表达式中获取变量的类型?typeOf
并且Object.prototype.Tostring.call
不工作.
<div ng-controller="MainCtrl" class="container">
<div>
{{ b }}
{{ typeOf(b) }}
{{ Object.prototype.toString.call(b) }}
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是JSFiddle:http://jsfiddle.net/g8Ld80x3/2/
在.NET中有两个AuthorizeAttribute
类.一个在System.Web.Http
命名空间中定义
namespace System.Web.Http
{
// Summary:
// Specifies the authorization filter that verifies the request's System.Security.Principal.IPrincipal.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class AuthorizeAttribute : AuthorizationFilterAttribute
{
// Summary:
// Initializes a new instance of the System.Web.Http.AuthorizeAttribute class.
public AuthorizeAttribute();
// Summary:
// Gets or sets the authorized roles.
//
// Returns:
// The roles string.
public string Roles { get; set; }
//
// Summary:
// Gets a unique identifier for …
Run Code Online (Sandbox Code Playgroud) c# ×5
c#-6.0 ×2
.net-core ×1
angularjs ×1
asp.net ×1
asp.net-mvc ×1
cookies ×1
javascript ×1
nuget ×1
operators ×1
types ×1
typescript ×1