小编Mat*_*ágl的帖子

ResharperUltimate - 禁用ReSpeller

如何从Visual Studio中的resharper选项中禁用此插件?让我疯狂,我已取消选中所有复选框,resharper->options->ReSpeller但它仍然坚持用绿色强调每一个字符串(用捷克语写).
提前致谢.

resharper

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

从Azure函数中的local.settings.json中读取自定义设置

我试图从local.settings.json文件中检索自定义设置.示例我正在尝试读取以下local.settings.json文件中的表列表

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true",
    "TableList": "TestTableName1,TestTableName2"
  }
}
Run Code Online (Sandbox Code Playgroud)

使用以下代码阅读它

string tableslist = ConfigurationManager.AppSettings["TableList"];
Run Code Online (Sandbox Code Playgroud)

并且它有效,但我在一些地方读过,这只适用于本地调试,在生产环境中部署之后可能无效.有人能指出我如何以正确的方式做到这一点?或者问题仅适用于连接字符串相关的设置?

c# azure azure-functions

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

如何在异步C#任务中使用yield

我试图使用yield并返回在异步任务中将X转换为Y的结果.但是,我在选择时收到错误.错误是:

错误CS1942 select子句中表达式的类型不正确.在"选择"调用中类型推断失败.

public async Task<Result<dynamic>> GetYAsync(IEnumerable<X> infos)
    {
        return Task.WhenAll(from info in infos.ToArray() select async ()=>
        {
            yield return await new Y(info.Id, "Start");
        });
    }
Run Code Online (Sandbox Code Playgroud)

c# asynchronous yield task

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

无法隐式转换类型'Microsoft.AspNetCore.Mvc.BadRequestObjectResult'

我有一个asp.net core 2.1项目,并且在控制器操作中遇到以下错误:

无法将类型“ Microsoft.AspNetCore.Mvc.BadRequestObjectResult”隐式转换为“ System.Collections.Generic.IList”。存在显式转换(您是否缺少演员表?)

这是我的代码:

[HttpPost("create")]
[ProducesResponseType(201, Type = typeof(Todo))]
[ProducesResponseType(400)]
public async Task<IList<Todo>> Create([FromBody]TodoCreateViewModel model)
{
    if (!ModelState.IsValid)
    {
        return BadRequest(ModelState);   // This is the line that causes the intellisense error
    }

    await _todoRepository.AddTodo(model);
    return await GetActiveTodosForUser();
}


[HttpGet("GetActiveTodosForUser")]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
public async Task<IList<Todo>> GetActiveTodosForUser(string UserId = "")
{
    if (string.IsNullOrEmpty(UserId))
    {
        UserId = HttpContext.User.FindFirstValue(ClaimTypes.Sid);
    }
    return await _todoRepository.GetAll(UserId, false);
}
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

c# asp.net .net-core

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

在编译时替换 const 值

我正在寻找一种在编译时读取文件内容并用它替换 const 值的方法:

public class MyClass {
  
 [LoadFromFile("/myFile.txt")]
 public const string MyConst = "";

}
Run Code Online (Sandbox Code Playgroud)

这将读取相对于工作目录的目录中的文件内容myFile.txt(可能使用File.ReadAllText或其他任何内容),该文件的内容可以是例如:

Hello world
Run Code Online (Sandbox Code Playgroud)

并且在编译后的汇编中将MyClass.MyConst返回Hello world.

研究引导我访问https://github.com/Fody/Fody并进行“组装编织”。您将如何解决这个问题?是否还有其他现成可用的解决方案?我正在使用.NET 5。

c#

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