小编Ant*_*ony的帖子

T-Sql中是否有三元运算符?

有哪些替代方法可以实现以下查询:

select *  
from table  
where isExternal = @type = 2 ? 1 : 0
Run Code Online (Sandbox Code Playgroud)

t-sql sql-server

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

从对象列表中获取值列表

我有一个简单的课程:

 private class Category
    {
        public int Id { get; set; }
        public string Value { get; set; }
    }  
Run Code Online (Sandbox Code Playgroud)

还有这种类型的对象列表:

 List<Category> Categories;
Run Code Online (Sandbox Code Playgroud)

我需要获取类别列表中的ID列表.有没有比使用for循环更简单的方法:

 List<int> list = new List<int>();
    for (int i = 0; i < Categories.Count; i++)
    {
        list.Add(Categories[i].Id);
    }
Run Code Online (Sandbox Code Playgroud)

提前致谢.

c# linq

18
推荐指数
2
解决办法
5万
查看次数

从DataRow单元解析int

如何从DataRow单元格中解析int值?

Int32.Parse(item["QuestionId"].ToString());
Run Code Online (Sandbox Code Playgroud)

这段代码有效,但看起来太冗长了.还可以处理DBNull值吗?

c#

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

TextBox选择颜色和选择括号颜色

我正在为Universal App(Windows和Windows Phone)设计TextBox控件.我发现选择颜色可以通过'SelectionHighlightColor'属性设置(图片上的蓝色).但不知何故,选择括号似乎保持系统强调颜色(在我的情况下为绿色):

在此输入图像描述

如何设置括号颜色或重新定义强调色?

更新:

我试图重新定义许多主题画笔和颜色,例如:

((SolidColorBrush)Resources["PhoneAccentBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0xFF);
Run Code Online (Sandbox Code Playgroud)

(Resources["PhoneAccentColor"]) = Color.FromArgb(0xFF, 0x00, 0xFF, 0xFF);
Run Code Online (Sandbox Code Playgroud)

这确实重新定义了重音,但没有任何东西对括号产生影响.他们仍然是绿色的......

c# xaml windows-8.1 windows-phone-8.1 win-universal-app

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

Windows Phone 8中应用程序栏的本地化

我希望本地化我在App.xaml中制作的App Bar,但是当我尝试绑定条形项目的文本时,它说文本不能为空,我尝试了本地化应用程序栏的其他示例,但它们都没有用于app栏,可以在所有页面上使用..

c# xaml windows-phone windows-phone-8

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

在ItemTemplate上设置属性

当它声明为:时,我可以在PivotItem上设置Margin属性:

<phone:Pivot Margin="50,0,50,0">
    <phone:PivotItem Margin="0">
        <TextBlock>Text</TextBlock>
    </phone:PivotItem>
</phone:Pivot>
Run Code Online (Sandbox Code Playgroud)

但是当我使用绑定时如何设置边距:

<phone:Pivot Margin="50,0,50,0">
    <phone:Pivot.ItemTemplate>                    
        <DataTemplate>
            <TextBlock Text="{Binding Body}"/>
        </DataTemplate>
    </phone:Pivot.ItemTemplate>
</phone:Pivot>
Run Code Online (Sandbox Code Playgroud)

如何在DataTemplate上设置保证金?

xaml windows-phone-8

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

应该何时将操作标记为异步?

我在mvc 4 app中有一个控制器动作:

public ActionResult Index()
    {
        GetStartedModel gsModel = new GetStartedModel();

        return View(gsModel);
    }
Run Code Online (Sandbox Code Playgroud)

和ViewModel:

public class GetStartedModel
{
    public IEnumerable<SelectListItem> listA { get; set; }
    public IEnumerable<SelectListItem> listB { get; set; }

    public GetStartedModel()
    {
        TestDataWebServiceHelper service = new TestDataWebServiceHelper();
        this.GetData(service);
    }

    private async void SetData(TestDataWebServiceHelper service)
    {
        listA = await this.SetListA(service);
        listB = await this.SetListB(service);
    }

    private async Task<IEnumerable<SelectListItem>> SetListA(TestDataWebServiceHelper service)
    {
        List<String> rawList = new List<String>();
        rawList = await service.GetValuesAsync("json");
        return rawList.Select(x => new SelectListItem { …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc async-await

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

从依赖注入配置进行依赖调用

我的需要是注入 HttpClient 并立即可供使用。但需要注意的是 HttpClient 需要设置Authorization标头,为此我需要再进行一次调用以获取令牌。我设法在启动的 RegisterServices 中完成所有这些配置,但我怀疑这是否是一个好主意。

services.AddHttpClient("OidcClient", (isp, client) =>
{
    var options = isp.GetRequiredService<IOptions<MyConfig>>().Value;
    client.BaseAddress = new Uri(options.OidcUrl);
});

services.AddHttpClient("MyClient", (isp, client) =>
{
    var options = isp.GetRequiredService<IOptions<MyConfig>>().Value;
    var oidcClient = isp.GetRequiredService<IHttpClientFactory>().CreateClient("OidcClient");
    var data = new Dictionary<string, string>
    {
        {"client_id", options.ClientId},
        {"client_secret", options.ClientSecret}
    };

    var request = new HttpRequestMessage(HttpMethod.Post, "/connect/token") { Content = new FormUrlEncodedContent(data) };
    var response = oidcClient.SendAsync(request).Result;

    var token = response.Content.ReadFromJsonAsync<TokenResponse>().Result;

    client.BaseAddress = new Uri(options.Url);
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Token);
});
Run Code Online (Sandbox Code Playgroud)

然后它被正确地注入到我的代码中,我可以使用带有授权标头的客户端。

所以,我的担忧是: …

c# dependency-injection dotnet-httpclient .net-core .net-5

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