Пример #1
0
        public void Advise(PropertyAdviceContext context)
        {
            // some non-sense mocking
            if (context.IsGetter)
                context.ReturnValue = Activator.CreateInstance(context.TargetProperty.PropertyType);

            // now, some advice
            if (NewReturnValue.HasValue)
                context.ReturnValue = NewReturnValue.Value;
        }
Пример #2
0
 public void Advise(PropertyAdviceContext context)
 {
     if (_persistenceProperty == null)
         _persistenceProperty = new PropertyImporter<IPersistence>(context.TargetProperty.DeclaringType);
     var persistence = _persistenceProperty.Get(context.Target);
     if (context.IsGetter)
         context.ReturnValue = persistence.GetValue(Name, context.TargetProperty.PropertyType, DefaultValue);
     else
         persistence.SetValue(Name, context.Value, AutoSave);
 }
Пример #3
0
 /// <summary>
 /// Implements advice logic.
 ///             Usually, advice must invoke context.Proceed()
 /// </summary>
 /// <param name="context">The method advice context.</param>
 void IPropertyAdvice.Advise(PropertyAdviceContext context)
 {
     if (context.IsSetter && context.Value == null)
     {
         Logging.DebugMessage("Property '{0}' cannot be null on '{1}'{2}Parent object: {2}{3}", context.TargetProperty.Name, context.TargetType.FullName, Environment.NewLine, context.Target == null ? "" : context.Target.ToString());
         throw new ArgumentNullException(context.TargetProperty.Name, string.Format("Property '{0}' cannot be null on '{1}'", context.TargetProperty.Name, context.TargetType.FullName));
     }
     context.Proceed();
     if (context.IsGetter && CheckOnGet && (!context.HasReturnValue || context.ReturnValue == null))
     {
         Logging.DebugMessage("Property '{0}' cannot be null on '{1}'{2}Parent object: {2}{3}", context.TargetProperty.Name, context.TargetType.FullName, Environment.NewLine, context.Target == null ? "" : context.Target.ToString());
         if (ThrowOnGet)
             throw new ArgumentNullException(context.TargetProperty.Name, string.Format("Property '{0}' cannot be null on '{1}'", context.TargetProperty.Name, context.TargetType.FullName));
     }
 }
 void IPropertyAdvice.Advise(PropertyAdviceContext context)
 {
     try
     {
         context.Proceed();
     }
     catch (NullReferenceException ex)
     {
         ex.Log(string.Format("Null reference in {2}.{0}.[{1}]", context.TargetProperty.Name, context.IsGetter ? "get" : "set", context.TargetType.FullName));
         throw;
     }
     catch (Exception ex)
     {
         ex.Log(context.IsGetter ? "Getter" : "Setter");
         throw;
     }
 }
Пример #5
0
        public void Advise(PropertyAdviceContext context)
        {

            using (var t = TracerFactory.StartTracer(context.TargetType, string.Format("{0}_{1}", context.IsGetter ? "get" : "set", context.TargetProperty.Name)))
            {
                if (info.ContainsCharacters()) t.SetAdidtionalInformation(info);
                try
                {

                    context.Proceed();
                }
                catch (Exception ex)
                {
                    if (TreatExceptionAsInformational) t.SetException(ex);
                    else t.SetErrorState(ex);
                    throw;
                }
            }
        }
 void IPropertyAdvice.Advise(PropertyAdviceContext context)
 {
     var ctx = BeforeProcessing(new ActivationContext(context));
     if (ctx.ExecuteAlternate)
     {
         if (context.IsGetter && ctx.SkipTargetProcess)
         {
             var task = AlternateProceed(ctx);
             context.Value = task;
         }
         else AlternateProceed(ctx);
     }
     if (!ctx.SkipTargetProcess)
     {
         try
         {
             context.Proceed();
         }
         catch (Exception ex)
         {
             HandleException(ctx,ex);
             throw;
         }
     }
     ctx = AfterProcesssing(ctx);
     ctx.Clean();
 }
Пример #7
0
 public void Advise(PropertyAdviceContext context)
 {
     context.Proceed();
 }