当前位置: 首页>>代码示例>>C#>>正文


C# MethodExecutionArgs类代码示例

本文整理汇总了C#中MethodExecutionArgs的典型用法代码示例。如果您正苦于以下问题:C# MethodExecutionArgs类的具体用法?C# MethodExecutionArgs怎么用?C# MethodExecutionArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MethodExecutionArgs类属于命名空间,在下文中一共展示了MethodExecutionArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnEntry

        public override void OnEntry(MethodExecutionArgs args)
        {
            if (!ValidationFlags.HasFlag(ValidationFlags.Arguments)) return;

            var method = MethodInformation.GetMethodInformation(args);
            if (method == null
                || !method.HasArguments
                || (!ValidationFlags.HasFlag(ValidationFlags.NonPublic) && !method.IsPublic)
                || (!ValidationFlags.HasFlag(ValidationFlags.Properties) && method.IsProperty)
                || (!ValidationFlags.HasFlag(ValidationFlags.Methods) && !method.IsProperty)
                // TODO: What about events?
                )
                return;

            var invalidArgument = (from arg in args.Method.GetParameters()
                where arg.MayNotBeNull() && args.Arguments[arg.Position] == null
                select arg).FirstOrDefault();

            if (invalidArgument == null) return;

            if (method.IsProperty)
            {
                throw new ArgumentNullException(invalidArgument.Name,
                    String.Format(CultureInfo.InvariantCulture,
                        "Cannot set the value of property '{0}' to null.",
                        method.Name));
            }
            throw new ArgumentNullException(invalidArgument.Name);
        }
开发者ID:RossMerr,项目名称:NullGuard,代码行数:29,代码来源:EnsureNonNullAspect.cs

示例2: OnEntry

        public override void OnEntry(MethodExecutionArgs args)
        {
            var cmdlet = args.Instance as CmdletProvider;
            if( null == cmdlet )
            {
                return;
            }

            string parameters = "";
            if( null != args.Arguments && args.Arguments.Any() )
            {
                parameters = String.Join("; ", args.Arguments.ToList().ConvertAll(a => (a ?? "null").ToString()).ToArray());
            }
            try
            {
                var s = String.Format(
                    "[{0}] >> Entering [{1}] ( [{2}] )",
                    args.Instance.GetType().FullName,
                    args.Method.Name,
                    parameters);
                cmdlet.WriteDebug(s);
            }
            catch
            {
            }
        }
开发者ID:beefarino,项目名称:TxF,代码行数:26,代码来源:LogProviderToSession.cs

示例3: OnEntry

        // Executed at runtime, before the method.
        public override void OnEntry( MethodExecutionArgs eventArgs )
        {
            // Compose the cache key.
            string key = this.formatStrings.Format(
                eventArgs.Instance, eventArgs.Method, eventArgs.Arguments.ToArray() );

            // Test whether the cache contains the current method call.
            lock ( cache )
            {
                object value;
                if ( !cache.TryGetValue( key, out value ) )
                {
                    // If not, we will continue the execution as normally.
                    // We store the key in a state variable to have it in the OnExit method.
                    eventArgs.MethodExecutionTag = key;
                }
                else
                {
                    // If it is in cache, we set the cached value as the return value
                    // and we force the method to return immediately.
                    eventArgs.ReturnValue = value;
                    eventArgs.FlowBehavior = FlowBehavior.Return;
                }
            }
        }
开发者ID:jogibear9988,项目名称:ormbattle,代码行数:26,代码来源:CacheAttribute.cs

示例4: OnException

        public override void OnException(MethodExecutionArgs args)
        {
            Console.WriteLine(String.Format("Exception in :[{0}] ,            Message:[{1}]", args.Method, args.Exception.Message));
            args.FlowBehavior = FlowBehavior.Continue;

            base.OnException(args);
        }
开发者ID:eiu165,项目名称:PostSharpTest,代码行数:7,代码来源:ExceptionAspect.cs

示例5: OnException

        public override void OnException(MethodExecutionArgs args)
        {
            InternalError internalError;
            HttpStatusCode httpStatusCode;

            var exceptionType = args.Exception.GetType();

            if (exceptionType == typeof(KeyNotFoundException))
            {
                httpStatusCode = HttpStatusCode.NotFound;
                var keyNotFoundException = args.Exception as KeyNotFoundException;
                internalError = InternalError.CreateNotFound(keyNotFoundException);
            }
            else if (exceptionType == typeof(ValidationException))
            {
                httpStatusCode = HttpStatusCode.BadRequest;
                var validationException = args.Exception as ValidationException;
                internalError = InternalError.CreateValidation(validationException);
            }
            else if (exceptionType == typeof(AuthenticationException))
            {
                httpStatusCode = HttpStatusCode.Unauthorized;
                var authenticationException = args.Exception as AuthenticationException;
                internalError = InternalError.CreateAuthentication(authenticationException);
            }
            else
            {
                httpStatusCode = HttpStatusCode.InternalServerError;
                internalError = InternalError.CreateUnexpected();
            }

            _log.Error(internalError.Id, args.Exception);
            throw new WebFaultException<InternalError>(internalError, httpStatusCode);
        }
开发者ID:nReality,项目名称:WCFRestApiBootstrapper,代码行数:34,代码来源:ExceptionShieldAttribute.cs

示例6: OnEntry

 public override void OnEntry(MethodExecutionArgs args)
 {
     // It is equiavlent to the start of the "try"
     Stopwatch sw = new Stopwatch();
     args.MethodExecutionTag = sw;
     sw.Start();
 }
开发者ID:adamcogx,项目名称:PostSharp.FastTrack,代码行数:7,代码来源:TimedAttribute.cs

示例7: OnEntry

 /// <summary>
 /// Called at runtime before the method is executed.
 /// </summary>
 /// <param name="eventArgs">Event arguments.</param>
 public override void OnEntry( MethodExecutionArgs eventArgs )
 {
     Trace.TraceInformation(
         "Entering " + this.strings.Format( eventArgs.Instance, eventArgs.Method, eventArgs.Arguments.ToArray() )
         );
     Trace.Indent();
 }
开发者ID:jogibear9988,项目名称:ormbattle,代码行数:11,代码来源:TraceAttribute.cs

示例8: OnSuccess

        public override void OnSuccess(MethodExecutionArgs args)
        {
            var status = args.ReturnValue as Status;

            if (status != null && status.Success)
            {
                var campaignId = AspectUtility.GetArgument<string>(args, AspectUtility.GetArgumentPosition(args, "campaignId"));
                var affiliateId = AspectUtility.GetArgument<string>(args, AspectUtility.GetArgumentPosition(args, "affiliateId"));
                var accessKeyId = AspectUtility.GetArgument<string>(args, AspectUtility.GetArgumentPosition(args, "accessKeyId"));

                Guid validCampaignId;
                Guid validAccessKeyId;

                if (Guid.TryParse(campaignId, out validCampaignId) && Guid.TryParse(accessKeyId, out validAccessKeyId))
                {
                    using (var context = new DataContext())
                    {
                        var accessKey = context.AccessKeys.SingleOrDefault(key => key.Id == validAccessKeyId);

                        if (accessKey != null && accessKey.UserId != null)
                        {
                            processAffiliate(context, accessKey.UserId ?? Guid.Empty, validCampaignId, affiliateId);
                        }
                    }
                }
            }
        }
开发者ID:akimboyko,项目名称:AOP.Hydra,代码行数:27,代码来源:ProcessAffiliateOnSuccessAttribute.cs

示例9: OnException

 public override void OnException(MethodExecutionArgs args)
 {
     object key = OperationContext.Current.IncomingMessageHeaders.MessageId;
     
     ObjectServiceExceptionStore.SetException(key, args.Exception.Message);
     throw args.Exception;
 }
开发者ID:NGITechnology,项目名称:BeymenCheckout,代码行数:7,代码来源:ObjectServiceExceptionHandlerAttribute.cs

示例10: OnEntry

 public override void OnEntry(MethodExecutionArgs args)
 {
     _methodKey = args.Instance.ToString() + "." + args.Method.Name;
     System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
     w.Start();
     args.MethodExecutionTag = w;
 }
开发者ID:ahmedomarjee,项目名称:ES-workshop,代码行数:7,代码来源:StatsdMetricsAttribute.cs

示例11: OnExit

        public override void OnExit(MethodExecutionArgs args)
        {
            System.Diagnostics.Stopwatch w = (System.Diagnostics.Stopwatch) args.MethodExecutionTag;
            w.Stop();

            Metrics.Timer(_methodKey, (int)w.ElapsedMilliseconds);
        }
开发者ID:ahmedomarjee,项目名称:ES-workshop,代码行数:7,代码来源:StatsdMetricsAttribute.cs

示例12: OnEntry

 public override void OnEntry(MethodExecutionArgs args)
 {
     args.MethodExecutionTag = Stopwatch.StartNew();
     //private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
     Logging.Info("Called Entry " + args.Method.Name);
     base.OnEntry(args);
 }
开发者ID:chandramohank,项目名称:Demo,代码行数:7,代码来源:MethodAspect.cs

示例13: Current

		int Current( MethodExecutionArgs args, int move )
		{
			var dictionary = cache.Get( args.Instance ?? args.Method.DeclaringType );
			var key = Keys.For( args );
			var result = dictionary[key] = dictionary.Ensure( key, i => 0 ) + move;
			return result;
		}
开发者ID:DevelopersWin,项目名称:VoteReporter,代码行数:7,代码来源:RecursionGuardAttribute.cs

示例14: OnEntry

 public override void OnEntry( MethodExecutionArgs eventArgs )
 {
     TransactionOptions options = new TransactionOptions();
     options.IsolationLevel = IsolationLevel.ReadCommitted;
     options.Timeout = TimeSpan.FromSeconds( this.timeout );
     eventArgs.MethodExecutionTag = new TransactionScope( this.transactionScopeOption, options );
 }
开发者ID:jogibear9988,项目名称:ormbattle,代码行数:7,代码来源:TransactionAttribute.cs

示例15: OnEntry

 public override void OnEntry(MethodExecutionArgs args)
 {
     _start = DateTime.Now;
     //note: this is a terrible example, aspects should be "method agnostic"
     //but I'm doing it to prove a point
     Console.WriteColorLine(string.Format("Starting search for {0}", args.Arguments[0]), ConsoleColor.Blue);
 }
开发者ID:ChadMcCallum,项目名称:AOPExamples,代码行数:7,代码来源:TracingAspect.cs


注:本文中的MethodExecutionArgs类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。