当前位置: 首页>>代码示例>>C#>>正文


C# Guid.GetBytes方法代码示例

本文整理汇总了C#中System.Guid.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Guid.GetBytes方法的具体用法?C# Guid.GetBytes怎么用?C# Guid.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Guid的用法示例。


在下文中一共展示了Guid.GetBytes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Guids

        public void Guids()
        {
            // Creation
            Guid a = new Guid();
            byte[] bytes = a.GetBytes();
            for (int i = 0; i < 16; i++)
                Assert.IsTrue(bytes[i] == 0x00);

            // Comparison
            a = new Guid(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
                0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0xFF, 0xFF }, 0);
            Guid b = new Guid(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
                0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, 0);

            Assert.IsTrue(a == b, "Guid comparison operator failed, " + a.ToString() + " should equal " + 
                b.ToString());

            // From string
            a = new Guid(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
                0x0B, 0x0C, 0x0D, 0x0E, 0x0F }, 0);
            string zeroonetwo = "00010203-0405-0607-0809-0a0b0c0d0e0f";
            b = new Guid(zeroonetwo);

            Assert.IsTrue(a == b, "Guid hyphenated string constructor failed, should have " + a.ToString() + 
                " but we got " + b.ToString());

            // ToString()
            string one = a.ToString();
            string two = b.ToString();
            Assert.IsTrue(a == b);
            one = a.ToString();
            two = b.ToString();
            Assert.IsTrue(a == b);
            Assert.IsTrue(a == (Guid)zeroonetwo);

            // TODO: CRC test
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:37,代码来源:TypeTests.cs

示例2: VoiceAccountFromGuid

 public string VoiceAccountFromGuid(Guid id)
 {
     string result = "x" + Convert.ToBase64String(id.GetBytes());
     return result.Replace('+', '-').Replace('/', '_');
 }
开发者ID:RavenB,项目名称:gridsearch,代码行数:5,代码来源:VoiceManager.cs

示例3: GiveFolder

        /// <summary>
        /// Give an inventory Folder with contents to another avatar
        /// </summary>
        /// <param name="folderID">The <seealso cref="Guid"/> of the Folder to give</param>
        /// <param name="folderName">The name of the folder</param>
        /// <param name="assetType">The type of the item from the <seealso cref="AssetType"/> enum</param>
        /// <param name="recipient">The <seealso cref="Guid"/> of the recipient</param>
        /// <param name="doEffect">true to generate a beameffect during transfer</param>
        public void GiveFolder(Guid folderID, string folderName, AssetType assetType, Guid recipient,
            bool doEffect)
        {
            byte[] bucket;

                List<InventoryItem> folderContents = new List<InventoryItem>();

                _Client.Inventory.FolderContents(folderID, _Client.Self.AgentID, false, true, InventorySortOrder.ByDate, 1000 * 15).ForEach(
                    delegate(InventoryBase ib)
                    {
                        folderContents.Add(_Client.Inventory.FetchItem(ib.Guid, _Client.Self.AgentID, 1000 * 10));
                    });
                bucket = new byte[17 * (folderContents.Count + 1)];

                //Add parent folder (first item in bucket)
                bucket[0] = (byte)assetType;
                Buffer.BlockCopy(folderID.GetBytes(), 0, bucket, 1, 16);

                //Add contents to bucket after folder
                for (int i = 1; i <= folderContents.Count; ++i)
                {
                    bucket[i * 17] = (byte)folderContents[i - 1].AssetType;
                    Buffer.BlockCopy(folderContents[i - 1].Guid.GetBytes(), 0, bucket, i * 17 + 1, 16);
                }

            _Client.Self.InstantMessage(
                    _Client.Self.Name,
                    recipient,
                    folderName,
                    Guid.NewGuid(),
                    InstantMessageDialog.InventoryOffered,
                    InstantMessageOnline.Online,
                    _Client.Self.SimPosition,
                    _Client.Network.CurrentSim.ID,
                    bucket);

            if (doEffect)
            {
                _Client.Self.BeamEffect(_Client.Self.AgentID, recipient, Vector3d.Zero,
                    _Client.Settings.DEFAULT_EFFECT_COLOR, 1f, Guid.NewGuid());
            }
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:50,代码来源:InventoryManager.cs

示例4: PackGuid

        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        public void PackGuid(Guid data)
        {
            byte[] bytes = data.GetBytes();

            // Not sure if our PackBitArray function can handle 128-bit byte
            //arrays, so using this for now
            for (int i = 0; i < 16; i++)
                PackBits(bytes[i], 8);
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:13,代码来源:BitPack.cs

示例5: GiveItem

        /// <summary>
        /// Give an inventory item to another avatar
        /// </summary>
        /// <param name="itemID">The <seealso cref="Guid"/> of the item to give</param>
        /// <param name="itemName">The name of the item</param>
        /// <param name="assetType">The type of the item from the <seealso cref="AssetType"/> enum</param>
        /// <param name="recipient">The <seealso cref="Guid"/> of the recipient</param>
        /// <param name="doEffect">true to generate a beameffect during transfer</param>
        public void GiveItem(Guid itemID, string itemName, AssetType assetType, Guid recipient,
            bool doEffect)
        {
            byte[] bucket;


                bucket = new byte[17];
                bucket[0] = (byte)assetType;
                Buffer.BlockCopy(itemID.GetBytes(), 0, bucket, 1, 16);

            _Client.Self.InstantMessage(
                    _Client.Self.Name,
                    recipient,
                    itemName,
                    Guid.NewGuid(),
                    InstantMessageDialog.InventoryOffered,
                    InstantMessageOnline.Online,
                    _Client.Self.SimPosition,
                    _Client.Network.CurrentSim.ID,
                    bucket);

            if (doEffect)
            {
                _Client.Self.BeamEffect(_Client.Self.AgentID, recipient, Vector3d.Zero,
                    _Client.Settings.DEFAULT_EFFECT_COLOR, 1f, Guid.NewGuid());
            }
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:35,代码来源:InventoryManager.cs

示例6: Xor

        /// <summary>
        /// Combine two Guids with the XOR operator
        /// </summary>
        /// <param name="guid">Guid to XOR with the current Guid</param>
        public static void Xor(this Guid thisGuid, Guid guid)
        {
            byte[] lhsbytes = thisGuid.GetBytes();
            byte[] rhsbytes = guid.GetBytes();
            byte[] output = new byte[16];

            for (int i = 0; i < 16; i++)
                output[i] = (byte)(lhsbytes[i] ^ rhsbytes[i]);

            thisGuid.FromBytes(output, 0);
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:15,代码来源:Guid.cs

示例7: Combine

        /// <summary>
        /// Combine two Guids together by taking the MD5 hash of a byte array
        /// containing both Guids
        /// </summary>
        /// <param name="guid">Guid to combine with the current Guid</param>
        public static void Combine(this Guid thisGuid, Guid guid)
        {
            // Construct the buffer that MD5ed
            byte[] input = new byte[32];
            Buffer.BlockCopy(thisGuid.GetBytes(), 0, input, 0, 16);
            Buffer.BlockCopy(guid.GetBytes(), 0, input, 16, 16);

            thisGuid.FromBytes(Utils.MD5(input), 0);
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:14,代码来源:Guid.cs

示例8: BeamEffect

        /// <summary>
        /// Create a particle beam between an avatar and an primitive
        /// </summary>
        /// <param name="sourceAvatar"><seealso cref="Guid"/> of sources avatar</param>
        /// <param name="targetObject"><seealso cref="Guid"/> of the target</param>
        /// <param name="globalOffset"><seealso cref="Vector3d"/>global offset</param>
        /// <param name="color"><seealso cref="Color4"/>Color values of beam</param>
        /// <param name="duration">a float representing the duration the beam will last</param>
        /// <param name="effectID"><seealso cref="Guid"/> of the Effect</param>
        public void BeamEffect(Guid sourceAvatar, Guid targetObject, Vector3d globalOffset, Color4 color,
            float duration, Guid effectID)
        {
            ViewerEffectPacket effect = new ViewerEffectPacket();

            effect.AgentData.AgentID = Client.Self.AgentID;
            effect.AgentData.SessionID = Client.Self.SessionID;

            effect.Effect = new ViewerEffectPacket.EffectBlock[1];
            effect.Effect[0] = new ViewerEffectPacket.EffectBlock();
            effect.Effect[0].AgentID = Client.Self.AgentID;
            effect.Effect[0].Color = color.GetBytes();
            effect.Effect[0].Duration = duration;
            effect.Effect[0].ID = effectID;
            effect.Effect[0].Type = (byte)EffectType.Beam;

            byte[] typeData = new byte[56];
            Buffer.BlockCopy(sourceAvatar.GetBytes(), 0, typeData, 0, 16);
            Buffer.BlockCopy(targetObject.GetBytes(), 0, typeData, 16, 16);
            Buffer.BlockCopy(globalOffset.GetBytes(), 0, typeData, 32, 24);

            effect.Effect[0].TypeData = typeData;

            Client.Network.SendPacket(effect);
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:34,代码来源:AgentManager.cs

示例9: LookAtEffect

        /// <summary>
        /// Start a particle stream between an agent and an object
        /// </summary>
        /// <param name="sourceAvatar"><seealso cref="Guid"/> Key of the source agent</param>
        /// <param name="targetObject"><seealso cref="Guid"/> Key of the target object</param>
        /// <param name="globalOffset">A <seealso cref="Vector3d"/> representing the beams offset from the source</param>
        /// <param name="type">A <seealso cref="T:PointAtType"/> which sets the avatars lookat animation</param>
        /// <param name="effectID"><seealso cref="Guid"/> of the Effect</param>
        public void LookAtEffect(Guid sourceAvatar, Guid targetObject, Vector3d globalOffset, LookAtType type,
            Guid effectID)
        {
            ViewerEffectPacket effect = new ViewerEffectPacket();

            effect.AgentData.AgentID = Client.Self.AgentID;
            effect.AgentData.SessionID = Client.Self.SessionID;

            float duration;

            switch (type)
            {
                case LookAtType.Clear:
                    duration = 0.0f;
                    break;
                case LookAtType.Hover:
                    duration = 1.0f;
                    break;
                case LookAtType.FreeLook:
                    duration = 2.0f;
                    break;
                case LookAtType.Idle:
                    duration = 3.0f;
                    break;
                case LookAtType.AutoListen:
                case LookAtType.Respond:
                    duration = 4.0f;
                    break;
                case LookAtType.None:
                case LookAtType.Select:
                case LookAtType.Focus:
                case LookAtType.Mouselook:
                    duration = Single.MaxValue / 2.0f;
                    break;
                default:
                    duration = 0.0f;
                    break;
            }

            effect.Effect = new ViewerEffectPacket.EffectBlock[1];
            effect.Effect[0] = new ViewerEffectPacket.EffectBlock();
            effect.Effect[0].AgentID = Client.Self.AgentID;
            effect.Effect[0].Color = new byte[4];
            effect.Effect[0].Duration = duration;
            effect.Effect[0].ID = effectID;
            effect.Effect[0].Type = (byte)EffectType.LookAt;

            byte[] typeData = new byte[57];
            if (sourceAvatar != Guid.Empty)
                Buffer.BlockCopy(sourceAvatar.GetBytes(), 0, typeData, 0, 16);
            if (targetObject != Guid.Empty)
                Buffer.BlockCopy(targetObject.GetBytes(), 0, typeData, 16, 16);
            typeData[56] = (byte)type;

            effect.Effect[0].TypeData = typeData;

            Client.Network.SendPacket(effect);
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:66,代码来源:AgentManager.cs

示例10: PointAtEffect

        /// <summary>
        /// Start a particle stream between an agent and an object
        /// </summary>
        /// <param name="sourceAvatar"><seealso cref="Guid"/> Key of the source agent</param>
        /// <param name="targetObject"><seealso cref="Guid"/> Key of the target object</param>
        /// <param name="globalOffset"></param>
        /// <param name="type">The type from the <seealso cref="T:PointAtType"/> enum</param>
        /// <param name="effectID">A unique <seealso cref="Guid"/> for this effect</param>
        public void PointAtEffect(Guid sourceAvatar, Guid targetObject, Vector3d globalOffset, PointAtType type,
            Guid effectID)
        {
            ViewerEffectPacket effect = new ViewerEffectPacket();

            effect.AgentData.AgentID = Client.Self.AgentID;
            effect.AgentData.SessionID = Client.Self.SessionID;

            effect.Effect = new ViewerEffectPacket.EffectBlock[1];
            effect.Effect[0] = new ViewerEffectPacket.EffectBlock();
            effect.Effect[0].AgentID = Client.Self.AgentID;
            effect.Effect[0].Color = new byte[4];
            effect.Effect[0].Duration = (type == PointAtType.Clear) ? 0.0f : Single.MaxValue / 4.0f;
            effect.Effect[0].ID = effectID;
            effect.Effect[0].Type = (byte)EffectType.PointAt;

            byte[] typeData = new byte[57];
            if (sourceAvatar != Guid.Empty)
                Buffer.BlockCopy(sourceAvatar.GetBytes(), 0, typeData, 0, 16);
            if (targetObject != Guid.Empty)
                Buffer.BlockCopy(targetObject.GetBytes(), 0, typeData, 16, 16);
            Buffer.BlockCopy(globalOffset.GetBytes(), 0, typeData, 32, 24);
            typeData[56] = (byte)type;

            effect.Effect[0].TypeData = typeData;

            Client.Network.SendPacket(effect);
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:36,代码来源:AgentManager.cs


注:本文中的System.Guid.GetBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。