小编Mat*_*art的帖子

自定义标记助手无法正常工作

我按照一些指南为ASP Core创建了自定义标记帮助程序.

这是我的帮手:

using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;

namespace ToolControlSystem.TagHelpers
{
    [HtmlTargetElement("description", Attributes = DescriptionAttributeName, TagStructure = TagStructure.NormalOrSelfClosing)]
    public class DescriptionTagHelper : TagHelper
    {
        private const string DescriptionAttributeName = "asp-for";


        [HtmlAttributeName(DescriptionAttributeName)]
        public ModelExpression Model { get; set; }

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            base.Process(context, output);

            var description = GetDescription(Model.ModelExplorer);

            output.TagName = "span";
            output.TagMode = TagMode.StartTagAndEndTag;
            output.Content.SetContent(description);
        }

        private string GetDescription(ModelExplorer modelExplorer)
        {
            string description;
            description = modelExplorer.Metadata.Placeholder;

            if (String.IsNullOrWhiteSpace(description))
            {
                description = modelExplorer.Metadata.Description;
            }

            return description; …
Run Code Online (Sandbox Code Playgroud)

c# model asp.net-core asp.net-core-tag-helpers

24
推荐指数
5
解决办法
6231
查看次数

如何正确检查是否所有表单元素都填充了JavaScript

我有一个表格:

<form action="process.php" method="POST" enctype="multipart/form-data" id="add_prod_form">
Item Name: <input type="text" name="add_prod_name" id="add_prod_name"/><br /><br />
Image 1: <input type="file" name="add_prod_image[]" id="add_prod_image"/><br /><br />
Image 2: <input type="file" name="add_prod_image[]" /><br /><br />
Image 3: <input type="file" name="add_prod_image[]" /><br /><br />
Image 4: <input type="file" name="add_prod_image[]" /><br /><br />
Image 5: <input type="file" name="add_prod_image[]" /><br /><br />
Short description:<br />
<textarea rows="7" cols="50" name="add_prod_description_short" id="add_prod_description_short"/></textarea><br />
Long description:<br />
<textarea rows="7" cols="50" name="add_prod_description_long" id="add_prod_description_long"/></textarea><br /><br />
Price: <input type="text" name="add_prod_price" id="add_prod_price"/><br /><br /> …
Run Code Online (Sandbox Code Playgroud)

html javascript php forms jquery

12
推荐指数
1
解决办法
3473
查看次数

从ReadOnlySequence <byte>获取连续的Memory <byte>

在Marc Gravell 关于这个主题的博客文章中对管道的精彩介绍之后,我正在修补用插座实现管道.

我知道Marc已经提出了Pipelines.Sockets.Unofficial ,我使用它作为参考,但我有一个问题.

似乎该方法SocketAsyncEventArgs有一个新的重载SetBuffer():SetBuffer(Memory<byte>)

看来这里的意图是与Pipes很好地集成.

我的困惑来自于Pipe.Reader.ReadAsync()返回ReadResult包含a ReadOnlySequence<byte>(ReadResult.Buffer)的事实

在这种情况下Buffer.IsSingleSegment == true,很明显该做什么:

SocketAsyncEventArgs.SetBuffer(Buffer[0])

但在有多个细分市场的情况下,我并不完全确定最佳行动方案是什么.

我当然可以byte[]从管道中获取一个并完成它,但这会产生一个副本(可能不止一个,甚至).

ReadOnlySequence<byte>这里的用途是什么?有没有办法让"记忆"代表序列的全部内容?

也许我需要重新阅读Marc的博文......

c# sockets .net-core

7
推荐指数
1
解决办法
1268
查看次数

如何使用支持 IE11 的 babel 启用异步/等待

我希望在我的源代码中使用 async/await 并让 babel 将其转换为>0.25% not dead.

我的脑子里嗡嗡作响,有很多方法可以解决这个问题。有些已被弃用,有些完全不起作用,而我已经开始工作的那个是我图书馆的两倍多。

我试过使用@babel/polyfillwith@babel/plugin-transform-async-to-generator并且效果很好,但库从 ~500kB 到 ~1.1MB。

我也尝试@babel/preset-env通过 give it将它留给它>0.25% not dead,但这并没有什么不同。我得到:

regeneratorRuntime 未定义

我希望有比包括所有这些regeneratorRuntime东西更好的方法来做到这一点......

我宁愿回到厄运的回调金字塔,也不愿运送超过 1mb 的图书馆......

我在用:

  • 网络包 4.41.0
  • 通天塔 7.6.2

javascript async-await internet-explorer-11 babeljs

7
推荐指数
1
解决办法
1万
查看次数

如何在类中包含定义常量的文件(及其范围)

假设我们有以下内容:

some.class.php

class
{
    public __construct()
    {
        fun_stuff();
    }

}
Run Code Online (Sandbox Code Playgroud)

configuration.inc

const SOMECONST = 1;
const SOMEOTHERCONST = 2;
Run Code Online (Sandbox Code Playgroud)

我希望做这样的事情:

some.class.php

class
{
    public __construct()
    {
        include_once(configuration.inc);
        fun_stuff();
    }

}
Run Code Online (Sandbox Code Playgroud)

现在这个工作,但是常量不在class(echo some::SOMECONST;)的范围内定义,而是在全局范围(echo SOMECONST;)中定义

真的很想把常量放在另一个文件中,因为它在我的情况下很有意义.有没有办法在类的范围内声明常量?我知道在课堂定义中使用includes或不可能,requires所以我不知所措.

php oop class constants include

4
推荐指数
2
解决办法
1662
查看次数

创建没有关系的实体

使用 SeaOrm,我想创建一个没有关系的模型。本质上是一个带有一张表的数据库。

这看起来应该非常简单,但是文档没有涵盖这一点,并且DeriveEntityModel宏需要存在实体关系的所有样板。

我想要的是:

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "device")]
pub struct Model {

    #[sea_orm(primary_key)]
    pub id: i32,

    #[sea_orm(column_name = "uuid")]
    pub uuid: Uuid,

    #[sea_orm(column_name = "location")]
    pub location: Option<String>,

    #[sea_orm(column_name = "lastHeard")]
    pub lastHeard: Option<DateTime>
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

cannot find type `Relation` in this scope

help: you might have meant to use the associated type: `Self::Relation`rustc(E0412)
the trait bound `models::device::ActiveModel: sea_orm::ActiveModelBehavior` is not satisfied

the trait `sea_orm::ActiveModelBehavior` is not implemented for `models::device::ActiveModel`
Run Code Online (Sandbox Code Playgroud)

我想必须有另一个宏可以使用,一个不需要关系的宏,但我在文档中找不到它。

orm rust sea-orm

3
推荐指数
1
解决办法
944
查看次数

GitLab Runner 从 gitlab 启动时无法恢复 nuget 包,但在本地启动时可以

我正在尝试使用 gitlab CI 构建和测试 .NET 项目。

我已经下载并安装了最新版本的 GitLab runner,并成功地将它注册到了我们的 gitlab 实例。我创建了以下.gitlab-ci.yaml文件:

variables:
  Solution: Performance-Validation-Tool.sln

stages:
  - build
  - test
#  - deploy

build:
  stage: build
  script:
  - echo "Restoring NuGet packages..."
  - 'C:/nuget/NuGet.exe restore'
  - echo building...
  - 'msbuild.exe "%Solution%"'
  except:
  - tags

test:
  stage: test
  script:
  - echo testing...
  - 'msbuild.exe "%Solution%"'
  - dir /s /b *.Tests.dll | findstr /r Tests\\*\\bin\\ > testcontainers.txt
  - 'for /f %%f in (testcontainers.txt) do mstest.exe /testcontainer:"%%f"'
  except:
  - tags
Run Code Online (Sandbox Code Playgroud)

重要的部分是构建操作。

如果我从 …

continuous-integration nuget gitlab gitlab-ci gitlab-ci-runner

2
推荐指数
1
解决办法
4460
查看次数

ASP Core 2.0 本地化程序找不到资源文件

我有一个想要本地化的 asp 核心应用程序。我会马上进入。

在 startup.cs - ConfigureServices 中:

        services.AddLocalization(options => options.ResourcesPath = "Resources");

        services.AddMvc()
            .AddViewLocalization(opts => 
                { opts.ResourcesPath = "Resources"; })
            .AddDataAnnotationsLocalization();
Run Code Online (Sandbox Code Playgroud)

startup.cs - 配置:

   var supportedCultures = new[]
    {
        new CultureInfo("en"),
        new CultureInfo("fr"),
    };

    app.UseRequestLocalization(new RequestLocalizationOptions
    {
        DefaultRequestCulture = new RequestCulture("en"),
        // Formatting numbers, dates, etc.
        SupportedCultures = supportedCultures,
        // UI strings that we have localized.
        SupportedUICultures = supportedCultures
    });
Run Code Online (Sandbox Code Playgroud)

我的资源文件是有序的。以fr(for HomeController, Homeaction)为例: {root}/Resources/Views/Home/Home.fr.resx

这是一个不起作用的视图:

@using Microsoft.AspNetCore.Mvc.Localization

@inject IViewLocalizer Localizer

@{
    ViewData["Title"] = @Localizer["test"];
} …
Run Code Online (Sandbox Code Playgroud)

c# localization asp.net-core

2
推荐指数
1
解决办法
2699
查看次数

是否可以在 Avalonia 应用程序中创建 Skia Canvas 元素?

我希望将 Electron 应用程序移植到 Avalonia。该应用程序目前使用 Paper.js 来绘制和管理与复杂多边形的交互。查看 Avalonia,我注意到它使用了 Skia,它似乎提供了与 Paper.js 相同的功能。我希望有一种简单的方法来创建 Skia“画布”,并且直接使用 SkiaSharp API。

不幸的是,我没有太多运气找到文档/答案。avalonia gitter 上有人提到我可能会使用 RenderTargetBitmap,但在查看源代码(找不到任何相关文档)后,我认为直接使用 Skia 画布会更容易/更优雅。

这可能吗?

skia skiasharp avaloniaui

2
推荐指数
1
解决办法
1236
查看次数

使用 dotnet new Angular 指定框架版本

我正在尝试在 Linux 上的 VS Code 中创建一个 Angular 项目。我想使用框架版本 2.2(已安装),但我为另一个需要它的项目安装了 3.0 的预览版。

当我运行时dotnet new angular,它默认使用 3.0。好吧,我去手动编辑 csproj。问题是,存在依赖性,特别是

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0-preview4-19216-03" />
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.0.0-preview4-19216-03" />
  </ItemGroup>
Run Code Online (Sandbox Code Playgroud)

我以为我可以更改两个部门的版本,但我错了。3.0之前的版本似乎NewtonsoftJson不存在。

此时,我不确定最好的方法是什么。我不想四处寻找并手动添加正确的依赖项。我真的希望使用 dotnet cli 来创建我的项目。

那么如何指定框架版本呢dotnet new?如果不能,我该如何通过 dotnet CLI 创建一个可用的 angular.js 项目?

.net-core visual-studio-code angular

0
推荐指数
1
解决办法
863
查看次数