zoukankan      html  css  js  c++  java
  • C#中常用的Attribute搜集(刚开始...)

    ObsoleteAttribute

    名字空间: System

    函数已经不推荐使用

    FlagsAttribute

    名字空间: System

    [FlagsAttribute]
    enum class MultiHue : short
    {
       Black = 0,
       Red = 1,
       Green = 2,
       Blue = 4
    };
    

    All possible combinations of values of an Enum with FlagsAttribute:

    0 - Black 1 - Red 2 - Green 3 - Red, Green 4 - Blue 5 - Red, Blue 6 - Green, Blue 7 - Red, Green, Blue 8 - 8

    SerializableAttribute, NonSerializedAttribute

    名字空间: System

    标记一个字段是否被序列化

    DllImportAttribute

    Win32 API 函数

       1:  [DllImport("User32.dll", EntryPoint="MessageBox")]
       2:  static extern int MessageDialog(int hWnd, string msg, string caption, int msgType);

    WebMethod

    名字空间: System.Web.Services

    WebService方法, 有6个属性, 分别是 BufferResponse, CacheDuration, Description, EnableSession, MessageName, TransactionOption

       1:  [WebMethod(TransactionOption=TransactionOption.RequiresNew) ]
       2:  public void Transfer(long Amount, long AcctNumberTo, long AcctNumberFrom) 
       3:  {
       4:  }

    DataObjectAttribute, DataObjectFieldAttribute, DataObjectMethodAttribute

    名字空间: System.ComponentModel

    [DataObjectAttribute]
    public class NorthwindData
    {  
      public NorthwindData() {}
    
      private int _employeeID;
      [DataObjectFieldAttribute(true, true, false)]
      public int EmployeeID
      {
        get { return _employeeID; }
        set { _employeeID = value; }
      }
    
    
      [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
      public static IEnumerable GetAllEmployees()
      {
        AccessDataSource ads = new AccessDataSource();
        ads.DataSourceMode = SqlDataSourceMode.DataReader;
        ads.DataFile = "~//App_Data//Northwind.mdb";
        ads.SelectCommand = "SELECT EmployeeID,FirstName,LastName FROM Employees";
        return ads.Select(DataSourceSelectArguments.Empty);
      }
    
      // Delete the Employee by ID.
      [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
      public void DeleteEmployeeByID(int employeeID)
      {
        throw new Exception("The value passed to the delete method is "
                             + employeeID.ToString());
      }
    }

    AmbientValueAttribute

    名字空间: System.ComponentModel

    标记一个属性是否从周围环境获得值, 比如: 一个空间的背景色自动为其父空间的背景色

    BindableAttribute

    名字空间: System.ComponentModel

    标记一个属性是否可以被绑定

    [Bindable(true)]
     public int MyProperty {
        get {
           // Insert code here.
           return 0;
        }
        set {
           // Insert code here.
        }
     }

    BrowsableAttribute, CategoryAttribute, DisplayNameAttribute,DescriptionAttribute

    DefaultEventAttribute, DefaultPropertyAttribute, DefaultValueAttribute,

    DesignerAttribute, DesignerCategoryAttribute, DesignTimeVisibleAttribute, DesignOnlyAttribute

    名字空间: System.ComponentModel

    设计一个GUI组件时, 标记属性, 事件, 方法在设计器如何显示.

    参见: Developing Custom Data-Bound Web Server Controls for ASP.NET 2.0

    ConditionalAttribute

    名字空间: System.Diagnostics

    class Test
    {
        static void Main()
        {               
            Console.WriteLine("Calling Method1");
            Method1(3);
            Console.WriteLine("Calling Method2");
            Method2();
    
            Console.WriteLine("Using the Debug class");
            Debug.Listeners.Add(new ConsoleTraceListener());
            Debug.WriteLine("DEBUG is defined");
        }
    
        [Conditional("CONDITION1")]
        public static void Method1(int x)
        {
            Console.WriteLine("CONDITION1 is defined");
        }
    
        [Conditional("CONDITION1"), Conditional("Condition2")]  
        public static void Method2()
        {
            Console.WriteLine("CONDITION1 or Condition2 is defined");
        }
    }
    

    /*
    When compiled as shown, the application (named ConsoleApp)
    produces the following output.

    csc ConsoleApp.cs
    Calling Method1
    Calling Method2
    Using the Debug class

    csc /define:CONDITION1 ConsoleApp.cs
    Calling Method1
    CONDITION1 is defined
    Calling Method2
    CONDITION1 or Condition2 is defined
    Using the Debug class

    csc /define:Condition2 ConsoleApp.cs
    Calling Method1
    Calling Method2
    CONDITION1 or Condition2 is defined
    Using the Debug class

    csc /define:DEBUG ConsoleApp.cs
    Calling Method1
    Calling Method2
    Using the Debug class
    DEBUG is defined
    */

    DebuggerBrowserableAttribute, DebuggerDisplayAttribute, DebuggerHiddenAttribute, MonitoringDescriptionAttribute

    DebuggerNonUserCodeAttribute

    DebuggerStepperBoundaryAttribute

    DebuggerStepThroughAttribute

    DebuggerTypeProxyAttribute

    SwitchAttribute

    SwitchLevelAttribute

  • 相关阅读:
    vue 中的const {XXX } =this 的作用效果
    <a href="javascript:;">的用法说明
    iOS抓包工具Charles —— 破解、抓包入门
    iOS抓包工具Charles
    Android抓包方法(一)之Fiddler代理
    appium+python自动化24-滑动方法封装(swipe)
    Appium移动自动化测试(五)--app控件获取之uiautomatorviewer
    appium自动化框架项目实战1——app初次使用引导页
    一个完整的Appium手机自动化测试实例
    Appium提高脚本复用、可配置性
  • 原文地址:https://www.cnblogs.com/mrfangzheng/p/1211868.html
Copyright © 2011-2022 走看看