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);
        }
Example #2
0
        public void ResetToMemberDefaultValue(string memberName)
        {
            ChoGuard.ArgumentNotNullOrEmpty(memberName, "MemberName");

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

            ResetToMemberDefaultValue(memberInfo);
        }
        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);
            }
        }
        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);
        }