雖然c# meta programing 的能力不夠
不過新特性還是比較爽的
用這些寫了個ioc類
挺有意思
c# **
using system;
using system.collections.generic;
using system.linq;
using system.text;
using nunit.framework;
namespace test
///
/// normal service
///
public
class singlecomponentservice
:icomponentservice
#region icomponentservice members
public t getcomponent()
#endregion
}
///
/// singleton service
///
public
class cachedcomponentservice
:icomponentservice
#region icomponentservice members
public t getcomponent()
#endregion
}
public
class servicenotexistexception : exception
}
///
/// 小型micro 容器
/// todo: 1 父容器 -ok
/// 2 service regist -ok
/// 3 generic -ok
/// 4 singlton,lazy initial -ok
/// 5 aop,attribute driver ,define to kernelsupport
///
public
class microcontainer
public microcontainer(microcontainer parentcontainer)
///
/// 註冊服務
///
///
///
///
public
void register
(string key, func
///
/// 註冊singleton服務
///
///
///
///
public
void registersingleton
(string key, func
///
/// 註冊服務
///
///
///
///
public
void registerservice
(string key,icomponentservice
service)
///
/// 取得元件
///
///
///
///
元件public t getcomponent
(string key)
}
}
使用方法如下
測試類:
c# **
public
class mainclass
public
int dotimes
public firstinte***ce sth
public
void run()
}
public
void runformetacall()
public
string methodmissing(string name)
}
public
inte***ce firstinte***ce
public
class firstclass : firstinte***ce
", name);
}
#endregion
}
public
class secondclass : firstinte***ce
", name);
}
#endregion
}
c# **
var parentcontainer = new microcontainer();
var container = new microcontainer(parentcontainer);
container.register
("firstclass", c => new firstclass());
container.register("name", c => "xiao li");
container.register("name2", c => "xiao zhang");
container.register("times", c => 3);
container.register("times2", c => 1);
container.register("mainclass",
c => new mainclass
);
parentcontainer.register
("secondclass",
c => new secondclass());
var mainclass = container.getcomponent
("mainclass");
mainclass.run();
用c ,寫了個單鏈錶類
這幾天開始學習資料結構,今天便寫了個最簡單的單鏈表,在標頭檔案裡定義的 並且實現了自定義位置插入資料,刪除資料,查詢資料,預設新增資料功能 不知道這算不算adt呢,對於概念還不是很懂 笑 只有一點點的c基礎,寫物件導向還不是很熟悉,希望 不會很難看xd include include using s...
用C 寫了個Convert類,僅供新手學習
convert.h class convert convert 是否小寫 static bool islower int c 是否大寫 static bool isupper int c 轉換成小寫 static int tolower int c 轉換成大寫 static int toupper ...
c 如何擴充套件系統內建類(C 3 0)
c 3.0 vs2008 支援在任何型別上擴充套件生成自定義的方法。比如說想在string型別的物件裡面多乙個toint32 來方便的將字元轉換成整形。在實現的過程中的關鍵字為static和this 下面我們來做乙個在string型別中新建乙個toint32的自定義方法 view code publ...