本文整理汇总了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));
}
}
}
示例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));
}
}
}
示例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);
}
示例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();
});
});
}
示例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));
});
}
示例6: Check
static MemberInfo Check( Expression<Func<ClassWithParameter, object>> expression ) => expression.GetMemberInfo();