zoukankan      html  css  js  c++  java
  • .net 特性使用

    using System;
    using System.Reflection;
    public class HelpAttribute : Attribute
    {
    string url;
    string topic;
    public HelpAttribute(string url)
    {
    this.url = url;
    }
    public string Url
    {
    get { return url; }
    }
    public string Topic
    {
    get { return topic; }
    set { topic = value; }
    }
    public string test { get; }
    }

    [Help("http://msdn.microsoft.com/.../MyClass.htm")]
    public class Widget
    {
    [Help("http://msdn.microsoft.com/.../MyClass.htm", Topic = "Display")]
    public void Display(string text) { }
    }


    class Test
    {
    static void ShowHelp(MemberInfo member)
    {
    HelpAttribute a = Attribute.GetCustomAttribute(member,
    typeof(HelpAttribute)) as HelpAttribute;
    if (a == null)
    {
    Console.WriteLine("No help for {0}", member);
    }
    else
    {
    Console.WriteLine("Help for {0}:", member);
    Console.WriteLine(" Url={0}, Topic={1}", a.Url, a.Topic);
    Console.ReadKey();
    }
    }
    static void Main()
    {
    ShowHelp(typeof(Widget));
    ShowHelp(typeof(Widget).GetMethod("Display"));
    }
    }

  • 相关阅读:
    Cocos2d-x之绘制线条
    Cocos2d-x之绘制填充不规则多边形
    unittest
    检查代码错误和代码风格问题
    命名
    二进制数据
    python 后台运行
    分页
    编码
    格式化
  • 原文地址:https://www.cnblogs.com/yexinw/p/3110517.html
Copyright © 2011-2022 走看看