Ejemplo n.º 1
0
 /// <summary>
 /// Called when a property <c>set</c> method is intercepted and executes before the method body.
 /// </summary>
 /// <param name="e">The interception event arguments.</param>
 /// <exception cref="InvalidOperationException">The object has been frozen and cannot receive updates</exception>
 /// <remarks>
 /// The value of the <see cref="PropertyInterceptionArgs.Value" /> property will be populated with the
 /// updated value which has been assigned during the set operation.
 /// </remarks>
 public void OnSet(PropertyInterceptionArgs e)
 {
     if (IsFrozen)
     {
         throw new FrozenException("The object has been frozen and cannot receive updates");
     }
 }
        /// <summary>
        /// Called when a property <c>set</c> method is intercepted and executes before the method body.
        /// </summary>
        /// <param name="e">The interception event arguments.</param>
        /// <remarks>
        /// The value of the <see cref="PropertyInterceptionArgs.Value" /> property will be populated with the
        /// updated value which has been assigned during the set operation.
        /// </remarks>
        public void OnSet(PropertyInterceptionArgs e)
        {
            var ignored = e.Property.GetCustomAttribute <IgnoreChangingAttribute>();

            if (ignored == null)
            {
                PropertyChanging?.Invoke(e.Instance, new PropertyChangingEventArgs(e.Property.Name));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Called when a property <c>get</c> method is intercepted and executes before the method body.
        /// </summary>
        /// <param name="e">The interception event arguments.</param>
        /// <remarks>
        /// If the property has a generated backing field, the value of the field will be loaded into the
        /// <see cref="PropertyInterceptionArgs.Value" /> property. If the value of this property is changed
        /// during the interception, the updated value will be copied into the backing field.
        /// </remarks>
        public void OnGet(PropertyInterceptionArgs e)
        {
            var type = e.Property.PropertyType;

            if (e.Value != null && !type.IsValueType)
            {
                return;
            }

            e.Value = Resolve(type);
        }
Ejemplo n.º 4
0
 public override void OnSetValue(PropertyInterceptionArgs <List <AspectJoinPoints> > args)
 {
     args.Value.Add(AspectJoinPoints.SetPropertyInterception);
     args.ProceedSetValue();
 }
 /// <summary>
 /// Called when a property <c>set</c> method is intercepted and executes after the method body.
 /// </summary>
 /// <param name="e">The interception event arguments.</param>
 public void OnExit(PropertyInterceptionArgs e)
 {
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes the members which will have been and will be referenced.
        /// </summary>
        private void InitializeReferencedMembers()
        {
            // interfaces
            IInjectAfterInitializer  = ResolveType("IInjectAfterInitializer");
            IInjectBeforeInitializer = ResolveType("IInjectBeforeInitializer");
            IInstanceAware           = ResolveType("IInstanceAware");
            IMemberAware             = ResolveType("IMemberAware");
            IMethodInterceptor       = ResolveType("IMethodInterceptor");
            IMethodReturnInterceptor = ResolveType("IMethodReturnInterceptor");
            IParameterInterceptor    = ResolveType("IParameterInterceptor");
            IPropertyGetInterceptor  = ResolveType("IPropertyGetInterceptor");
            IPropertySetInterceptor  = ResolveType("IPropertySetInterceptor");
            IRequireInitialization   = ResolveType("IRequireInitialization");

            // classes
            CompilationImplementsAttribute = ResolveType("CompilationImplementsAttribute");
            CompilationOptionsAttribute    = ResolveType("CompilationOptionsAttribute");
            Exception                    = ResolveType("Exception");
            MethodBase                   = ResolveType("MethodBase");
            MethodInfo                   = ResolveType("MethodInfo");
            MethodInterceptionArgs       = ResolveType("MethodInterceptionArgs");
            MethodReturnInterceptionArgs = ResolveType("MethodReturnInterceptionArgs");
            ObjectArray                  = new ArrayType(ResolveType("Object"));
            ParameterInfo                = ResolveType("ParameterInfo");
            ParameterInterceptionArgs    = ResolveType("ParameterInterceptionArgs");
            PropertyInfo                 = ResolveType("PropertyInfo");
            PropertyInterceptionArgs     = ResolveType("PropertyInterceptionArgs");
            Type      = ResolveType("Type");
            TypeArray = new ArrayType(Type);

            // constructors
            CompilerGeneratedAttributeCtor   = ResolveType("CompilerGeneratedAttribute").GetConstructor();
            MethodInterceptionArgsCtor       = MethodInterceptionArgs.GetConstructor();
            MethodReturnInterceptionArgsCtor = MethodReturnInterceptionArgs.GetConstructor();
            NonSerializedAttributeCtor       = ResolveType("NonSerializedAttribute").GetConstructor();
            ParameterInterceptionArgsCtor    = ParameterInterceptionArgs.GetConstructor();
            PropertyInterceptionArgsCtor     = PropertyInterceptionArgs.GetConstructor();

            // methods
            MethodBaseGetMethodFromHandle        = ResolveType("MethodBase").GetMethod("GetMethodFromHandle", parameters: new[] { ResolveType("RuntimeMethodHandle") });
            MethodBaseGetMethodFromHandleAndType = ResolveType("MethodBase").GetMethod("GetMethodFromHandle", parameters: new[] { ResolveType("RuntimeMethodHandle"), ResolveType("RuntimeTypeHandle") });
            MethodBaseGetParameters         = ResolveType("MethodBase").GetMethod("GetParameters");
            MethodInterceptorOnEnter        = IMethodInterceptor.GetMethod("OnEnter");
            MethodInterceptorOnException    = IMethodInterceptor.GetMethod("OnException");
            MethodInterceptorOnExit         = IMethodInterceptor.GetMethod("OnExit");
            MethodReturnInterceptorOnReturn = IMethodReturnInterceptor.GetMethod("OnReturn");
            ParameterInterceptorOnEnter     = IParameterInterceptor.GetMethod("OnEnter");
            PropertyGetInterceptorOnExit    = IPropertyGetInterceptor.GetMethod("OnExit");
            PropertyGetInterceptorOnGet     = IPropertyGetInterceptor.GetMethod("OnGet");
            PropertySetInterceptorOnExit    = IPropertySetInterceptor.GetMethod("OnExit");
            PropertySetInterceptorOnSet     = IPropertySetInterceptor.GetMethod("OnSet");
            RequireInitializationInitialize = IRequireInitialization.GetMethod("Initialize");
            TypeGetProperty       = Type.GetMethod("GetProperty", parameters: new[] { ResolveType("String"), ResolveType("BindingFlags") });
            TypeGetTypeFromHandle = Type.GetMethod("GetTypeFromHandle", parameters: new[] { ResolveType("RuntimeTypeHandle") });
            TypeMakeGenericType   = Type.GetMethod("MakeGenericType");

            // properties

            InstanceAwareInstanceSet             = IInstanceAware.GetProperty("Instance").Resolve().SetMethod.Import();
            MemberAwareMemberSet                 = IMemberAware.GetProperty("Member").Resolve().SetMethod.Import();
            MethodInterceptionArgsCancelGet      = MethodInterceptionArgs.GetProperty("Cancel").Resolve().GetMethod.Import();
            MethodInterceptionArgsReturnGet      = MethodInterceptionArgs.GetProperty("Return").Resolve().GetMethod.Import();
            MethodInterceptionArgsReturnSet      = MethodInterceptionArgs.GetProperty("Return").Resolve().SetMethod.Import();
            MethodReturnInterceptionArgsValueGet = MethodReturnInterceptionArgs.GetProperty("Value").Resolve().GetMethod.Import();
            MethodReturnInterceptionArgsValueSet = MethodReturnInterceptionArgs.GetProperty("Value").Resolve().SetMethod.Import();
            ParameterInterceptionArgsValueGet    = ParameterInterceptionArgs.GetProperty("Value").Resolve().GetMethod.Import();
            PropertyInterceptionArgsIsDirtyGet   = PropertyInterceptionArgs.GetProperty("IsDirty").Resolve().GetMethod.Import();
            PropertyInterceptionArgsValueGet     = PropertyInterceptionArgs.GetProperty("Value").Resolve().GetMethod.Import();
            PropertyInterceptionArgsValueSet     = PropertyInterceptionArgs.GetProperty("Value").Resolve().SetMethod.Import();
            TypeTypeHandleGet = Type.GetProperty("TypeHandle").Resolve().GetMethod.Import();
        }
 public override void OnGetValue(PropertyInterceptionArgs <string> args)
 {
     Console.WriteLine("OnGetValue of AnotherPropertyInterceptionAspect");
     args.ProceedGetValue();
 }
Ejemplo n.º 8
0
 public new void OnSetValue(PropertyInterceptionArgs <string> args, string s)
 {
     base.OnSetValue(args);
 }
 public override void OnGetValue(PropertyInterceptionArgs <string> args)
 {
     Console.WriteLine("OnGetValue", args.Property.Name);
     args.ProceedGetValue();
 }
Ejemplo n.º 10
0
 public override void OnGetValue(PropertyInterceptionArgs <int> args)
 {
     base.OnGetValue(args);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Called when a property <c>get</c> method is invoked and has produced an unhandled exception.
 /// </summary>
 /// <param name="e">The interception event arguments.</param>
 /// <param name="ex">The intercepted exception.</param>
 public void OnException(PropertyInterceptionArgs e, Exception ex)
 {
 }
Ejemplo n.º 12
0
 public void OnSet(PropertyInterceptionArgs e)
 {
     Console.WriteLine($"Set Property {e.Property.Name}");
 }
Ejemplo n.º 13
0
 public void OnException(PropertyInterceptionArgs e, Exception ex)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Called when a property <c>set</c> method is invoked and has produced an unhandled exception.
 /// </summary>
 /// <param name="e">The interception event arguments.</param>
 /// <param name="ex">The intercepted exception.</param>
 public void OnException(PropertyInterceptionArgs e, Exception ex) => throw ex;
Ejemplo n.º 15
0
            public new string OnSetValue(PropertyInterceptionArgs <string> args)
            {
                base.OnSetValue(args);

                return(string.Empty);
            }
Ejemplo n.º 16
0
 /// <summary>
 /// Called when a property <c>set</c> method is intercepted and executes before the method body.
 /// </summary>
 /// <param name="e">The interception event arguments.</param>
 /// <remarks>
 /// The value of the <see cref="P:Mimick.Aspect.PropertyInterceptionArgs.Value" /> property will be populated with the
 /// updated value which has been assigned during the set operation.
 /// </remarks>
 public void OnSet(PropertyInterceptionArgs e) => GetSynchronizationLock().EnterWriteLock();
Ejemplo n.º 17
0
 /// <summary>
 /// Called when a property <c>get</c> method is intercepted and executes before the method body.
 /// </summary>
 /// <param name="e">The interception event arguments.</param>
 /// <remarks>
 /// If the property has a generated backing field, the value of the field will be loaded into the
 /// <see cref="P:Mimick.Aspect.PropertyInterceptionArgs.Value" /> property. If the value of this property is changed
 /// during the interception, the updated value will be copied into the backing field.
 /// </remarks>
 public void OnGet(PropertyInterceptionArgs e) => GetSynchronizationLock().EnterReadLock();