• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MethodExecutionArgs类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: OnExit

        public void OnExit(MethodExecutionArgs args)
        {
            var tabControlMember = Instance.GetType()
                                                    .GetFields(BindingFlags.NonPublic | BindingFlags.Public |
                                                               BindingFlags.Instance)
                                                    .FirstOrDefault(x => x.FieldType == typeof(TabControl));
            if (tabControlMember == null)
                return;

            var tabControl = tabControlMember.GetValue(Instance) as TabControl;
            if (tabControl == null)
                return;

            var formControllerMember = Instance.GetType()
                                         .GetFields(BindingFlags.NonPublic | BindingFlags.Public |
                                                    BindingFlags.Instance)
                                         .FirstOrDefault(x => x.FieldType.IsSubclassOf(typeof(BaseController)));

            if (formControllerMember == null)
                return;

            var formController = formControllerMember.GetValue(Instance) as BaseController;
            if (formController == null)
                return;

            var tabPage = new TabPage { Text = "Documents" };
            DocumentControl documentControl = new DocumentControl();
            tabPage.Controls.Add(documentControl);
            documentControl.Dock = DockStyle.Fill;
            tabControl.TabPages.Add(tabPage);
            formController.DataSourceInitialized += (sender, eventArgs) => documentControl.Controller.InitDataSource();
        }
开发者ID:fpommerening,项目名称:PostSharpSamples,代码行数:32,代码来源:IncludeAdditionalControlAspect.cs


示例17: OnSuccess

 public override void OnSuccess(MethodExecutionArgs args)
 {
     //note: this is a terrible example, aspects should be "method agnostic"
     //but I'm doing it to prove a point :P
     var results = args.ReturnValue as SearchResults;
     Console.WriteColorLine(string.Format("Successfully searched twitter, got {0} results", results.Results.Length), ConsoleColor.Yellow);
 }
开发者ID:ChadMcCallum,项目名称:AOPExamples,代码行数:7,代码来源:TracingAspect.cs


示例18: OnException

 public override void OnException(MethodExecutionArgs args)
 {
     const string anErrorOccured = "An error occured";
     Console.WriteLine(anErrorOccured);
     args.ReturnValue = anErrorOccured;
     args.FlowBehavior = FlowBehavior.Return;
 }
开发者ID:EvanPalmer,项目名称:AopIlWeavingExample,代码行数:7,代码来源:Program.cs


示例19: OnEntry

        public override void OnEntry(MethodExecutionArgs args)
        {
            if (string.IsNullOrEmpty(_name))
                _name = args.Method.Name;

            base.OnEntry(args);
        }
开发者ID:virtser,项目名称:Varshaman,代码行数:7,代码来源:GaugeAttribute.cs


示例20: OnEntry

 public override void OnEntry(MethodExecutionArgs args)
 {
     if (_amountParameterIndex != -1)
     {
         Logger.Write(_className + "." + _methodName + ", amount: " + args.Arguments[_amountParameterIndex]);
     }
 }
开发者ID:olcayseker,项目名称:PostSharp5,代码行数:7,代码来源:TransactionAuditAttribute.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MethodImplAttributes类代码示例发布时间:2022-05-24
下一篇:
C# MethodDefinitionHandle类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap