属性设置器块未在WCF中按需执行 [英] Property Setter Block not excuting as desired in WCF

查看:62
本文介绍了属性设置器块未在WCF中按需执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在WCF服务类中,我们有一个属性,在该属性的setter块中,我们正在设置另一个属性.请参阅
以下代码段:

Hi,
In our WCF service class we have a property in whose setter block we are setting another property. Please see
the below snippet:

public bool isDirty;
public string title;
       [XmlIgnore]
        public bool IsDirty
        {
            get
            {
                return isDirty;
            }
            set
            {
                isDirty = value;
            }
        }
public string Title
        {
            get { return title; }
            set
            {
                if (value != title)
                {
                    IsDirty = true;
                    title = value;
                }
            }
        }

当我们通过直接Dll引用对其进行测试时,这将正常工作.但是,当通过服务引用对象对其进行测试时,setter块无法按预期工作. IE. IsDirty标志未变为真.

请指教.

[edit]将内联代码转换为代码块-OriginalGriff [/edit]

This is working properly when we have tested it through direct Dll reference. But, when are testing it through service reference object the setter block is not working as expected. I.e. the IsDirty flag is not becoming true.

Please advise.

[edit]Inline code converted to code block - OriginalGriff[/edit]

推荐答案

尝试将您的属性基础字段更改为private:
Try changing your property base fields to private:
public bool isDirty;
public string title;

成为

private bool isDirty;
private string title;

如果这引发任何编译错误,那就是您的问题.

公开财产的财产基础字段从来都不是一个好主意,因为它违背了首先拥有财产的目的.

If this throws up any compilation errors, that is your problem.

It is never a good idea to make the property base field for a property public - it defeats the purpose of having a property in the first place.


这篇关于属性设置器块未在WCF中按需执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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