zoukankan      html  css  js  c++  java
  • dotnet Framework的aop和dotnet net core的aop

    .Net Framework的aop

    /// <summary>
        /// 特性类
        /// </summary>
        public class FormFilterAttribute:Attribute
        {
            private readonly string _formTitle;
    
            public FormFilterAttribute(string formTitle)
            {
                this._formTitle = formTitle;
            }
    
            /// <summary>
            /// 通过特性设置标题
            /// </summary>
            /// <param name="form"></param>
            public void SetTitle(Form form)
            {
                form.Text = _formTitle;
            }
    
        }
    View Code
     /// <summary>
        /// 调用特性的类
        /// </summary>
        public class RunWithAop
        {
            /// <summary>
            /// aop通用的方法
            /// </summary>
            /// <param name="form"></param>
            public static void AopMethod(Form form)
            {
                /**
                 * 1.获取特性
                 * 2.得到特性的实例,调用特性中的方法
                 */ 
                 Type type= form.GetType();
                if (type.IsDefined(typeof(FormFilterAttribute),true))
                {
                    //调用GetCustomAttribute方法需要引用反射的命名空间。否则只能看到GetCustomAttributes方法。
                    FormFilterAttribute attribute = (FormFilterAttribute)type.GetCustomAttribute(typeof(FormFilterAttribute));
                    attribute.SetTitle(form);
                }
            }
    
            /// <summary>
            /// 给外界调用的方法
            /// </summary>
            /// <param name="form"></param>
            public static void RunApp(Form form)
            {
                AopMethod(form);
                Application.Run(form);
            }
    
            public static void Show(Form form)
            {
                AopMethod(form);
                form.Show();
            }
    
            public static void ShowDialog(Form form)
            {
                AopMethod(form);
                form.ShowDialog();
            }
        }
    View Code
     static class Program
        {
            /// <summary>
            ///  The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.SetHighDpiMode(HighDpiMode.SystemAware);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                //Application.Run(new Form1());
                RunWithAop.RunApp(new Form1());
            }
        }
    View Code
  • 相关阅读:
    Xcode配置.pch文件
    iOS ViewController生命周期
    小技巧 -- 隐藏导航栏返回按钮附带的文字
    添加App启动页面
    iOS 关于nil和Nil及null与<null>的区别
    文件上传之组件
    js验证
    java mail
    validform 一款好用的表单验证插件
    tomcat启动时出错
  • 原文地址:https://www.cnblogs.com/wesley168/p/14819600.html
Copyright © 2011-2022 走看看