예제 #1
0
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            MemberInfo memberInfo = ChoTypeMembersCache.GetMemberInfo(_type, binder.Name);

            if (memberInfo == null)
            {
                return(false);
            }

            try
            {
                object newConvertedValue = ChoConvert.ConvertFrom(_instance, value, ChoType.GetMemberType(memberInfo), ChoTypeConvertersCache.GetTypeConverters(memberInfo));
                ChoType.SetMemberValue(_instance, memberInfo, newConvertedValue);
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                return(false);
            }

            if (!(_instance is INotifyPropertyChanged))
            {
                PropertyChangedEventHandler propertyChanged = PropertyChanged;
                if (propertyChanged != null)
                {
                    propertyChanged(this, new PropertyChangedEventArgs(binder.Name));
                }
            }
            return(true);
        }
예제 #2
0
        public void ResetToMemberDefaultValue(string memberName)
        {
            ChoGuard.ArgumentNotNullOrEmpty(memberName, "MemberName");

            MemberInfo memberInfo = ChoTypeMembersCache.GetMemberInfo(GetType(), memberName);

            ResetToMemberDefaultValue(memberInfo);
        }
예제 #3
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;
            MemberInfo memberInfo = ChoTypeMembersCache.GetMemberInfo(_type, binder.Name);

            if (memberInfo != null)
            {
                result = ChoType.GetMemberValue(_instance, memberInfo);
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #4
0
        public override bool TrySetMember(SetMemberBinder binder, object value)
        {
            MemberInfo memberInfo = ChoTypeMembersCache.GetMemberInfo(_type, binder.Name);

            if (memberInfo == null)
            {
                return(false);
            }

            string propertyName = ChoType.GetMemberName(memberInfo);

            object newConvertedValue = null;

            try
            {
                newConvertedValue = ChoConvert.ConvertFrom(value, memberInfo, _instance);
                //           newConvertedValue = ChoConvert.ConvertFrom(_instance, value, ChoType.GetMemberType(memberInfo),
                //ChoTypeDescriptor.GetTypeConverters(memberInfo), ChoTypeDescriptor.GetTypeConverterParams(memberInfo));
                ChoType.SetMemberValue(_instance, memberInfo, newConvertedValue);
            }
            catch (ChoConfigurationObjectPostInvokeException)
            {
            }
            catch (ChoFatalApplicationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                if (_instance.RaiseConfigurationObjectMemberLoadError(binder.Name, propertyName, value, ex))
                {
                    _instance.OnPropertyChanged(binder.Name);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            _instance.OnPropertyChanged(binder.Name);
            return(true);
        }