.NET – Plugin

我之前在 .NET – Load Plugins 寫過如何實做簡單的 plugin interface,最近真正在用的時候才發現問題。

Assembly.Load* 雖然可以把 .dll 檔案動態載入,可是卻找不到任何方法可以 unload.. Assembly 在被載入之後是處於鎖定的狀態,如果這時候把檔案換掉的話,Assembly.Load 便無法再重新載入,會出現 Exception

這樣就沒辦法在後端偷偷換掉 backend 了 -_-

要實做動態的 load, unload 好像是要使用 System.AppDomain 來做(時際上是用 Remoting 的技術),看似簡單,可是我試到現在還沒成功過… 還變成好像 Assembly 被 Cache 起來的情況,怎麼 load, unload 都是用到舊的 Assembly… 天阿

參考:通过应用程序域AppDomain加载和卸载程序集之后,如何再返回原来的主程序域

Leaftag

gmail 的 label 分類方法帶動一股檔案管理的新風氣,陸陸續續有人針對桌面應用提出各種實做。之前的 CatFS 就是其中之一。

今天在 PlanetGnome 上看到 chipx86 的新作品 Leaftag,一個 GObject-based 的 library,引述網站上的介紹:

Leaftag is a library and set of utilities for tagging files on the Linux desktop. It’s a convenient way of organizing files in a non-hierarchical manner. Local files, websites, or anything with a URI can be tagged with one or more names and easily referenced by anything that supports Leaftag.

另外有 command line 的工具 tagutils 可以用來 tag, untag 等 tag 管理,還有 python binding,gnome plugins 等等。

因為是 userspace 的工具加上有 library 的介面,感覺還滿不錯的。做了 deb 出來測試,想要用的人可以將 apt.debian.org.tw 加到 sources.list 裡,然後

$ apt-get update && apt-get install tagutils
$ ls
mypic1.png  mypic2.png  mypic3.png
$ tag work mypic1.png
$ tag love mypic2.png
$ tag work,love mypic3.png
$ tags
love
work
$ tagls love
/home/kanru/work/test/mypic2.png
/home/kanru/work/test/mypic3.png
$ tagls work
/home/kanru/work/test/mypic1.png
/home/kanru/work/test/mypic3.png
$ tag url http://blog.kanru.info
$ tagls url
http://blog.kanru.info

Short, Int, 加加減減

在 C 裡面,我們可能不小心寫出這樣的 code 而不自覺會造成 overflow

short x = 32767;
x = x + 2;

但是在 C# 則會得到

error CS0266: Cannot implicitly convert type 'int' to 'short'. \
       An explicit conversion exists (are you missing a cast?)

要改成

x = (short)(x +2);

才行;
不過神奇的是,如果寫成

x += 2;

則不會有任何問題的直接 overflow… 這究竟是什麼樣的設計考量呢?