当前位置: 代码迷 >> C# >> 那类头上中括号里的像标签一样的货色是干什么用的.下面的代码是什么意思.有什么书系统详细的介绍?解释详细的90以分上
  详细解决方案

那类头上中括号里的像标签一样的货色是干什么用的.下面的代码是什么意思.有什么书系统详细的介绍?解释详细的90以分上

热度:112   发布时间:2016-05-05 04:12:16.0
那类头上中括号里的像标签一样的东西是干什么用的.下面的代码是什么意思.有什么书系统详细的介绍?解释详细的90以分上
// Generated by .NET Reflector from C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.Composition\v4.0_4.0.0.0__b77a5c561934e089\System.ComponentModel.Composition.dll
namespace System.ComponentModel.Composition
{
    using System;
    using System.Runtime;
    using System.Runtime.CompilerServices;
    
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Class, AllowMultiple=true, Inherited=false)]
    public class ExportAttribute : Attribute
    {
        [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
        public ExportAttribute() : this(null, null)
        {
        }
        
        [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
        public ExportAttribute(string contractName) : this(contractName, null)
        {
        }
        
        [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
        public ExportAttribute(Type contractType) : this(null, contractType)
        {
        }
        
        public ExportAttribute(string contractName, Type contractType)
        {
            this.ContractName = contractName;
            this.ContractType = contractType;
        }
        
        public string ContractName
        {
            [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
            get
            {
                return this.<ContractName>k__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                this.<ContractName>k__BackingField = value;
            }
        }
        
        public Type ContractType
        {
            [CompilerGenerated, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
            get
            {
                return this.<ContractType>k__BackingField;
            }
            [CompilerGenerated]
            private set
            {
                this.<ContractType>k__BackingField = value;
            }
        }
    }
}

------解决思路----------------------
Attribute
http://www.cnblogs.com/hyddd/archive/2009/07/20/1526777.html
http://www.cnblogs.com/luckdv/articles/1682488.html
http://kb.cnblogs.com/page/87531/
------解决思路----------------------
msdn有详细的文章:
Attributes Tutorial
https://msdn.microsoft.com/en-AU/library/aa288454(v=vs.71).aspx
------解决思路----------------------
曾经自己也定义过属性,就是在写类定义,需要与数据库表结构应对的时候,发现有些字段名与语法冲突不能写成类成员名,那就换个名字,然后再贴个标签,在标签里记录下对应的字段名.然后在自动生成类实例的时候,通过反射取这些标签,如果有则从中取字段名,如果没有那对应的字段名就是这个成员名.
  相关解决方案