程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#反射機制

C#反射機制

編輯:C#入門知識

反射機制基礎類

反射機制的功能與介紹

反射層次模型圖

類獲取程序及信息

類獲取程序集模塊信息

類獲取類型的信息

利用反射調用方法

特性(Attribute)

介紹

示例

自定義特性

自定義特性說明

示例

類的使用

可選參數與命名參數

標識符

通過反射獲取Attributes

Main([] args)

assem = .Load();

.LoadFrom();LoadFile()方法

.GetExecutingAssembly();

.Read();

PrintInfo( assem)

.WriteLine(:"

.WriteLine("

.WriteLine(:"

.WriteLine("

.WriteLine("

[] types = assem.GetTypes();

.WriteLine(:"

" + item.Name);//輸出類型名

.WriteLine();

Main([] args)

assembly = .Load();

module = assembly.GetModule();

.WriteLine("

[] types = module.FindTypes(.FilterTypeName, );

( item types)

.WriteLine("

.Read();

Id;

Name;

Method( i) { }

Main([] args)

type = ();

.WriteLine(:"

.WriteLine("

.WriteLine(:"

.WriteLine("

.WriteLine(:"

.WriteLine("

.WriteLine("

.WriteLine("

[] memberInfos = type.GetMembers();

( item memberInfos)

.WriteLine(""

.Read();

Myclass()

.WriteLine(Myclass對象!"

Method( i)

.WriteLine("

Main([] args)

t = ();

o = .CreateInstance(t);

.WriteLine(Myclass對象:"

method = t.GetMethod();

[] { 100 });

.Read();

(Attribute)

(")]true改成false就可以編譯通過

OldMethod() { }

Main([] args)

.Read();

Attribute類命名為XXXAttribute

:

description;

HelpAttribute( Descrition_in)

.description = Descrition_in;

Description

{ description; }

("Attribute”後綴

Main([] args)

.Read();

(.Method, AllowMultiple = , Inherited = )]

:

description;

HelpAttribute( Descrition_in)

.description = Descrition_in;

Description

{ description; }

("

Main([] args)

.Read();

(.Method, AllowMultiple = , Inherited = )]

:

_description;

_name;

HelpAttribute( description)

.WriteLine("

._description = description;

Description

{ _description; }

Name

{ _name; }

,必須要有set方法

.WriteLine(");

;

(""

Main([] args)

.Read();

:

_description;

_name;

HelpAttribute( description)

.WriteLine(===="

._description = description;

Description

{ _description; }

Name

{ _name; }

,必須要有set方法

.WriteLine(" + );

;

(")]

("1"

("2"

TestMethod()

.WriteLine(==========="

Main([] args)

t = ();

[] obis = t.GetCustomAttributes((), );

attribute = obis[0] ;

.WriteLine( + attribute.Description + + attribute.Name + );

method = t.GetMethod();

[] methods = method.GetCustomAttributes((), );

( help methods)

.WriteLine( + help.Description + + help.Name + );

.Read();

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved