public object HandleCall(MethodInvocation call) { IProxy proxy = (IProxy)call.Target; InterceptedParameter stateParam = (InterceptedParameter)call.Parameters [0]; IContext ctx = (IContext)stateParam.Value; proxy.SetInterceptor(ctx.Interceptor); if (proxy.GetInterceptor() == null) { call.Proceed(); return(null); } else { bool cancel = false; proxy.GetInterceptor().NotifyInstantiatingObject(call.Target, ref cancel); if (!cancel) { call.Proceed(); } proxy.GetInterceptor().NotifyInstantiatedObject(call.Target); return(null); } }
private object HandleGetProperty(MethodInvocation call) { IProxy proxy = (IProxy)call.Target; string propertyName = call.Method.Name.Substring(4); //object value = call.Proceed(); object value = null; bool cancel = false; Puzzle.NPersist.Framework.Interfaces.IInterceptor interceptor = proxy.GetInterceptor(); if (interceptor != null) { interceptor.NotifyPropertyGet(call.Target, propertyName, ref value, ref cancel); } if (cancel) { return(value); } //if (cancel) {return GetDefaultValue(call.ReturnType);} value = call.Proceed(); if (interceptor != null) { interceptor.NotifyReadProperty(proxy, propertyName, ref value); } return(value); }
private void InitProperties() { Type baseType = target.GetType().BaseType; PropertyInfo[] propertyArray = baseType.GetProperties(); properties.Clear(); IProxy proxy = (IProxy)target; IContext context = proxy.GetInterceptor().Context; foreach (PropertyInfo property in propertyArray) { if (property.PropertyType.IsInterface) { continue; } if (!property.CanWrite) { continue; } IClassMap classmap = context.DomainMap.GetClassMap(property.PropertyType); if (classmap != null) { continue; } properties[property.Name] = property; } }
private object HandleSetProperty(MethodInvocation call) { IProxy proxy = (IProxy)call.Target; bool cancel = false; object value = ((InterceptedParameter)call.Parameters[0]).Value; string propertyName = call.Method.Name.Substring(4); object refValue = value; #if NET2 IPropertyChangedHelper propertyChangedObj = (IPropertyChangedHelper)proxy; propertyChangedObj.OnPropertyChanging(propertyName); #endif Puzzle.NPersist.Framework.Interfaces.IInterceptor interceptor = proxy.GetInterceptor(); if (interceptor != null) { interceptor.NotifyPropertySet(call.Target, propertyName, ref refValue, ref cancel); } if (cancel) { return(null); } ((InterceptedParameter)call.Parameters[0]).Value = refValue; call.Proceed(); #if NET2 propertyChangedObj.OnPropertyChanged(propertyName); #endif return(null); }
private IInterceptor GetInterceptor() { if (target != null) { IProxy proxy = target as IProxy; if (proxy != null) { return(proxy.GetInterceptor()); } } return(null); }
private object HandleSetProperty(MethodInvocation call) { IProxy proxy = (IProxy)call.Target; bool cancel = false; object value = ((InterceptedParameter)call.Parameters[0]).Value; string propertyName = call.Method.Name.Substring(4); object refValue = value; #if NET2 IPropertyChangedHelper propertyChangedObj = (IPropertyChangedHelper)proxy; propertyChangedObj.OnPropertyChanging(propertyName); #endif Puzzle.NPersist.Framework.Interfaces.IInterceptor interceptor = proxy.GetInterceptor(); if (interceptor != null) { interceptor.NotifyPropertySet(call.Target, propertyName, ref refValue, ref cancel); } if (cancel) { return(null); } IContext context = null; if (interceptor != null) { context = interceptor.Context; } object oldValue = null; if (context != null) { oldValue = context.ObjectManager.GetPropertyValue(call.ExecutionTarget, propertyName); } else { oldValue = call.ExecutionTarget.GetType().GetProperty(propertyName).GetValue(call.ExecutionTarget, null); } ((InterceptedParameter)call.Parameters[0]).Value = refValue; call.Proceed(); #if NET2 propertyChangedObj.OnPropertyChanged(propertyName); #endif if (interceptor != null) { interceptor.NotifyWroteProperty(call.Target, propertyName, refValue, oldValue); } return(null); }
public static object GetProperty(IProxy proxy, string propertyName, Type propertyType, object refValue) { #if NPDEBUG Console.Write(propertyType.ToString()); #endif bool cancel = false; IInterceptor interceptor = proxy.GetInterceptor(); if (interceptor.Notification != Notification.Disabled) { if (interceptor != null) { interceptor.NotifyPropertyGet(proxy, propertyName, ref refValue, ref cancel); } if (cancel) { return GetDefaultValue(propertyType); } if (interceptor != null) { interceptor.NotifyReadProperty(proxy, propertyName, refValue); } } return refValue; }
public static object GetProperty(IProxy proxy, string propertyName, Type propertyType, object refValue) { #if NPDEBUG Console.Write(propertyType.ToString()); #endif bool cancel = false; IInterceptor interceptor = proxy.GetInterceptor(); if (interceptor.Notification != Notification.Disabled) { if (interceptor != null) { interceptor.NotifyPropertyGet(proxy, propertyName, ref refValue, ref cancel); } if (cancel) { return(GetDefaultValue(propertyType)); } if (interceptor != null) { interceptor.NotifyReadProperty(proxy, propertyName, refValue); } } return(refValue); }