FileHelpers-创建一个字段对象 [英] FileHelpers - Creating a field object

查看:48
本文介绍了FileHelpers-创建一个字段对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将字段属性动态添加到我也使用FileHelpers.Dynamic.DelimitedClassBuilder动态构建的记录类中.创建类对象没有问题,目前我使用AddField(String)方法添加字段.

I am trying to dynamically add field properties to a record class that I am also building dynamically using FileHelpers.Dynamic.DelimitedClassBuilder. I have no issues creating the class object and I currently add a field using the AddField(String) method.

随着我的应用程序的发展,我现在需要在各种情况下声明特定的字段属性.因此,从同样的意义上讲,我想使用FileHelpers.Dynamic.DelimitedFieldBuilder创建一个字段对象,然后使用AddField(DelimitedFieldBuilder)方法将其传递给我的DelimitedClassBuilder对象.

As my apps grows I now have a need to declare specific field properties in various situations. So in the same sense I wanted to use FileHelpers.Dynamic.DelimitedFieldBuilder to create a field object and then pass that to my DelimitedClassBuilder object using the method AddField(DelimitedFieldBuilder).

但是,我无法使用FileHelpers.Dynamic.DelimitedFieldBuilder实例化新对象.发出以下代码时,我收到一条错误消息,指出DelimitedFieldBuilder不包含带有两个参数的构造函数.

However I am unable to instantiate a new object using FileHelpers.Dynamic.DelimitedFieldBuilder. When I issue the following code I get an error stating that DelimitedFieldBuilder does not contain a constructor that takes two arguments.

FileHelpers.Dynamic.DelimitedFieldBuilder fb = new FileHelpers.Dynamic.DelimitedFieldBuilder("ClassName", "Type");

查看文档,该类似乎仅具有关联的属性有了它,所以我对如何真正实现这一目标有些困惑.似乎应该相当容易,但我似乎无法弄清楚.感谢您的帮助.

Looking at the documentation it appears that this class does only have properties associated with it, so I am kind of stuck on how to actually implement this. It seems like it should be fairly easy but I cant seem to figure it out. Thanks for any help.

推荐答案

DelimitedFieldBuilder 内部,因此您在使用该方法时会遇到困难.但是, AddField(String)返回一个 DelimitedFieldBuilder ,因此您可以使用它.

The constructors of DelimitedFieldBuilder are internal so you'll run into difficulty with your approach. However AddField(String) returns a DelimitedFieldBuilder, so you might be able to use that.

创建自己的类 MyFieldBuilder 可能会更容易,该类调用标准的 AddField(String).

It might be easier to make your own class MyFieldBuilder which calls the standard AddField(String).

这篇关于FileHelpers-创建一个字段对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆