虽然我已经使用Microsoft .NET Framework几年了,但是对于ASP.NET(尤其是ASP.NET WebAPI Framework),我还是一个新手。我正在考虑将ASP.NET WebAPI框架用于一个小项目。
我查看了ASP.NET WebAPI poster,发现一个Controller类可以:
ApiController班级派生,或IHttpController界面阅读该类的MSDN文档ApiController显示该类已实现IHttpController。似乎IHttpController只是声明了一个名为的方法ExecuteAsync()。
我不清楚的是:在什么情况下应该从中派生ApiController或仅实现IHttpController接口的ExecuteAsync()方法?每种方法的优缺点是什么?
考虑以下分析器:
public void AnalyzeNode(SyntaxNode node, SemanticModel semanticModel, Action<Diagnostic> addDiagnostic, CancellationToken cancellationToken)
{
var throwStatement = node as ThrowStatementSyntax;
var isObjectCreationExpression = throwStatement.Expression is ObjectCreationExpressionSyntax;
var obj = throwStatement.Expression as ObjectCreationExpressionSyntax;
var isCorrectTypeOfExpression = (obj.Type as IdentifierNameSyntax).Identifier.Text == typeof(ArgumentException).Name;
}
Run Code Online (Sandbox Code Playgroud)
随着SyntaxKind.ThrowStatement利息的种类.
obj应该是null,如果抛出的异常尚未声明在那里的形式new Exception()而是被呈现为throw e这里e是一个先前声明的除外.
这反过来将抛出NullReferenceException时obj.Type被后立即调用.
有问题的例子:
static void Method1()
{
throw new ArgumentException();
}
static void Method2(ArgumentException e)
{
throw e;
}
Run Code Online (Sandbox Code Playgroud)
第一throw将通过分析器就好,但第二个将导致obj …
我正在使用Xamarin表单,SQLite.net和SQLitenet扩展,我无法弄清楚为什么我希望简单的东西不起作用.
我有两节课
public class MeasurementInstanceModel
{
public MeasurementInstanceModel ()
{
}
[PrimaryKey]
[AutoIncrement]
public int Id {
get;
set;
}
[ForeignKey(typeof(MeasurementDefinitionModel))]
public int MeasurementDefinitionId {
get;
set;
}
[ManyToOne(CascadeOperations = CascadeOperation.CascadeRead)]
public MeasurementDefinitionModel Definition {
get;
set;
}
[ForeignKey(typeof(MeasurementSubjectModel))]
public int MeasurementSubjectId {
get;
set;
}
[ManyToOne(CascadeOperations = CascadeOperation.CascadeRead)]
public MeasurementSubjectModel Subject {
get;
set;
}
public DateTime DateRecorded {
get;
set;
}
[OneToMany(CascadeOperations = CascadeOperation.All)]
public List<MeasurementGroupInstanceModel> MeasurementGroups {
get;
set;
}
}
Run Code Online (Sandbox Code Playgroud)
和
public class MeasurementSubjectModel
{
[PrimaryKey] …Run Code Online (Sandbox Code Playgroud) 我使用了以下XML评论,
/// <example>
/// This example shows how to use <see cref="SampleCollection"/> property.
/// <code>
/// class TestClass
/// {
/// List<string> collection = new List<string>();
/// collection.Add("Column1");
/// collection.Add("Column2");
/// this.SampleCollection = collection;
/// }
/// </code>
/// </example>
public List<string> SampleCollection
{
get;
set;
}
Run Code Online (Sandbox Code Playgroud)
但它有以下警告错误,
关于'SampleCollection'的XML注释格式错误 - '结束标记'代码'与开始标记'字符串'不匹配.
因为List定义有<string>.所以它认为是XML标签.
有什么方法可以解决这个问题吗?
好吧,对于我的C#编程课我正在制作冒险游戏.我想我明白如何做到这一点大多数期待我在设置"世界"时遇到麻烦.
我有一个世界级(World.cs),我开始为每个房间创建一个列表.但是我很困惑为每个房间添加名称和描述.
例如,如果List(房间)是String我会做的类型room.Add("Prison", "This is a prison).做这个的最好方式是什么?
我定义了List这样的:
List<Agahii.Ads> ads = new List<Agahii.Ads>();
Run Code Online (Sandbox Code Playgroud)
然后我想用LINQ查询的结果填充它:
for (int i = 0; i < adid.Count(); i ++ )
{
var dd = adid[i];
var cc = (from a in context.Ads where a.AdID == dd select a).ToList();
ads.Add(cc); // error appears here
};
Run Code Online (Sandbox Code Playgroud)
错误出现在该ads.Add(cc);行中.
错误:System.Collections.Generic.List.Add(Agahii.Ads)的最佳重载方法匹配有一些无效的参数
@using System.Data
@model DataTable
@foreach (var row in Model.Rows)
{
@row[] // how do you cast this to a object?
}
Run Code Online (Sandbox Code Playgroud)
如何使用Razor语法将@row转换为对象?
由于R#不支持Roslyn Early Preview C#6.0功能,代码看起来非常沉闷......
我想使用分类器VSIX对代码着色.是否有可能从Roslyn语言服务获取当前文档的语义模型?
我有一个JSON响应,包含在外部数组中,如下所示:
[
{
"type": "a"
},
{
"type": "b",
"id": 1
},
{
"type": "c",
"name": "somename"
}
]
Run Code Online (Sandbox Code Playgroud)
我试图将此转换为对象,如下所示:
class LoginOptions
{
public IList<ILoginOption> Options { get; set; }
}
interface ILoginOption
{
[JsonProperty("type")]
LoginType LoginType { get; }
}
class LoginOptionA : ILoginOption{
public LoginType LoginType
{
get { return LoginType.A; }
}
}
class LoginOptionB : ILoginOption{
public LoginType LoginType
{
get { return LoginType.B; }
}
[JsonProperty("id")]
public int Id { get; set; }
}
class …Run Code Online (Sandbox Code Playgroud) 从以前的2013更新4安装Visual Studio 2015后,我无法将我的Windows Phone应用程序部署到收到错误0x89721500的设备.
visual-studio windows-phone windows-phone-8.1 visual-studio-2015