当前位置: 首页>>代码示例>>C#>>正文


C# Expression.GetMemberInfo方法代码示例

本文整理汇总了C#中System.Linq.Expressions.Expression.GetMemberInfo方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.GetMemberInfo方法的具体用法?C# Expression.GetMemberInfo怎么用?C# Expression.GetMemberInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Linq.Expressions.Expression的用法示例。


在下文中一共展示了Expression.GetMemberInfo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetNotificationForProperty

        public IObservable<IObservedChange<object, object>> GetNotificationForProperty(object sender, Expression expression, bool beforeChanged = false)
        {
            var iro = sender as IReactiveObject;
            if (iro == null) {
                throw new ArgumentException("Sender doesn't implement IReactiveObject");
            }

            var obs = beforeChanged ? iro.getChangingObservable() : iro.getChangedObservable();

            var memberInfo = expression.GetMemberInfo();
            if (beforeChanged) {
                if (expression.NodeType == ExpressionType.Index) {
                    return obs.Where(x => x.PropertyName.Equals(memberInfo.Name + "[]"))
                        .Select(x => new ObservedChange<object, object>(sender, expression));
                } else {
                    return obs.Where(x => x.PropertyName.Equals(memberInfo.Name))
                        .Select(x => new ObservedChange<object, object>(sender, expression));
                }
            } else {
                if (expression.NodeType == ExpressionType.Index) {
                    return obs.Where(x => x.PropertyName.Equals(memberInfo.Name + "[]"))
                        .Select(x => new ObservedChange<object, object>(sender, expression));
                } else {
                    return obs.Where(x => x.PropertyName.Equals(memberInfo.Name))
                        .Select(x => new ObservedChange<object, object>(sender, expression));
                }
            }
        }
开发者ID:KimCM,项目名称:ReactiveUI,代码行数:28,代码来源:IROObservableForProperty.cs

示例2: GetNotificationForProperty

        public IObservable<IObservedChange<object, object>> GetNotificationForProperty(object sender, Expression expression, bool beforeChanged)
        {
            var before = sender as INotifyPropertyChanging;
            var after = sender as INotifyPropertyChanged;

            if (beforeChanged ? before == null : after == null)  {
                return Observable.Never<IObservedChange<object, object>>();
            }

            var memberInfo = expression.GetMemberInfo();
            if (beforeChanged) {
                var obs = Observable.FromEventPattern<PropertyChangingEventHandler, PropertyChangingEventArgs>(
                    x => before.PropertyChanging += x, x => before.PropertyChanging -= x);

                if (expression.NodeType == ExpressionType.Index) {
                    return obs.Where(x => x.EventArgs.PropertyName.Equals(memberInfo.Name + "[]"))
                        .Select(x => new ObservedChange<object, object>(sender, expression));
                } else {
                    return obs.Where(x => x.EventArgs.PropertyName.Equals(memberInfo.Name))
                    .Select(x => new ObservedChange<object, object>(sender, expression));
                }
            } else {
                var obs = Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>(
                    x => after.PropertyChanged += x, x => after.PropertyChanged -= x);

                if (expression.NodeType == ExpressionType.Index) {
                    return obs.Where(x => x.EventArgs.PropertyName.Equals(memberInfo.Name + "[]"))
                    .Select(x => new ObservedChange<object, object>(sender, expression));
                } else {
                    return obs.Where(x => x.EventArgs.PropertyName.Equals(memberInfo.Name))
                    .Select(x => new ObservedChange<object, object>(sender, expression));
                }
            }
        }
开发者ID:bbqchickenrobot,项目名称:RxUI-UWP-Sample,代码行数:34,代码来源:INPCObservableForProperty.cs

示例3: GetNotificationForProperty

        public IObservable<IObservedChange<object, object>> GetNotificationForProperty(object sender, Expression expression, bool beforeChanged = false)
        {
            if (beforeChanged)
                return Observable.Never<IObservedChange<object, object>>();

            var type = sender.GetType();
            var propertyName = expression.GetMemberInfo().Name;

            var match = config.Keys
                .Where(x=> x.IsAssignableFrom(type) && config[x].Keys.Contains(propertyName))
                .Select(x=> config[x][propertyName])
                .OrderByDescending(x=> x.Affinity)
                .FirstOrDefault();

            if(match == null)
                throw new NotSupportedException(string.Format("Notifications for {0}.{1} are not supported", type.Name, propertyName));

            return match.CreateObservable((NSObject) sender, expression);
        }
开发者ID:journeyman,项目名称:ReactiveUI,代码行数:19,代码来源:UIKitObservableForPropertyBase.cs

示例4: GetNotificationForProperty

        public IObservable<IObservedChange<object, object>> GetNotificationForProperty(object sender, Expression expression, bool beforeChanged = false)
        {
            var obj = sender as NSObject;
            if (obj == null) {
                throw new ArgumentException("Sender isn't an NSObject");
            }
            var propertyName = expression.GetMemberInfo().Name;

            return Observable.Create<IObservedChange<object, object>>(subj => {
                var bobs = new BlockObserveValueDelegate((key,s,_) => {
                    subj.OnNext(new ObservedChange<object, object>(s, expression));
                });
                var pin = GCHandle.Alloc(bobs);

                var keyPath = (NSString)findCocoaNameFromNetName(sender.GetType(), propertyName);

                obj.AddObserver(bobs, keyPath, beforeChanged ? NSKeyValueObservingOptions.Old : NSKeyValueObservingOptions.New, IntPtr.Zero);

                return Disposable.Create(() => {
                    obj.RemoveObserver(bobs, keyPath);
                    pin.Free();
                });
            });
        }
开发者ID:journeyman,项目名称:ReactiveUI,代码行数:24,代码来源:KVOObservableForProperty.cs

示例5: GetNotificationForProperty

        public IObservable<IObservedChange<object, object>> GetNotificationForProperty(object sender, Expression expression, bool beforeChanged = false)
        {
            var ei = default(EventInfo);

            lock (eventInfoCache) {
                ei = eventInfoCache.Get(Tuple.Create(sender.GetType(), expression.GetMemberInfo().Name));
            }

            return Observable.Create<IObservedChange<object, object>>(subj => {
                bool completed = false;
                var handler = new EventHandler((o, e) => {
                    if (completed) return;
                    try {
                        subj.OnNext(new ObservedChange<object, object>(sender, expression));
                    } catch (Exception ex) {
                        subj.OnError(ex);
                        completed = true;
                    }
                });

                ei.AddEventHandler(sender, handler);
                return Disposable.Create(() => ei.RemoveEventHandler(sender, handler));
            });
        }
开发者ID:nestalk,项目名称:ReactiveUI,代码行数:24,代码来源:WinformsCreatesObservableForProperty.cs

示例6: Check

		static MemberInfo Check( Expression<Func<ClassWithParameter, object>> expression ) => expression.GetMemberInfo();
开发者ID:DevelopersWin,项目名称:VoteReporter,代码行数:1,代码来源:ObjectExtensionsTests.cs


注:本文中的System.Linq.Expressions.Expression.GetMemberInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。