在AO或者是AE的二次開發中,介面查詢(QI)技術被認為是最基本,同時也是最重要的技術之一,幾乎每一個GIS系統,甚至是一個小小的GIS功能模組,都不可能不用到介面查詢技術。通俗地說,QI就是類中的顯式強制轉換,請看下面例子。/*
* Created by SharpDevelop.
* User: noo
* Date: 2009-8-18
* Time: 15:46
*
* 介面查詢(QI)
*/
using System ;
interface IApple//蘋果介面
{
string spice//香屬性
{
get;
set;
}
void circle();//圓方法
}
interface IBanana//香蕉介面
{
string sweet//甜屬性
{
get;
set;
}
void column();//柱方法
}
class Fruit:IApple,IBanana//水果類
{
private string str1;
string IApple.spice//注意這裡的寫法
{
get{return str1;}
set{str1=value;}
}
void IApple.circle()//同上
{
Console.WriteLine ("蘋果介面的成員函數");
}
private string str2;
string IBanana.sweet
{
get{return str2;}
set{str2=value;}
}
void IBanana.column()
{
Console.WriteLine ("香蕉介面的成員函數");
}
}
class Test
{
static void Main()
{
IApple pApple=new Fruit ();//執行個體化介面類型的類
pApple.circle ();
pApple.spice ="香蘋果";
Console.WriteLine (pApple.spice );
IBanana pBanana=new Fruit ();
pBanana.column ();
pBanana.sweet ="甜香蕉";
Console.WriteLine (pBanana.sweet );
IApple pApp=new Fruit ();
IBanana pBan=pApp as IBanana ;//介面查詢(QI),這裡其實就是一個顯式的強制轉換
pBan.column ();
pBan.sweet ="甜香蕉";
Console.WriteLine (pBan.sweet );
}
}從上面例子可以看出,QI其實是很好掌握的,原理非常簡單