简体   繁体   English

运行 .NET 核心控制台应用程序

[英]Running a .NET Core Console Application

I am trying to create a console app from a project template, but I am running into multiple bugs.我正在尝试从项目模板创建控制台应用程序,但我遇到了多个错误。

Can someone please create a console app and explain what information I need to change in order for it to run?有人可以创建一个控制台应用程序并解释我需要更改哪些信息才能运行它吗? It should be very simple.应该很简单。

Link: https://medium.com/@utterbbq/c-serializing-list-of-objects-to-csv-9dce02519f6b链接: https://medium.com/@utterbbq/c-serializing-list-of-objects-to-csv-9dce02519f6b

Summary:概括:

I am unsure if I am supposed to insert values into these property types or to leave blank.我不确定是否应该将值插入这些属性类型或留空。 I believe this half is similar to filling out a model form?我相信这半部分类似于填写 model 表格?

 void Main()
        {
            var rentInvoiceType = typeof(ClientClass);
            var properties = typeof(ClientClass).GetProperties()
             .Where(n =>
             n.PropertyType == typeof(string)
             || n.PropertyType == typeof(bool)
             || n.PropertyType == typeof(char)
             || n.PropertyType == typeof(byte)
             || n.PropertyType == typeof(decimal)
             || n.PropertyType == typeof(int)
             || n.PropertyType == typeof(DateTime)
             || n.PropertyType == typeof(DateTime?));

For the last half, I am receiving errors under the 'var output' value, 'var delimiter' value, the instance if the 'items' in item, 'null', the value of 'n', and '.Aggregate'.在后半部分,我在“var output”值、“var delimiter”值、item 中的“items”实例、“null”、“n”的值和“.Aggregate”下收到错误。

            var output = “”;
            var delimiter = ‘;’;
            using (var sw = new StringWriter())
            {
                var header = properties
                .Select(n => n.Name)
                .Aggregate((a, b) => a + delimiter + b);

                sw.WriteLine(header);

                foreach (var item in items)
                {
                    var row = properties
                    .Select(n => n.GetValue(item, null))
                    .Select(n => n == null ? “null” : n.ToString())
                .Aggregate((a, b) => a + delimiter + b);

                    sw.WriteLine(row);
                }

                output = sw.ToString();
            }
            return output;

I am receiving errors under the 'var output' value,我在“var output”值下收到错误,

From the example, you need to replace single ( ' ' ) and double ( “ ” ) quotes with ( ' ' ) and ( " " ).从示例中,您需要将单引号 ( ' ' ) 和双引号 ( “ ” ) 替换为 ( ' ' ) 和 ( " " )。

and '.Aggregate'和 '.Aggregate'

Add:添加:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq; // <=

I am unsure if I am supposed to insert values into these property type我不确定是否应该将值插入这些属性类型

Put your values in the class you have defined (not in the 'PropertyType'):将您的值放入您定义的 class 中(不在“PropertyType”中):

var rentInvoice = new RentInvoice()
{
    Car = "Lotus",
    Price = 1234,
    ...
};

the instance if the 'items' in item,如果项目中的“项目”的实例,

And add the class to 'items':并将 class 添加到“项目”:

var items = new List<RentInvoice>();
items.Add(rentInvoice);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Mac或Windows上运行.NET Core Console应用程序 - Running a .NET Core Console Application on Mac or Windows 在没有 .NET Core SDK 的情况下将 ASP.NET Core MVC 作为控制台应用程序项目运行 - Running ASP.NET Core MVC as a Console Application Project without .NET Core SDK .Net Core 控制台应用程序未在 Docker 容器中运行 - .Net Core Console App not running in Docker container 将 .NET Core 控制台应用程序作为服务运行,还是重做? - Running .NET Core console app as a service, or redo? .Net Core 2.0控制台程序在运行`serviceProvider.GetService&#39;时具有空值 <Application> ();`? - .Net core 2.0 console program got null value when running `serviceProvider.GetService<Application>();`? .net core控制台应用程序强类型配置 - .net core Console application strongly typed Configuration .Net核心/控制台应用程序/配置/ XML - .Net Core / Console Application / Configuration / XML 在.NET Core控制台应用程序中使用HttpClient - Using HttpClient with .NET Core Console application .Net core 2.0控制台应用程序的日志记录和配置? - Logging and configuration for .Net core 2.0 console application? 依赖注入网络核心控制台应用程序设置 - Dependency injection net core console application setup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM