本來以為, .Net 編譯出來的東西與 mono 是不通用的.
可是很奇怪,在網路上都找不到相關的文件來解釋為甚麼 nant 用 mono 編譯會有警告/錯誤或是為甚麼 nhibernate 用 mono 編譯會有警告/錯誤之類的問題.
照理來說,如果是很常見的問題,都應該早有人問了才對.
昨天,赫然發現,其實是通用的.
我用 .Net Framework 1.1 編譯好一個簡單的 hello world 程式,然後放到 linux 上,以 mono 執行.
果然可以執行…
換句話說……我是豬頭……
早就該想到了,如果都 follow ECMA 的標準,其實都是通用的才對!!!
真是笨.
Inversion of Control
本想看看 .Net 實做 Spring 的專案的.找著找著,又看到了 Castle. 後來發現他們都用了所謂的 Inversion of Control 的概念.
這我就好奇了,甚麼是 Inversion of Control ??
在這裡看到一段很好的解說:
“That’s the basic concept of Inversion of Control; you don’t create your objects, you describe how they should be created. You don’t directly connect your components and services together in code, you describe which services are needed by which components, and the container is responsible for hooking it all together. The container creates all the objects, wires them together by setting the necessary properties, and determines when methods are invoked.”
然後提到大致上有三種實做的方式:
type-3 Services dependencies are provided as constructor parameters (and are not exposed as JavaBeans properties). This is the exclusive approach used by PicoContainer, and is also used in HiveMind and Spring.
接著又提到 Inversion of Control Container 應該被稱為 Dependency Injection pattern 會比較恰當…看這篇:Inversion of Control Containers and the Dependency Injection pattern
PicoContainer 與 Castle 很接近,應該都屬於 type-3 – constructor injection, 此外也有很重的 Interface Injection 味道.
上面那篇文章寫的很好,可以算是經典文了.
其他參考性的東西,不再贅述…
*Castle 官網上對 IoC 的說明就直接貼出兩篇經典文的網址.
*c# 對 IoC 的實做,目前有三個實做: StructureMap, Castle, Spring.net
*Open Source Inversion of Control Containers in C#
*Design Better Software with the Inversion of Control Pattern
*Inversion of Control
*PicoContainer – Inversion of Control
*Apache Excalibur – guide-patterns-ioc
本性解碼
在愛麗絲夢遊部落格仙境: 本性解碼逛到的,既逛之,則玩之.
我的結果大致是這樣:
雙子 50%
天蠍 20%
獅子 10%
牡羊 20%
整體性格
elleryq先生,靈活變通;溫柔體貼;開朗隨和;禮貌周到;努力向上也享受生活。
待人性格
elleryq先生待人:合情合理;重視感情;既喜歡與人同樂也能樂於獨處;有自信但不愛出風頭;有親疏觀念但不過分;大方坦蕩但也能保守秘密。
處世性格
elleryq先生處事:善於表達意見但不愛管閒事;隨和有彈性;行事圓融;把握重點兼顧細節;比較理想化;既有計劃也靈活應變。
性格缺點
elleryq先生性格的缺點為:容易產生忌妒心;有時候缺乏享受浪漫的心情;偶爾會動作緩慢老是慢半拍。
價值觀
elleryq先生重視的價值觀為:愛情的滋潤;和諧的人際關係;勢力範圍;較不擅長:與眾不同;追逐功利;出頭爭先。
愛情性格
elleryq先生在愛情上喜歡快速的進展步調,很羅曼蒂克,享受獨立也喜歡有人作伴;較常表現:幽默風趣,情深意濃,認真執著,優雅大方。
金錢性格
elleryq先生的金錢觀:花錢有分寸不浪費也不小氣,喜歡按照計劃用錢;容易把錢用於:追求新奇,享受浪漫,紓解壓力,崇尚唯美。
還可以看五星運勢,不過那是算當天的,就不貼了…
要直接算的話,點這裡吧…
mod_mono AutoConfiguration
Mono 1.1.10 前幾天 release 了,在 asp.net 方面,多了一個很方便的功能 – AutoConfiguration.
在之前,每次添加一個 asp.net application, 就需要去更動 mod_mono 設定,相當麻煩.
現在可以不用了,只要在 mod_mono.conf 添加
MonoAutoApplication enabled
之後,就可以很方便的跟寫 php application 一樣,建立目錄以後,就等同於是建立 application.
舉例來說,你在你的 Home directory 編修一個 asp.net 網頁
$ echo $USER
rupert
$ cd
$ cd public_html
$ mkdir demo
$ cd demo
$ edit hello.aspx
那麼,你編寫完以後,就可以直接
http://your_server/~rupert/demo/hello.aspx
真的是…太方便啦… 🙂
Mono Directions
今早在LinuxToday上看到Mono Directions…
裡面報導了目前的現況,以及未來的方向.
我只摘錄我有興趣的幾個項目:
*mono 1.2 要等到 Windows.Form 完備以後才 release
*gmcs (.Net 2.0 c# compiler) 除了 nullable types 之外,已經齊全.
*monodevelop, 可以寫 plugin 來 enhance 了,我最期待的是 asp.net designer…
*asp.net 2.0 在進行中,但已經有不少 control 可用,而 Atlas 也開始實做.
*msbuild 也有替代品 – xbuild…但還沒作為正式 release 的內容 (Google Summer of code projects 的成品)
*xaml 也有人實作了. (Google Summer of code projects 的成品)
*ADO.Net 2.0 進行中.
其他又學到的,原來有 mono debugger可用…
介面非常類似 gdb,對熟悉 linux 程式寫作的人,不難上手.
UML 2.0
關於UML 2.0,網路上的資源很多。你可以直接下載OMG的UML 2.0文件,網址在:http://www.omg.org/cgi-bin/apps/doc?ptc/04-10-02.pdf。
另外,http://www.uml.org/#UML2.0 有許多UML相關的連結,也值得去看看。
出塞曲
這可不是王昭君的出塞曲.
而是駐塞內加爾農業技術團的撤退紀實.
*出塞曲–自塞內加爾撤退紀實(上) – New Africa
*出塞曲–自塞內加爾撤退紀實(下) – New Africa
看來新聞言過其實啊.
.Net attribute
attribute, 用來為 class, method, parameters 貼上標籤,以便後續的應用.
所有的 attribute class 都要繼承 System.Attribute
class Class1Attribute: System.Attribute
{
}
使用的時候可以省略 Attribute
[Class1]
class Class2
{
}
打全名當然也是可以
[Class1Attribute]
class Class2
{
}
使用 xxx( yyy ) 時,attribute 的 constructor 會被套用,而 attribute class 裡的 property 會被自動認定為 named parameter.
class Class1Attribute: System.Attribute
{
private int _id;
private string _name;
public Class1Attribute( int id )
{
_id = id;
}
public string Name
{
get { return _name };
set { _name = value };
}
}
[Class1( 1, Name="This is a test" )]
class class2
{
}
也可以貼很多標籤上去
[AttributeUsage(AttributeTargets.Class, AllowMultiple=true)]
class Class1Attribute: System.Attribute
{
....
}
[Class1( 1, Name="This is a test" ), Class1( 2, Name="Test2" )]
class class2
{
}
但是要怎麼應用呢? 從 .Net framework documentation 裡的 sample, 大致上可以猜到.
using System;
using System.Reflection;
namespace CustomAttrCS {
// An enumeration of animals. Start at 1 (0 = uninitialized).
public enum Animal {
// Pets.
Dog = 1,
Cat,
Bird,
}
// A custom attribute to allow a target to have a pet.
public class AnimalTypeAttribute : Attribute {
// The constructor is called when the attribute is set.
public AnimalTypeAttribute(Animal pet) {
thePet = pet;
}
// Keep a variable internally ...
protected Animal thePet;
// .. and show a copy to the outside world.
public Animal Pet {
get { return thePet; }
set { thePet = Pet; }
}
}
// A test class where each method has its own pet.
class AnimalTypeTestClass {
[AnimalType(Animal.Dog)]
public void DogMethod() {}
[AnimalType(Animal.Cat)]
public void CatMethod() {}
[AnimalType(Animal.Bird)]
public void BirdMethod() {}
}
class DemoClass {
static void Main(string[] args) {
AnimalTypeTestClass testClass = new AnimalTypeTestClass();
Type type = testClass.GetType();
// Iterate through all the methods of the class.
foreach(MethodInfo mInfo in type.GetMethods()) {
// Iterate through all the Attributes for each method.
foreach (Attribute attr in Attribute.GetCustomAttributes(mInfo)) {
// Check for the AnimalType attribute.
if (attr.GetType() == typeof(AnimalTypeAttribute))
Console.WriteLine(
"Method {0} has a pet {1} attribute.",
mInfo.Name, ((AnimalTypeAttribute)attr).Pet);
}
}
}
}
}
所以你可以看到,在貼上標籤以後,其實對 Class 本身來說沒啥作用,會認為有用的,是其他的 Class, 他們可以依據這些 Attribute 來作一些特定的處理.
這邊有一系列的文章,還提出了應用.
- 博客园 – dudu – Attribute在.net编程中的应用(一)
- 博客园 – dudu – Attribute在.net编程中的应用(二)
- 博客园 – dudu – Attribute在.NET编程中的应用(三)
- 博客园 – dudu – Attribute在.NET编程中的应用(四)
- 博客园 – dudu – Attribute在.NET编程中的应用(五)
- 博客园 – dudu – Attribute在.NET编程的应用(六)
系列 2~4 介紹一個 sql generator 的範例.
系列 5~6 是一個比較深的範例,牽涉到 Remoting 的東西
.Net framework 內也預定了不少 Attribute,我覺得還蠻有用的.
例如: Conditional attribute
以下面的範例來說,如果 DEBUG 沒被定義,那麼 Class1.M() 將不會被執行.
這倒是一個不錯的debug方法
#define DEBUG
using System;
using System.Diagnostics;
class Class1
{
[Conditional("DEBUG")]
public static void M() {
Console.WriteLine("Executed Class1.M");
}
}
class Class2
{
public static void Test() {
Class1.M();
}
}
仔細想想也可以用來作版本控管喔…某版本可以用這個 method, 但是某版本不行….
還有就是 Obsolete, 可以用來指示 class 或 method 即將被淘汰
2005/11/05慶生會
[新酷音]ChewingServer無法啟動
公司的電腦老是無法使用新酷音輸入法.
狀況是這樣子的,切換到新酷音輸入法之後,打任何字都會造成短暫的延遲,無法輸入.
大致的猜測,是因為 ChewingServer 無法載入.
利用 svn 下載 source code(包含 library) 之後
svn co https://svn.csie.net/chewing/win32-chewing/
svn co https://svn.csie.net/chewing/libchewing/
svn co https://svn.csie.net/chewing/libchewingpp/
進行 Trace, 花了不到十五分鐘,就找出原因.
答案是因為在載入家目錄下的 hash.dat ( 在 \Document and settings\xxx\application data\chewing\hash.dat)時,發生了異常,導致整個 ChewingServer crash.
這也是為甚麼會有短暫延遲的原因,每輸入一個字,新酷音輸入法就會試著去啟動 ChewingServer,每次啟動,每次都 crash, 因此就會有延遲.
刪除掉 hash.dat, 讓ChewingServer重新產生以後就行了.
這個問題也回報到這裡了…(很遺憾,第一次填寫,搞不清楚甚麼欄位要填啥,不小心把主旨填成自己的名字了,而且回報的內容也不夠好…下次改進)
