我正在使用C#6.0测试Visual Studio 2015,但语言功能不起作用.在MVC Web应用程序中,以下代码编译:
if (!string.IsNullOrWhiteSpace(Model.Profile?.TypeName))
{
// More logic here...
}
Run Code Online (Sandbox Code Playgroud)
但是,当我通过Debug和IIS Express运行应用程序时,我收到以下错误:
CS1525:无效的表达式术语'.'
如何启用这些功能?
Travis CI持续集成服务正式支持多种语言,但不支持C#或F#.
我可以在我的.net项目中使用它吗?
当.NET Core仍然使用该project.json格式时,您可以构建一个针对多个框架的类库(例如net451,netcoreapp1.0).
既然官方项目格式正在csproj使用MSBuild,那么如何指定要定位的多个框架?我试图寻找这个在VS2017的项目设置,但我能只针对从.NET框架的核心在单一框架(它甚至没有列出我的其他完整的.NET框架版本都已经安装) :
我无法让IIS Express接受我正在开发的VS2010 MVC3项目的安全连接.我可以让它接受端口80上的不安全连接,但不能在端口443上安全.
我基于谷歌搜索采取了以下步骤:
1)通过在VS2010命令行上执行以下操作,找到我的IIS Express Server自签名证书的SHA1指纹:
certmgr.exe /c /s /r localMachine MY
Run Code Online (Sandbox Code Playgroud)
结果是9B088F80 A4FC3141 28F62890 70BA1FC4 49FDD009.后来我才知道我需要在使用指纹时删除空格.
2)通过在提升的命令行提示符下执行以下命令,删除链接到端口443的任何证书:
netsh http delete sslcert ipport=0.0.0.0:443
Run Code Online (Sandbox Code Playgroud)
3)通过在VS2010工具菜单中运行Create GUID生成新的GUID.在我的情况下,我得到了B0421A5B-FF61-47CE-892D-11AA3A9C7D2A.
4)通过在提升的命令行提示符上执行以下命令,将自签名证书安装到端口443:
netsh http add sslcert ipport=0.0.0.0:443 certhash=9B088F80A4FC314128F6289070BA1FC449FDD009 appid={B0421A5B-FF61-47CE-892D-11AA3A9C7D2A}
Run Code Online (Sandbox Code Playgroud)
5)通过从提升的命令行提示符运行以下命令来修改ACL:
netsh http add urlacl url=https://localhost:443/ user=everyone
Run Code Online (Sandbox Code Playgroud)
6)通过为端口443和https协议添加绑定,修改了IIS Express的application.config文件.该文件的网站部分最终看起来像这样:
<sites>
<site name="Development Web Site" id="1" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="%IIS_BIN%\AppServer\empty_wwwroot" />
</application>
<bindings>
<binding protocol="https" bindingInformation="*:443:localhost" />
<binding protocol="http" bindingInformation="*:80:localhost" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
</siteDefaults>
<applicationDefaults …Run Code Online (Sandbox Code Playgroud) 我需要一些简单的字符串加密,所以我写了下面的代码(从这里有很多"灵感" ):
// create and initialize a crypto algorithm
private static SymmetricAlgorithm getAlgorithm(string password) {
SymmetricAlgorithm algorithm = Rijndael.Create();
Rfc2898DeriveBytes rdb = new Rfc2898DeriveBytes(
password, new byte[] {
0x53,0x6f,0x64,0x69,0x75,0x6d,0x20, // salty goodness
0x43,0x68,0x6c,0x6f,0x72,0x69,0x64,0x65
}
);
algorithm.Padding = PaddingMode.ISO10126;
algorithm.Key = rdb.GetBytes(32);
algorithm.IV = rdb.GetBytes(16);
return algorithm;
}
/*
* encryptString
* provides simple encryption of a string, with a given password
*/
public static string encryptString(string clearText, string password) {
SymmetricAlgorithm algorithm = getAlgorithm(password);
byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(clearText); …Run Code Online (Sandbox Code Playgroud) 在与C#库交互时,我发现自己想要Nullable结构和引用类型的C#的空合并运算符.
是否有可能在F#中使用一个内联适当if情况的重载运算符对其进行近似?
如何返回一个json格式的类.
这个方法在控制器中运行很好但是当我想放入一个类时,Json对象似乎不存在.
public JsonResult Test()
{
//Error 1 The name 'Json' does not exist in the current context C:\inetpub\wwwroot\mvcinfosite\mvcinfosite\Validation\ValidationClass\BaseValidator.cs 66 20 mvcinfosite
return Json(new { errMsg = "test" });
}
Run Code Online (Sandbox Code Playgroud)
我想将该代码放在一个简单的类中.我希望能够在许多控制器中调用此方法.
谢谢.
编辑
这是我的班级(代码不起作用的地方)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using mvcinfosite.Models;
using mvcinfosite.Base;
using System.Web.Mvc;
public class BaseValidator
{
public JsonResult Test()
{
return Json(new { errMsg = "test" });
}
}
Run Code Online (Sandbox Code Playgroud) 使用Visual Studio 2017中的新csproj格式,可以非常轻松地构建nuget包.事实上,在项目文件中的属性为您提供了一个gui,您可以输入所有的nuget信息,只需点击一下即可打包.
然而也有在GUI中没有选择建立一个symbols.nupkg包括源和PDB为的NuGet调试服务器.
我如何使用这项新功能在VS2017,仍然创造symbols.nupkg?
我注意到具有必需和方法的新ExpandoObject工具因此应该可以使用集合初始化语法以与向字典添加项目相同的方式向expando对象添加属性.IDictionary<string,object>IEnumerable<KeyValuePair<string, object>>Add(string, object)
Dictionary<string,object> dict = new Dictionary<string,object>()
{
{ "Hello", "World" }
};
dynamic obj = new ExpandoObject()
{
{ "foo", "hello" },
{ "bar", 42 },
{ "baz", new object() }
};
int value = obj.bar;
Run Code Online (Sandbox Code Playgroud)
但似乎没有办法做到这一点.错误:
'System.Dynamic.ExpandoObject'不包含'添加'的定义
我认为这不起作用,因为接口是明确实现的.但有没有办法解决这个问题?这工作正常,
IDictionary<string, object> exdict = new ExpandoObject() as IDictionary<string, object>();
exdict.Add("foo", "hello");
exdict.Add("bar", 42);
exdict.Add("baz", new object());
Run Code Online (Sandbox Code Playgroud)
但是集合初始化器语法更整洁.
我正在寻找一种干净的通用方法的概念来描述XAML FlowDocument中重复的页眉和页脚,而不需要任何代码.它只需要在从C#渲染到XPS时正确显示.