小编Dra*_*rop的帖子

如何配置 CsvHelper 以跳过 MissingFieldFound 行

public interface ICsvProductReaderConfigurationFactory
{
    Configuration Build();
}

public class CsvProductReaderConfigurationFactory : ICsvProductReaderConfigurationFactory
{
    private readonly ClassMap<ProductDto> classMap;

    public CsvProductReaderConfigurationFactory(IProductDtoClassMapProvider classMapProvider)
    {
        classMap = classMapProvider.Get();
    }

    public Configuration Build()
    {
        var config = new Configuration
        {
            Delimiter = "\t",
            HasHeaderRecord = true,
            IgnoreQuotes = true,
            MissingFieldFound = (rows, fieldIndex, readingContext) =>
                Log.Warn($"Missing Field Found at line {readingContext.Row}\r\n" +
                         $"Field at index {fieldIndex} does not exist\r\n" +
                         $"Raw record: {readingContext.RawRecord}"),
            BadDataFound = context => 
                Log.Warn($"Bad data found at row {context.Row}\r\n" +
                         $"Raw …
Run Code Online (Sandbox Code Playgroud)

c# csv csvhelper

8
推荐指数
3
解决办法
8749
查看次数

如何在 C# (.NET Core 3.1) 中处理 POST 请求中的 JSON 数据

以前(在 .Net Core 2.1 中)我使用以下方法成功处理了 JSON 数据

[HttpPost]
[Route("sendJsonData")]
public JObject saveTemplate(JObject jsonString)
{

        string templateName = (string)jsonString.SelectToken("templateName");
        string filePathAndName = "D:\\" + "templates\\" + templateName + ".txt";

        using (StreamWriter file = File.CreateText(@filePathAndName))
        {
            JsonSerializer serializer = new JsonSerializer();
            serializer.Serialize(file, jsonString);
        }

    return jsonString;
}
Run Code Online (Sandbox Code Playgroud)

但是当我使用 .Net Core 3.1 创建相同的方法时。它无法正常工作,显示 JObject 出现一些错误。我从下面的代码中得到那个 JSON

onSubmit() {
this.http.post("https://localhost:44350/ReportAPI/sendJsonData", this.surveyForm.value)
            .subscribe(
                data => console.log("success!", data),
                error => console.error("couldn't post because", error)
            );
}
Run Code Online (Sandbox Code Playgroud)

以下是错误(来自邮递员的回复)

{
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "title": "One or more validation errors …
Run Code Online (Sandbox Code Playgroud)

.net c# json angular

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

GridGroupHeaderItem.AggregatesValues 没有 Eval

Telerik 文档中,据说聚合值存储在AggregatesValues. 他们甚至在示例中使用它。

但我觉得无法证明。因为一切都是真实的,直到被证明是错误的......对吧?
让我为您提供一个最小、完整且可验证的示例。所以你可以指出我的错误。

ASP :

<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource" AllowPaging="True" ShowGroupPanel="True">
    <MasterTableView>
        <GroupByExpressions>
            <telerik:GridGroupByExpression>
                <SelectFields>                       
                    <telerik:GridGroupByField FieldAlias="GrpGroupID1" FieldName="GroupID" />
                    <telerik:GridGroupByField FieldAlias="SumCount" FieldName="Count" Aggregate="Sum" />
                </SelectFields>
                <GroupByFields>
                    <telerik:GridGroupByField FieldAlias="GrpGroupID" FieldName="GroupID" HeaderText="" />
                </GroupByFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
        <GroupHeaderTemplate>
            <table>
                <tr>
                    <td>eval GrpGroupID1:</td>
                    <td><%# Eval("GrpGroupID1") %></td>
                    <td> ||| </td>
                    <td>Bind GrpGroupID1:</td>
                    <td><%# ((GridGroupHeaderItem)Container).AggregatesValues["GrpGroupID1"] %></td>
                </tr>
                <tr>
                    <td>eval SumCount:</td>
                    <td><%# Eval("SumCount") %></td>
                    <td> ||| </td>
                    <td>Bind SumCount:</td>
                    <td><%# ((GridGroupHeaderItem)Container).AggregatesValues["SumCount"] %></td>
                </tr>
            </table>
        </GroupHeaderTemplate>
        <Columns>
            <telerik:GridNumericColumn DataField="ID" HeaderText="ID" …
Run Code Online (Sandbox Code Playgroud)

asp.net telerik

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

Linq groupBy以简单/干净的方式组合到List <>

我用这种方法做了一个重构.在我们有很多循环和虚拟代码之前.这是我可以去的,但我想我可以更简单.

我想我可以直接从from*group&select以正确的方式放入列表中.

这可能吗?或者我必须有这个循环?

private IEnumerable<ESMatchDate> groupBydate(IEnumerable<ESMatch> matches)
{
    List<ESMatchDate> lMatchDates = new List<ESMatchDate>();

    if (null != matches && matches.Any())
    {
        var dates = from ESMatch in matches
                group ESMatch by ESMatch.BeginDate.ToShortDateString() into newGroup
                orderby Convert.ToDateTime(newGroup.Key)
                select newGroup;

        foreach (var d in dates)
            lMatchDates.Add( new ESMatchDate 
                { Date = Convert.ToDateTime(d.Key), Matches = d.ToList()} );

    }
    else
        lMatchDates = null;

    return lMatchDates;
}
Run Code Online (Sandbox Code Playgroud)

c# linq group-by

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

自动封装字段重构,“使用字段”和“使用属性”之间的区别?

在Visual Studio 2017上,使用自动封装字段重构工具时有两个选项:

  1. 使用财产
  2. 仍在使用领域

法语菜单的屏幕截图。

我已经在基础课上测试了其他选项:

public class Test_EncapsulateFieldRefactoring_Property
{
    public int id;
    public string name;
}
Run Code Online (Sandbox Code Playgroud)

但是两种选择都给出了相同的结果:

public class Test_EncapsulateFieldRefactoring_Property
{
    private int id;
    private string name;

    public int Id { get => id; set => id = value; }
    public string Name { get => name; set => name = value; }
}
Run Code Online (Sandbox Code Playgroud)

为什么存在这些选择?区别在哪里(在生成的代码中,“用法” *)?



免责声明:

  • 屏幕截图是法国VS上的。因此,选项翻译由我完成,实际选项文本可能有所不同。
  • 我知道字段和属性之间的区别。我检查了很多主题,看是否不是骗子。我可能会错过一个。
  • *,找不到适合的翻译:“使用方式”。但是在这种情况下,as字段和property之间的用法差异并不大,而在菜单选项中。

c# visual-studio

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

C#按列表项按组排序

我有一个列表,其中包含一些BW具有2个 属性的对象,分别为shapequantity

根据preShape值和preQuantity给定的值,我将使用和将每个项目排序。所述优先级为第一,则是第二优先级。我已经对和进行了排序,然后对进行了排序,并取决于和。这样的结果很好:List<BW>preShapepreQuantityshapequantityList<BW>GroupByshapequantitypreShapepreQuantity

  • “预成形”值:MN22
  • “量化前”值:20

 

| shape | quantity|
--------|----------
| MN22  | 20      |
| MN22  | 14      |
| MN11  | 20      |
| MN11  | 10      |
| ANT   | 20      |
| ANT   | 18      |
| ANT   | 16      |
| ANT   | 10      |
Run Code Online (Sandbox Code Playgroud)

但我想这样 …

c# linq lambda

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

.Where(x=&gt; x.listFoos.Count() &gt; 1) 是否计算所有子元素?

给定一个具有 List 类型属性的对象列表:

class Bar{
   public List<Foo> Foos{get;set;}
}
Run Code Online (Sandbox Code Playgroud)

下面的代码会选择所有具有多个 Foo 的栏,计算所有 Foos 吗?
或者它会在 2 Foos 处停止迭代?

var input = new List<Bar>();
var result = input.Where(x=> x.Foos.Count()>1).ToList();
Run Code Online (Sandbox Code Playgroud)

c# linq

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

如何将时间戳转换为日期时间?

我想将纪元转换为人类可读的日期,反之亦然。
我想用C#写一些类似链接的东西。

将 Firefox 中的 place.sqlite 文件中的日期转换为 DateTime。

static void Main(string[] args)
{
    //1540787809621000
    string epoch = "1540787809621000";
}

private string epoch2string(int epoch) {
    return 
        new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
            .AddSeconds(epoch)
            .ToShortDateString(); 
}
Run Code Online (Sandbox Code Playgroud)

int size 不够 我尝试了很长的纪元但不起作用

c# firefox timestamp epoch

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

标签 统计

c# ×7

linq ×3

.net ×1

angular ×1

asp.net ×1

csv ×1

csvhelper ×1

epoch ×1

firefox ×1

group-by ×1

json ×1

lambda ×1

telerik ×1

timestamp ×1

visual-studio ×1