指的是在初始化过程中被初始化的对象? [英] Refer to an object being initialized within the initialization?

查看:47
本文介绍了指的是在初始化过程中被初始化的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个委托方法的对象DataParameterInfo(DPI),这些委托方法用于将数据从DataReader移入POCO或从POCO中获取值.

I have an object DataParameterInfo (DPI) with a couple of delegate methods that are used to move data from a DataReader into a POCO or to get values out of the POCO.

示例:

new DataParameterInfo<IBulletinPCN>
{
    FieldName = "ChangeProcedure",
    ParameterName = "@ChangeProcedure",
    EntityName = "ChangeProcedure",
    DataType = SqlDbType.NVarChar,
    FieldType = FieldType.Other,
    PopulateEntity = (dr, e) => e.ChangeProcedure = dr.IsDBNull(dr.GetOrdinal("ChangeProcedure")) ? null : dr.GetString(dr.GetOrdinal("ChangeProcedure")),
    ReadEntity = e => e.ChangeProcedure
}

我希望 像这样在PopulateEntity委托中引用我的DPI的Fieldname属性:

I would like to refer to the Fieldname property of my DPI within the PopulateEntity delegate like such:

    PopulateEntity = (dr, e) => e.ChangeProcedure = dr.IsDBNull(dr.GetOrdinal(FieldName)) ? null : dr.GetString(dr.GetOrdinal(FieldName)),

或者也许

    PopulateEntity = (dr, e) => e.ChangeProcedure = dr.IsDBNull(dr.GetOrdinal(this.FieldName)) ? null : dr.GetString(dr.GetOrdinal(this.FieldName)),

当我尝试时,仅"this"是指创建DPI的类,而不是DPI本身.

Only the "this" when I try that refers to the class in which the DPI is being created, not the DPI itself.

我可以做上面想做的事情,如果可以,怎么做?

Can I do what I'm trying, above, and if so, how?

推荐答案

您可以通过更改代理的调用者,将字段名作为参数传递给代理:

You can pass the fieldname to your delegate as a parameter by changing the caller of that delegate:

例如:

PopulateEntity = (dr, e, fieldname) => e.ChangeProcedure = dr.IsDBNull(dr.GetOrdinal(fieldname)) ? null : dr.GetString(dr.GetOrdinal(fieldname))

在执行该委托时,您说:

and in the point where you execute that delegate you say:

PopulateEntity(dr, e, this.fieldname);

这篇关于指的是在初始化过程中被初始化的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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