小编Bla*_*ell的帖子

在c#中创建只适用于特定类型的泛型函数

我正在尝试创建一个处理我的两个模型之一的通用函数.请注意,这两个模型都具有相同的确切属性...

例如,在下面的代码中,即使"NewProduct"和"OldProduct"都具有此属性,智能感知也不知道在T中存在名为Price的属性.如何向VS指定我希望能够传入的两种类型?IList<NewProduct>, IList<OldProduct>

public static IList<T> GenericFunction<T>(IList<T> objList)
{
    IList<T> filteredData = objList.Where(p => p.Price > 0));
}
Run Code Online (Sandbox Code Playgroud)

c# generics generic-collections

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

没有使用ASP.NET Core Angular Spa项目JavaScriptServices的Guard提供程序

我收到错误: 没有AuthGuard提供商!

如果AuthGuard未在app.module中注册,通常会发生这种情况.在这种情况下,我在app.module.shared.ts中注册了它

最新的JavaScriptServices Angular模板将app.module拆分为3 - app.module.shared.ts,app.module.client.ts,app.module.server.ts这可能就是为什么它表现得很奇怪.

还有什么可能导致此错误发生吗?我相信它只发生在这个新的JavaScriptServices模板中,而不是一个vanilla Angular项目.

javascript asp.net typescript asp.net-core angular

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

使用 Razor 页面在 ASP.NET Core MVC 中使用处理程序设置 Kendo UI Grid DataSource Read 属性

我正在使用带有 Razor Pages Web 应用程序的 ASP.NET Core MVC 套件的 Kendo UI,因此我尝试将处理程序技术用于网格的服务器操作。

@(Html.Kendo().Grid<CustomerViewModel>()
        .Name("CustomersGrid")
        .Columns(columns =>
        {
            columns.Bound(x => x.CustomerId).Title("Student ID");
            columns.Bound(x => x.CustomerName).Title("Name");
        })
        .Pageable()
        .Sortable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .ServerOperation(true)
            .Read(read => read.Url("/Customers?handler=Read")))
         )
Run Code Online (Sandbox Code Playgroud)

我查看了网络选项卡,它正在向http://localhost:5000/Customers?handler=Read发出正确的 POST但是我没有在断点处结束,我得到了一个状态代码 400。

在剃刀页面的 Action 方法后面的代码中,它被命名为 OnPostReadAsync

知道为什么这不起作用吗?除了 .Url 之外,还尝试在 DataSource 的 .Read 属性中使用 read.Action 和 read.Route。

这是带有 action 方法的类:

public class IndexModel : PageModel
{
    private readonly ICustomerRepository _customerRepository;
    private readonly IMapper _mapper;

    public IndexModel(ICustomerRepository customerRepository, IMapper mapper)
    {
        _customerRepository = …
Run Code Online (Sandbox Code Playgroud)

c# kendo-ui-mvc kendo-ui-grid asp.net-core razor-pages

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

Moment.js startOf 返回一天的结束时间

我通过查询字符串传递以下日期:2020-09-23

我试图找出为什么上面带有“不起作用”注释的下面的代码不起作用。

// If figure here I should only have to convert to a moment once
const momentDate = moment.utc(req.query.dateTime);

// Doesn't work
const startOfDay = momentDate.startOf('day');
const endOfDay = momentDate.endOf('day');
Run Code Online (Sandbox Code Playgroud)

这就是我得到的:
console.log(startOfDay) = Moment<2020-09-23T23:59:59Z>
console.log(endOfDay) = Moment<2020-09-23T23:59:59Z>

// Works (when I directly pass in the query string param)
const startOfDay = moment.utc(req.query.dateTime).startOf('day');
const endOfDay = moment.utc(req.query.dateTime).endOf('day');
Run Code Online (Sandbox Code Playgroud)

console.log(startOfDay) = 时刻<2020-09-23T00:00:00Z>
console.log(endOfDay) = 时刻<2020-09-23T23:59:59Z>

node.js express momentjs

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

使用Resharper更改VS2015名称中C#属性的颜色

我有Visual Studio 2015和ReSharper.我目前正在使用默认的Dark Theme.但是,我想让属性名称为紫色.

在YouTube上观看此视频,了解我要查找的内容.(56:37)或整个视频的任何地方.

例如:

var userId = User.Identity.GetUserId();
Run Code Online (Sandbox Code Playgroud)

我希望'User.Identity'以白色以外的颜色显示.

我假设唯一可能的方法来改变属性的颜色是使用ReSharper,但我无法弄清楚如何在工具>选项>字体和颜色屏幕.

c# resharper visual-studio visual-studio-2015

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

在 Angular 中一个接一个地同步调用 observable

我有以下服务调用可用:
productService.GetAllProducts()
productService.DeleteProduct()
productService.GetCategories()
productService.DeleteCategory()

在 sudo 代码中,我需要在我的组件中执行以下操作:

  1. 使用 productService.GetAllProducts() 获取产品列表。

  2. 遍历产品列表并为每个产品调用 productService.DeleteProduct()。

  3. 一旦我可以确认上述删除都已完成(由于数据库约束),我需要使用 productService.GetCategories() 获取类别列表。循环遍历每个类别并调用 productService.DeleteCategory()。

我知道如果我有更好的后端调用来进行批量删除,我的生活会容易得多,但在这种情况下我别无选择。我需要遵循获取列表的模式,循环遍历它,对每个项目单独删除一个。

甚至可以使用 flatMap 和可观察的完整参数来做我想做的事情吗?我最大的问题是在搜索和删除所有类别之前知道代码何时完成删除所有产品。

rxjs typescript angular

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

从 Angular 父组件传递到子组件的数据在子组件中未定义

我有一个父组件将信息传递给子组件,但它是未定义的。如果这是 Angular 101,我很抱歉,但是如何延迟子组件渲染或运行任何 javascript,直到它获得所需的输入?

拉取数据的父组件 ngOnInit:

public ngOnInit(): void {
     this.productService.getProductById(1).subscribe(product => {
            this.product = product;
        });
}
Run Code Online (Sandbox Code Playgroud)

父组件 HTML:

<child-component [product]="product" id="myProduct"></child-component>
Run Code Online (Sandbox Code Playgroud)

子组件输入声明:

@Input() public product: Product;
Run Code Online (Sandbox Code Playgroud)

子组件 ngOnInit 需要产品存在:

public ngOnInit(): void {
     // It is returning as undefined
     console.log(this.product);
}
Run Code Online (Sandbox Code Playgroud)

javascript angular

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

嵌套任务的C#代码运行速度比相同代码慢,而顶层只有Tasks

我遇到了一个问题,其中场景1的运行速度比场景2慢,尽管场景1似乎应该运行得更快,因为它不仅在更高级别打开任务,而且在内部级别打开.有点像父子概念(我知道父/子实际上并没有发生,因为我认为任务都在同一级别运行).场景2只是在更高级别创建任务,并且整体运行得更快.我唯一能想到的是,运行较少的任务会更快,因此可以并行处理所有内容,而不是尝试打开更多可能导致等待4核(8线程)CPU的任务.

我试图弄清楚场景2是否总是会更快,或者是否有更好的方法来编码场景1,以便它实际上比场景2更快.

场景1(嵌套任务):

public void MainFunction() {
    IList<Task<ProductMaster>> tasks = new List<Task<ProductMaster>>();
    foreach (var x in products) 
    {
        Task<ProductMaster> prodMaster = Task.Factory.StartNew<ProductMaster>(() => RunProductMasterCode(param1, param2));

        tasks.Add(prodMaster);   
    }

    foreach (Task<ProductMaster> tsk in tasks)
    {
        ProductMaster prodMaster = tsk.Result;
        // COMPLEX CODE HERE THAT RELIES ON tsk.Result
    }
}

public ProductMaster RunProductMasterCode(int param1, int param2) {
    IList<Task<ProductSub>> tasks = new List<Task<ProductSub>>();
    foreach (var x in subProducts) 
    {
        Task<ProductSub> prodSub = Task.Factory.StartNew<ProductSub>(() => RunProductSubCode(param1));

        tasks.Add(prodSub);
    }

    foreach (Task<ProductSub> tsk in tasks)
    {
        ProductSub …
Run Code Online (Sandbox Code Playgroud)

c# performance multithreading asynchronous async-await

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

防止 DocuSign 文本选项卡在其他文本选项卡中输入相同的文本

我向文档添加了 3 个单独的文本选项卡的列表(名字、姓氏、电话号码),但是当用户签名时,如果他们填写了名字字段,则其余文本字段将填写相同的信息。我需要设置什么属性才能使每个文本字段唯一并防止这种情况发生?

c# docusignapi

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

将用户Steam ID从控制台转换为C#中的64位版本

我正在创建一个应用程序,用户可以在其中粘贴用户的Steam ID在搜索框中。在大多数情况下,它将是游戏控制台中的Steam ID,看起来像:STEAM_1:0:12345678。我需要将其转换为64位版本,以便向该用户发出Steam API的请求。

这里有很多有用的信息:https : //developer.valvesoftware.com/wiki/SteamID

但是我仍然不知道如何转换为64位。

c# steam-web-api steam steamworks-api

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

扩展 CrudRepository 并仍然使用 Spring Data JPA 为自定义方法创建自己的实现

我有一个存储库接口,它扩展了 CrudRepository 以自动为我提供所有基本的 crud 存储库功能。

public interface CustomerRepository extends CrudRepository<Customer, Integer> {
}
Run Code Online (Sandbox Code Playgroud)

我还能添加自定义存储库功能并实现此接口吗?

java spring spring-data-jpa

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

使用c#中的加号和减号将十进制格式化为货币

有没有办法格式化小数,使其显示为带有+或 - 符号的货币?

例如:

+ $ 5.00(大于零的加号)
$ 0.00(零没有符号)
- $ 5.00(减号小于零)

以下是我想要的但不确定如何合并货币:

var formattedprice = $"{price:+0;-#}"
Run Code Online (Sandbox Code Playgroud)

我通常使用C0作为货币或N0作为数字.

c#

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

使用管道和地图在Angular HttpClient帖子的响应上运行逻辑

我打电话给我的Web API登录.该调用返回一个JSON对象,该对象具有一个名为token的属性.

在我的AuthService中,我有以下功能:

  login(model: any) {
    return this.http.post('http://localhost:5000/api/auth.login', model, httpOptions).pipe(map((response: Response) => {
      console.log(response);
      if (response) {
        // localStorage.setItem('token', jwtHelper.decodeToken(response.token));
        // this.decodedToken = jwtHelper.decodeToken(response.token);
        // this.userToken = response.token;
      }
    }));
  }
Run Code Online (Sandbox Code Playgroud)

以下是console.log响应的样子:

{token: "eyJhbGciOiJIUzXxMiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiO…CDNojrJEwmuIbLOjhCxzDwls22SA4Whpklh7zPFaR6g_1iQcQ"}
Run Code Online (Sandbox Code Playgroud)

我可以让这个函数没有返回调用它的组件,但为了在本地存储和一些其他属性中设置令牌,我使用管道,然后映射.它是否正确?我尝试访问它时,response.token会抛出一个错误,因为typescript不知道响应中的token属性.

observable rxjs angular

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