我使用 ASP.net Core 和 swagger,创建了以下方法和详细文档:
/// <summary>Creates a package with the requested information.</summary>
/// <param name="createPackage">The package information to create.</param>
/// <response code="201" cref="PackageCreatedExample">Created</response>
/// <returns><see cref="PackageCreated"/> package created.</returns>
[HttpPost]
[SwaggerResponse(201, "Package created", typeof(PackageCreated))]
[SwaggerResponse(400, "Validation failure", typeof(ApiErrorResult))]
[SwaggerResponseExample(201, typeof(PackageCreatedExample))]
public async Task<IActionResult> CreatePackage(PackageCreate createPackage)
{
if (!ModelState.IsValid)
{
return BadRequest(new ApiErrorResult(ModelState));
}
var createdPackageInfo = new PackageCreated();
// Created item and location returned.
return CreatedAtAction(nameof(GetPackage), new { createdPackageInfo.Id, Version = "2" }, createdPackageInfo);
}
Run Code Online (Sandbox Code Playgroud)
我试图获取一个以 swagger 形式出现的示例响应,但它总是默认响应示例,如下所示:
正如您从上面的代码中看到的,我创建了一个“PackageCreatedExample”类,我希望在 swagger …
我需要以编程方式(在 C# 中)打开或关闭特定段落的悬挂缩进。
我创建了一个加载项,其中有一个按钮,单击该按钮后,我(尝试)执行此操作的代码。它是一个切换开关,因此第一次单击会添加悬挂缩进,第二次单击应将其删除。
在Word中,它是Paragraph>Indentation中的设置,后跟设置“ Special ”等于None或Hanging。
我对此的最佳尝试是使用以下代码:
foreach (Footnote rngWord in Globals.OSAXWord.Application.ActiveDocument.Content.Footnotes)
rngWord.Range.ParagraphFormat.TabHangingIndent(
rngWord.Range.ParagraphFormat.FirstLineIndent == 0 ? 1 : -1);
Run Code Online (Sandbox Code Playgroud)
它仅出于某种原因修改该段落的最后一行。我需要它是除第一行之外的所有挂起的行。我究竟做错了什么?
修改:
注意 - 我实际上是在文档中的脚注上执行此操作。
我以我对 ReactJs 非常陌生并且可能试图解决一些非常基本的问题这一事实作为序言。
我有一段带有自定义 HTML 的代码:
示例组件
const Sample = ({ title, children }) => {
return (
<div class="panel">
<div class="title">
{title}
</div>
<div class="body">
{children}
</div>
</div>
);
};
Run Code Online (Sandbox Code Playgroud)
附带问题 - 以上的正确名称是什么?一个片段?它看起来不是一个“组件”,而只是学习 React 的命名约定
利用组件
export default class ExampleComponent extends Component {
render() {
return <div class="page-body">
<div class="row">
<h1> Page 1 </h1>
<Sample title={<h1>Some title!</h1>}>
<p>This is my sample body!</p>
</Sample>
</div>
</div>
}
}
Run Code Online (Sandbox Code Playgroud)
使用示例组件的理想方式
export default class ExampleComponent extends Component {
render() …Run Code Online (Sandbox Code Playgroud) 我正在使用 EF Core 和 .NET 6,我想将一个实体更新插入到表中 - 这是一个相当简单的问题。
我有以下代码:
var countries = GetCountries();
using (var scope = scopeFactory.CreateScope())
{
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
foreach (var c in countries)
{
// check if the country already exists.
var exists = dbContext.Countries.Where(d => d.Id == c.Id).FirstOrDefault();
// if already exists - update (rather than add).
if (exists != null)
{
exists.Name = c.Name;
exists.DisplayName = c.DisplayName;
... // omitted other prop updates.
dbContext.Countries.Update(exists);
}
else
{
dbContext.Countries.Add(c);
}
}
await dbContext.SaveChangesAsync();
} …Run Code Online (Sandbox Code Playgroud) 我有一个场景,我有三个数字:
我需要将它们转换为整个百分比值(这样当添加时,总计100%就像你期望的那样).我有这个功能:
function roundPercentageTotals(num1, num2, num3) {
var total = num1 + num2 + num3; // 117
var num1Total = (num1 / total) * 100; // 14.529914529914531
var num2Total = (num2 / total) * 100; // 8.547008547008546
var num3Total = (num3 / total) * 100; // 76.92307692307693
var num1ToDecimal = num1Total.toFixed(1); // 14.5
var num2ToDecimal = num2Total.toFixed(1); // 8.5
var num3ToDecimal = num3Total.toFixed(1); // 76.9
var totalPercentage = parseInt(num1ToDecimal) + parseInt(num2ToDecimal) + parseInt(num3ToDecimal); // 98
return { …Run Code Online (Sandbox Code Playgroud) 我在 VSTS 中有一个构建,如下所示:
您可以从屏幕截图中看到“测试并生成代码覆盖率”的测试步骤。它使用这个命令:
/p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)\TestResults\Coverage\coverage
这允许生成代码覆盖率报告。我已经使用我定义的特征(例如集成或单元)将“类别”添加到我的 xUnit 测试中,以允许我在构建/发布期间过滤测试。示例是:
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit.Abstractions;
using Xunit.Sdk;
/// <summary>
/// Decorates a test as a Unit Test, so that it runs in Continuous Integration builds.
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public sealed class IsUnitAttribute : AICategoryAttribute
{
/// <summary>
/// Initializes a new instance of <see cref="IsUnitAttribute"/>
/// </summary>
public IsUnitAttribute() : base("Unit") { }
}
/// <summary>
/// Decorates a test as an Integration Test, so …Run Code Online (Sandbox Code Playgroud) testing code-coverage xunit.net reportgenerator azure-pipelines-build-task
我正在尝试在 ASP.net MVC 应用程序之外使用 DataAnnotation 属性验证。理想情况下,我想在我的控制台应用程序中采用任何模型类并将其装饰如下:
private class MyExample
{
[Required]
public string RequiredFieldTest { get; set; }
[StringLength(100)]
public int StringLengthFieldTest { get; set; }
[Range(1, 100)]
public int RangeFieldTest { get; set; }
[DataType(DataType.Text)]
public object DataTypeFieldTest { get; set; }
[MaxLength(10)]
public string MaxLengthFieldTest { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后(伪)做这样的事情:
var item = new MyExample(); // not setting any properties, should fail validation
var isValid = item.Validate();
Run Code Online (Sandbox Code Playgroud)
我在网上的一个示例中找到了这段代码:
var item = new MyExample(); // not setting any …Run Code Online (Sandbox Code Playgroud) 我将以下 JSON 保存在文件“test.json”中:
{
"metadata": [
{
"src": [
{
"files": [
"src/**.csproj"
]
}
],
"dest": "api",
"disableGitFeatures": false,
"disableDefaultFilter": false
}
]
}
Run Code Online (Sandbox Code Playgroud)
我想修改“src”元素。代替:
"src": [
{
"files": [
"src/**.csproj"
]
}
],
Run Code Online (Sandbox Code Playgroud)
它必须是:
"src": [
{
"files": [
"*.csproj"
],
"cwd":".."
}
],
Run Code Online (Sandbox Code Playgroud)
我修改“文件”的第一个元素并添加“cwd”。这应该是直截了当的,但我正在努力在 powershell 中实现这一目标。任何人都可以指出我正确的方向吗?
感谢您提前提供任何指示。
在c#中有一种快速的方法可以用更高效的代码替换以下内容:
string letters = "a,b,c,d,e,f";
if (letters.Contains("a"))
{
return true;
}
if (letters.Contains("b"))
{
return true;
}
if (letters.Contains("c"))
{
return true;
}
Run Code Online (Sandbox Code Playgroud)
我想取消必须有三行比较代码.
谢谢!
c# ×5
javascript ×2
.net-6.0 ×1
asp.net-core ×1
asp.net-mvc ×1
components ×1
html ×1
json ×1
linq ×1
math ×1
modelstate ×1
ms-word ×1
paragraph ×1
percentage ×1
powershell ×1
reactjs ×1
rounding ×1
string ×1
swagger ×1
swagger-ui ×1
testing ×1
tofixed ×1
validation ×1
xunit.net ×1