国产探花免费观看_亚洲丰满少妇自慰呻吟_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
        }
    }
}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 靖边县| 张家港市| 皋兰县| 涟水县| 同江市| 永嘉县| 进贤县| 桑植县| 鲁甸县| 酒泉市| 海晏县| 嘉义市| 班戈县| 外汇| 彭阳县| 延长县| 汤阴县| 翁牛特旗| 阳高县| 沙坪坝区| 桂阳县| 盐边县| 襄汾县| 辉县市| 峨眉山市| 阳曲县| 高雄县| 牡丹江市| 启东市| 西青区| 台东市| 武鸣县| 麻城市| 彰武县| 板桥市| 南通市| 怀化市| 绩溪县| 桃源县| 二连浩特市| 中阳县|