国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

老外編的程序(五)--如何使用全球標識符(GUID)

2024-07-21 02:20:13
字體:
來源:轉載
供稿:網友

最大的網站源碼資源下載站,

// snippet shows how interfaces and coclasses can adorn the guid attribute.
// running the regasm will generate .reg and .tlb files. reg file can be
// used to register the interface and coclass with the registry. tlb file
// are used to do interop. also illustrates how system.guid can be constructed
// and how guid objects can be compared.

namespace guidsnippet
{
    //<snippet1>
    using system;
    using system.runtime.interopservices;

    // guid for the interface ifoo.
    [guid("f9168c5e-ceb2-4faa-b6bf-329bf39fa1e4")]
    interface ifoo
    {
        void foo();
    }

    // guid for the coclass cfoo.
    [guid("936da01f-9abd-4d9d-80c7-02af85c822a8")]
    public class cfoo : ifoo
    {
        // run regasm on this assembly to create .reg and .tlb files.
        // reg file can be used to register this coclass in the registry.
        // tlb file will be used to do interop.

        public void foo() {}

        public static void main( string []args )
        {
            // snippet addresses the following in system.runtime.interopservices.guidattribute.
            // how to specify the attribute on interface/coclass.
            // retrieve the guidattribute from an interface/coclass.
            // value property on guidattribute class.

            // snippet addresses the following in system.guid.
            // constructor guid(string).
            // constructor guid(bytearray).
            // equals.
            // operator ==.
            // compareto.

            attribute ifooattribute = attribute.getcustomattribute( typeof( ifoo ), typeof( guidattribute ) );
            
            // the value property of guidattribute returns a string.
            system.console.writeline( "ifoo attribute: " + ((guidattribute)ifooattribute).value );    

            // using the string to create a guid.
            guid guidfoo1 = new guid( ((guidattribute)ifooattribute).value );
            // using a byte array to create a guid.
            guid guidfoo2 = new guid ( guidfoo1.tobytearray() );

            // equals is overriden and so value comparison is done though references are different.
            if ( guidfoo1.equals( guidfoo2 ) )
                system.console.writeline( "guidfoo1 equals guidfoo2" );
            else
                system.console.writeline( "guidfoo1 not equals guidfoo2" );

            // equality operator can also be used to determine if two guids have same value.
            if ( guidfoo1 == guidfoo2 )
                system.console.writeline( "guidfoo1 == guidfoo2" );
            else
                system.console.writeline( "guidfoo1 != guidfoo2" );
        
            // compareto returns 0 if the guids have same value.
            if ( guidfoo1.compareto( guidfoo2 ) == 0 )
                system.console.writeline( "guidfoo1 compares to guidfoo2" );
            else
                system.console.writeline( "guidfoo1 does not compare to guidfoo2" );

            system.console.readline();

            //output.
            //ifoo attribute: f9168c5e-ceb2-4faa-b6bf-329bf39fa1e4
            //guidfoo1 equals guidfoo2
            //guidfoo1 == guidfoo2
            //guidfoo1 compares to guidfoo2
        }
    }
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 牡丹江市| 祁门县| 阳原县| 融水| 津南区| 枣庄市| 资阳市| 南漳县| 康保县| 黑水县| 黔东| 饶河县| 林州市| 乌兰县| 嵊泗县| 巴林左旗| 斗六市| 淮北市| 扶余县| 庆阳市| 济源市| 桦甸市| 海阳市| 卢龙县| 蛟河市| 南皮县| 黄浦区| 方正县| 哈密市| 会泽县| 东兰县| 沙坪坝区| 巫山县| 西峡县| 嘉义县| 正定县| 逊克县| 米泉市| 四会市| 巫溪县| 确山县|