小编Jaz*_*azb的帖子

.NET and .net core share file among projects

We have some .cs files in our project A that are needed in Project B.

First question: how do I share the files across projects without recreating them in the other project?

第二个问题:如果项目 A 是在 中制作的.Net,项目 B 是在 中制作的.NET Core,我们如何共享文件而不需要在两个项目中重新创建它们?

我正在使用 C#

.net c# asp.net-core

5
推荐指数
1
解决办法
2335
查看次数

获取复选框的检查值-物料设计

我有一个页面使用基于基本引导程序的Admin BSB物料设计布局

我很难从此设计的复选框中获取价值。

“已选中”示例复选框:

在此处输入图片说明

在此处输入图片说明

我看到即使没有添加data-cypress="mycheckbx"属性,赛普拉斯也无法找到复选框控件。

所以我的问题是:在这种情况下如何获取“选中”属性?

使用的样式:

[type="checkbox"].filled-in:not(:checked)+label:before {
    width: 0;
    height: 0;
    border: 3px solid transparent;
    left: 6px;
    top: 10px;
    -webkit-transform: rotateZ(37deg);
    transform: rotateZ(37deg);
    -webkit-transform-origin: 20% 40%;
    transform-origin: 100% 100%
}

[type="checkbox"].filled-in:not(:checked)+label:after {
    height: 20px;
    width: 20px;
    background-color: transparent;
    border: 2px solid #5a5a5a;
    top: 0;
    z-index: 0
}

[type="checkbox"].filled-in:checked+label:before {
    top: 0;
    left: 1px;
    width: 8px;
    height: 13px;
    border-top: 2px solid transparent;
    border-left: 2px solid transparent;
    border-right: 2px solid #fff;
    border-bottom: 2px solid #fff;
    -webkit-transform: rotateZ(37deg); …
Run Code Online (Sandbox Code Playgroud)

cypress

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

函数侦听器无法启动。Azure 函数应用时间触发器

当我在本地环境中从 Visual Studio 运行 azure 函数时出现以下错误:

函数“Function1”的侦听器无法启动。Microsoft.WindowsAzure.Storage:错误请求。

这是我的代码

using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace FunctionApp3
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static void Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

配置(即local.settings.json)

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我设置一个 http 触发功能应用程序时,它工作正常。

c# azure-functions

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

在 .net core 中使用带有 graphql 的泛型类

我是GraphQL 的新手,我正在制作一个用于管理学生和课程的小型网站。

在我的应用程序中,我有一个通用类:

public class RangeModel<TFrom, TTo>
    {
        #region Propertes

        public TFrom From { get; set; }

        public TTo To { get; set; }

        #endregion
    }
Run Code Online (Sandbox Code Playgroud)

此类用于定义具有通用数据类型的范围。范围可以是:

RangeModel<double?, double?>

RangeModel<int?, int?>

... 等等。

我尝试制作一个RangeModelType继承的类ObjectGraphType

    public class RangeModelType<TFrom, TTo>: InputObjectGraphType<RangeModel<TFrom, TTo>>
        {
            public RangeModelType()
            {
                Field(x => x.From).Description("Minimum range");
                Field(x => x.To).Description("Maximum range");
            }
        }
Run Code Online (Sandbox Code Playgroud)

并定义我的查询如下:

var studentsQueryArguments = new QueryArguments();
            studentsQueryArguments.Add(new QueryArgument<ListGraphType<IntGraphType>> { Name = "ids", Description = "Student indexes." });
            studentsQueryArguments.Add(new QueryArgument<ObjectGraphType<RangeModelType<double?, double?>>>{Name …
Run Code Online (Sandbox Code Playgroud)

c# .net-core graphql asp.net-core-webapi asp.net-core-2.0

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

DynamoDB无法转换为System.DateTime

我在我的应用程序中使用C#对象持久性模型,并从外部源填充表。我插入具有下列日期行(字符串列)2018-12-12T22:27:14.73Z。这是使用以下Go代码从时间戳生成的:

&dynamodb.AttributeValue{S: aws.String(entity.TimeStamp.UTC().Format("2006-01-02T15:04:05.999Z"))}
Run Code Online (Sandbox Code Playgroud)

但是,当尝试将DynamoDB对象持久性模型转换为时,该模型会System.DateTime出现错误:System.InvalidOperationException: Unable to convert [2018-12-12T22:27:14.73Z] of type Amazon.DynamoDBv2.DocumentModel.Primitive to System.DateTime

如果我让我的服务写一个System.DateTime(使用包含一个DateTime属性POCO),它看起来是这样的:2018-12-19T07:45:36.431Z。我缺少什么使AWS无法正确反序列化我的日期?看起来我以与Amazon相同的格式编写它们?

c# datetime amazon-web-services amazon-dynamodb

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

使用 Ctrl +V 组合键时,是否有方法更新附加到 Blazor 中的输入文本项的绑定变量?

我有这个输入来捕获电话号码。当用户输入数字并按“Enter”键时,会触发“KeyWasPressed”方法并进行一些验证。这按预期工作,但是......

例如,当用户从 Excel 复制并粘贴数字时,变量@Phone不会更新其值,因此当用户按“Enter”键时,验证会发送空值。

@Phone当某些文本粘贴到输入控件时,有没有办法刷新/更新变量?

这是我的代码片段:

<input type="number" class="form-control" @bind="@Phone" @onkeypress="@(async e => await KeyWasPressed(e))" placeholder="Client Phone Number" />

@code {

    string Phone { get; set; }

    private async Task GetClientInfo()
    {
        if(String.IsNullOrWhiteSpace(Phone))
        {
            notificationMessages = $"Add a phone number";
        }
        else
        {
            showSpinner = true;

            clientInfo = await ApiHelper.GetClientInfoByPhone(Phone);           

            if(clientInfo != null)
            {
                var singleViewId = clientInfo?.SingleViewId;
                var customerNumber = clientInfo?.Accounts?.FirstOrDefault().CustomerNumber;
                var status = clientInfo?.Accounts?.FirstOrDefault().Status;
                showClientInformation = true;

                var CrossSell = clientInfo?.Accounts[0]?.CrossSell; …
Run Code Online (Sandbox Code Playgroud)

keypress asp.net-core blazor blazor-server-side

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

带有 React 的 .NET 6 无法连接到 SignalR

我想将 .NET Core 5 React 项目迁移到 .NET 6,但我遇到了 SignalR 的一些问题。

我已按照此Microsoft 文档中的文章一步步使用 .NET 6 实现 SignalR。但我仍然遇到与此处所示相同的错误:SignalR 错误日志

任何帮助将不胜感激。我的代码片段:

程序.cs

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllersWithViews();

builder.Services.AddSignalR();

builder.Services.AddCors(options =>
{
    options.AddDefaultPolicy(
        builder =>
        {
            builder.WithOrigins("https://localhost:44413/")
                .AllowAnyHeader()
                .WithMethods("GET", "POST")
                .AllowCredentials();
        });
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();

app.UseCors();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller}/{action=Index}/{id?}");

app.MapFallbackToFile("index.html");
app.MapHub<ChatHub>("/chatHub");

app.Run();
Run Code Online (Sandbox Code Playgroud)

聊天中心.cs

public class ChatHub : Hub …
Run Code Online (Sandbox Code Playgroud)

c# signalr reactjs asp.net-core .net-6.0

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

收益率返回和"并非所有代码路径返回值"

为什么以下代码:

private static IEnumerable<int> TestYield(bool check)
{
    if (check)
    {
        return 1;
    }
    else
    {
        Console.WriteLine("In the else");
    }
}
Run Code Online (Sandbox Code Playgroud)

产生错误,"并非所有代码路径都返回值".但是,以下代码不会产生相同的错误:

private static IEnumerable<int> TestYield(bool check)
{
    if (check)
    {
        yield return 1;
    }
    else
    {
        Console.WriteLine("In the else");
    }
}
Run Code Online (Sandbox Code Playgroud)

唯一的区别是产量.产生不同的产量不会导致同样的错误?

c# yield-return

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

重写方法是违反 LSP 的唯一方法吗

我一直在寻找代码中的迹象,表明可能会违反里氏替换原则。首先我创建了一个简单的类和另一个继承它的类:

public class Adder
{
    public virtual int Add(int operand1, int operand2)
    {
        return operand1 + operand2;
    }
}

public class AdvancedAdder : Adder
{
}
Run Code Online (Sandbox Code Playgroud)

然后我创建了一个检测 LSP 违规的 UnitTest:

public abstract class AdderUnitTestsBase
{
    protected static Adder Adder;

    [DataTestMethod]
    [DataRow(2, 2, 4)]
    [DataRow(-1, 2, 1)]
    [DataRow(2, -3, -1)]
    [DataRow(0, 0, 0)]
    public void Add_ReturnsCorrectResult(
        int operand1, int operand2, int result)
    {
        Assert.AreEqual(result, Adder.Add(operand1, operand2));
    }
}


[TestClass]
public class AdderUnitTests : AdderUnitTestsBase
{
    [ClassInitialize]
    public static void ClassInit(TestContext context) …
Run Code Online (Sandbox Code Playgroud)

c# oop liskov-substitution-principle

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

如何从bool转换为int?

我的代码看起来像这样:

if (Settings.adp == true)
   App.DB.UpdateIntSetting(SET.Adp, 0);
else
   App.DB.UpdateIntSetting(SET.Adp, 1);
Run Code Online (Sandbox Code Playgroud)

有没有办法通过以某种方式将bool Settings.adp转换为int(0或1)来将其降低到一行

c# int boolean type-conversion

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