This project has moved. For the latest updates, please go here.
1

Resolved

1.4.3 在设置控件事件时任然有些问题

description

如果控件的某个事件没有设置ScriptVisibleAttribute属性,将导致其在设置后无法使用SetProperty修改为NULL(即移出事件的绑定)。

测是代码使用的示例程序CLREvent,未修改任何参数。
1.4.3
static class PropertyAccessHelper
{
...
    internal static void SetProperty(ScriptContext context, object target, string identifier, object value)
{
...
                        // remove event if property value is set to null
                        if (value == null && srm.AllowCLREvent)
                        {
                            EventInfo ei = type.GetEvent(memberName, BindingFlags.Instance | BindingFlags.Public);

                            var sva = ei == null ? null : (ScriptVisibleAttribute)ei.GetCustomAttributes(
                                typeof(ScriptVisibleAttribute), true).FirstOrDefault();
                            if (sva != null && ei != null && (string.IsNullOrEmpty(sva.Alias)
                                || sva.Alias.Equals(identifier, StringComparison.CurrentCultureIgnoreCase)))
                            {
                                srm.DetachEvent(target, ei);
                                processed = true;
                            }
                        }
...
}
...
}

comments

niijyeni wrote Apr 23, 2014 at 4:05 AM

目前我的处理方式如下,可暂时解决问题
//var sva = ei == null ? null : (ScriptVisibleAttribute)ei.GetCustomAttributes(
// typeof(ScriptVisibleAttribute), true).FirstOrDefault();
//if (sva != null && ei != null && (string.IsNullOrEmpty(sva.Alias)
// || sva.Alias.Equals(identifier, StringComparison.CurrentCultureIgnoreCase)))
if (ei != null)

unvell wrote Apr 23, 2014 at 7:28 AM

感谢指出问题,应该是1.4.3版本(可能更早版本)增加ScriptVisible功能时的一个错误。
被你注释掉的代码应该被删掉,不是很确定,目前暂时注释掉。
如果还有问题请随时联系!
(为了共享信息,下面用英语)

Thanks for pointing out this issue.
This is a problem which might be caused by adding ScriptVisible feature in 1.4.3 or earlier versions.
The code you commented out there should be removed.

The fixed code has been submitted. Thanks a again!
Please let me know if you have other problems!

cheers, Jing