我使用静态方法来处理我真正想要静态的事情。我使用 ReSharper 来提高代码质量。有时 ReSharper 建议可以将方法设为静态。
当我上以下课时:
public class WhatEverClass {
private string DoSomethingFancy(string input)
{
string fancyStuff;
// Fancy Stuff here
return fancyStuff;
}
public WhatEverClass() {
string awesome=DoSomethingFancy("some fancy string");
}
}
Run Code Online (Sandbox Code Playgroud)
ReSharper 可能会说“DoSomethingFancy 可以变为静态”。
我知道它可以变成静态的,但是真的有充分的理由这样做吗?或者我应该忽略这些建议?
我错误地把错误的构造函数放在ActionLink
:
@Html.ActionLink("Show Customer", "Load", "Customer", new {Model.Id });
Run Code Online (Sandbox Code Playgroud)
错误是,最后一个参数是类型htmlAttributes
而不是routeValues
(如预期的那样).所以正确的构造函数应该是:
@Html.ActionLink("Show Customer", "Load", "Customer", new {Model.Id }, null);
Run Code Online (Sandbox Code Playgroud)
所以我不需要解决这个问题......我只是想知道,当我使用错误的构造函数时,我的routeValue必须被解释为htmlAttribute
.
我很惊讶它导致了一个length
参数.生成的代码是:
/客户/负载?长度= 7
只是出于好奇:它length=7
来自哪里?
我尝试为我的数据编写一个 json 模式。数据看起来是这样的:
{
"gold": [
{
"id": "goldOne",
"name": "firstGold",
"title": "Gold 1 earned"
},
{
"id": "goldTwo",
"name": "secondGold",
"title": "Gold 2 earned"
}
],
"silver": [
{
"id": "silberOne",
"name": "firstSilver",
"title": "Silver!"
}
],
"bronze": [
{
"id": "bronzeOne",
"name": "firstBronze",
"title": "Bronze!"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我已经为“黄金”数组创建了架构:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title" : "trophy descriptions",
"type": "object",
"properties": {
gold: {
"description": "gold trophies",
"type":"array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "unique …
Run Code Online (Sandbox Code Playgroud) Github 问题可能包含一段时间的“反应”(如此处所述:https : //github.com/blog/2119-add-reactions-to-pull-requests-issues-and-comments)
我想使用 Github api 接收该信息,但在遇到问题时似乎没有类似的东西,例如
api.github.com/repos/twbs/bootstrap/issues/19575
Run Code Online (Sandbox Code Playgroud)
该信息似乎不在该响应中。此外,我没有找到可以检索该信息的另一个 API 调用。如何得到这些“反应”?
我使用“经典”Pulumi.Azure 创建应用程序服务:
var appservice=new AppService(appserviceName, new AppServiceArgs
{
Name = appserviceName,
Location = _resourceGroup.Location,
AppServicePlanId = _servicePlan.Id,
ResourceGroupName = _resourceGroup.Name,
SiteConfig = new Pulumi.Azure.AppService.Inputs.AppServiceSiteConfigArgs
{
DotnetFrameworkVersion = "v5.0",
ScmType = "None",
},
Tags = { { "environemnt", "dev" } },
Logs = new AppServiceLogsArgs
{
HttpLogs = new AppServiceLogsHttpLogsArgs
{
FileSystem = new AppServiceLogsHttpLogsFileSystemArgs { RetentionInDays = 14, RetentionInMb = 35 }
}
}
,
AppSettings = appSettings
});
Run Code Online (Sandbox Code Playgroud)
我还创建了一个密钥库:
var currentConfig=Output.Create(GetClientConfig.InvokeAsync());
var keyVault = new KeyVault(vaultname, new KeyVaultArgs
{ …
Run Code Online (Sandbox Code Playgroud) 我有以下HTML:
<div class="wrapper">
<div class="countme"> </div>
<div class="countme"> </div>
<div class="countme"> </div>
<div class="stophere"> </div>
<div class="whatever"> </div>
<div class="countme"> </div>
<div class="countme"> </div>
<div class="countme"> </div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想在任何其他课程出现之前知道countme div 的数量.$('.countme').length
不起作用,因为当我期望的结果当然应该是3时它给出了6的结果.
我正在使用锁定机制来确保两个并行调用不会更新同一行,从而导致意外行为。所以我的代码是这样的:(没有现实世界的例子)
public class UserController {
public ActionResult AddReputation(int id, int repAmount) {
int lockWait=0;
bool alreadyLocked=true;
while (alreadyLocked) {
alreadyLocked=GetLockForUser(id);
Thread.Wait(1000);
lockWait++;
if (lockWait>10) {
return new HttpStatus(xxx);
}
}
SetlockForUser(id);
AddUserRep(id,repAmount);
return new Content("Well Done");
}
}
Run Code Online (Sandbox Code Playgroud)
所以。如果10秒后锁仍然存在,我想告诉调用者“请稍后再试,其他人只是在为该用户保存数据”。
REST-API 中最好的 HTTP 代码是什么?
409 Conflict
?或者423 Locked
?
注意:这不是 SQL-DB。我没有可以使用的真正的交易机制。所以我必须实现自己的锁定机制。
我有以下 html 代码
<div class="magicbullets">
Nice
awesome
cool
</div>
Run Code Online (Sandbox Code Playgroud)
我需要它表现得像
<div class="magicbullets">
<ul>
<li>nice</li>
<li>aweseome</li>
<li>cool</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我可以环绕<ul></ul>
内容,但我不能逐行修改内容本身(nice、awesome、cool)。我只需要选择使用 CSS 来实现我想要的。
我设法创建了所需的新行
.magicbullets {
white-space: pre-line;
}
Run Code Online (Sandbox Code Playgroud)
对于每个条目,但list-style-type
没有列表就无法真正工作。
总结一下,它应该是这样的:
这是使用纯 CSS可行还是需要某种客户端代码(JS、jQuery)或服务器代码(PHP)?
我使用以下(标准)-Pulumi - 代码来创建一个简单的资源:
public MyStack()
{
var current = Output.Create(GetSubscription.InvokeAsync());
this.CurrentSubscriptionDisplayName = current.Apply(current => current.DisplayName);
// Create an Azure Resource Group
var resourceGroup = new ResourceGroup("dingdongdiehexisttot"); // TODO: Conf
// Create an Azure Storage Account
var storageAccount = new Account("storage", new AccountArgs
{
ResourceGroupName = resourceGroup.Name,
AccountReplicationType = "LRS",
AccountTier = "Standard"
});
// Export the connection string for the storage account
this.ConnectionString = storageAccount.PrimaryConnectionString;
}
Run Code Online (Sandbox Code Playgroud)
这会失败并显示 403,因为它是在不允许我在其中创建资源的订阅中创建的。我有多个订阅,并且想要定义要使用的订阅。我可以使用“GetSubscription”检索当前内容,但没有找到任何方法来实际设置要使用的订阅。
如何定义要使用的订阅
(我在runnung pulumi up之前使用成功登录az login
)
我使用 AzureNextGen 创建一个 CosmosDB/DocumentDB - 帐户:
var databaseAccount=new Pulumi.AzureNextGen.DocumentDB.Latest.DatabaseAccount(accountName,
new Pulumi.AzureNextGen.DocumentDB.Latest.DatabaseAccountArgs
{
// parameters
}
);
Run Code Online (Sandbox Code Playgroud)
为了之后能够访问该数据库,我需要检索该数据库帐户的key
或connection string
:
我可以通过构建连接字符串的第一部分(端点), databaseAccount.DocumentEndpoint.Apply(q => "AccountEndpoint=" + q)
但我无法获取更关键的部分,即密钥。
如何才能实现这一目标?
c# ×5
azure ×3
pulumi ×3
jquery ×2
asp.net-mvc ×1
css ×1
dom ×1
github ×1
github-api ×1
http ×1
json ×1
jsonschema ×1
razor ×1
resharper ×1
static ×1