这些资料是我学习的时候在网络上寻找到的,发布出来希望对大家有帮助,一起努力前进,嘿嘿......Microsoft C#规范 2.0 版 GFC用户提交

feedsky 抓虾 pageflakes google reader my yahoo bloglines 鲜果 有道 http://wap.feedsky.com/bliplink

AttributeB


//第三步:在运行阶段检测属性
//应用属性对象只会在程序集中生成额外的元数据,应用程序代码的行为根本不会有任何变化。
//如果应用了属性对象,在运行时必须实现一些代码来检查在某些目标上是否存在该属性的实例,
//然后执行一些逻辑分支代码,正因为如此,属性才变得如此有用。


using System;
using System.Diagnostics;
using System.Reflection;


[assembly: CLSCompliant(true)]


[Serializable]
[DefaultMemberAttribute("Main")]
public sealed class Program
{
 [Conditional("Debug")]
 [Conditional("Release")]
 public void DoSomething() { }

 public Program()
 {
 }

 [CLSCompliant(true)]
 [STAThread]
 public static void Main()
 {
  // Show the set of attributes applied to this type
  ShowAttributes(typeof(Program));

  // Get the set of methods associated with the type
  MemberInfo[] members = typeof(Program).FindMembers(
   MemberTypes.Constructor | MemberTypes.Method,
   BindingFlags.DeclaredOnly | BindingFlags.Instance |
   BindingFlags.Public | BindingFlags.Static,
   Type.FilterName, "*");

  foreach (MemberInfo member in members)
  {
   // Show the set of attributes applied to this member
   ShowAttributes(member);
  }
 }

 private static void ShowAttributes(MemberInfo attributeTarget)
 {
  Attribute[] attributes = Attribute.GetCustomAttributes(attributeTarget);
     
  Console.WriteLine("Attributes applied to {0}: {1}",
   attributeTarget.Name, (attributes.Length == 0 ? "None" : String.Empty));

  foreach (Attribute attribute in attributes)
  {
   // Display the type of each applied attribute
   Console.WriteLine("  {0}", attribute.GetType().ToString());
        
   if (attribute is DefaultMemberAttribute)
    Console.WriteLine("    MemberName={0}",
     ((DefaultMemberAttribute) attribute).MemberName);

   if (attribute is ConditionalAttribute)
    Console.WriteLine("    ConditionString={0}",
     ((ConditionalAttribute) attribute).ConditionString);

   if (attribute is CLSCompliantAttribute)
    Console.WriteLine("    IsCompliant={0}",
     ((CLSCompliantAttribute) attribute).IsCompliant);

 }
  Console.WriteLine();
 }
}


友情链接

郑州大学软件学院 SpringWidgets-Blogger 徵信社 翻译公司 链接帮手网 行驶证字体 酷站目录 Friend Connectified