當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。