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


C# LLSDMap.ContainsKey方法代码示例

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


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

示例1: BuildPacket

        /// <summary>
        /// Attempts to convert an LLSD structure to a known Packet type
        /// </summary>
        /// <param name="capsEventName">Event name, this must match an actual
        /// packet name for a Packet to be successfully built</param>
        /// <param name="body">LLSD to convert to a Packet</param>
        /// <returns>A Packet on success, otherwise null</returns>
        public static Packet BuildPacket(string capsEventName, LLSDMap body)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            // Check if we have a subclass of packet with the same name as this event
            Type type = assembly.GetType("OpenMetaverse.Packets." + capsEventName + "Packet", false);
            if (type == null)
                return null;

            Packet packet = null;

            try
            {
                // Create an instance of the object
                packet = (Packet)Activator.CreateInstance(type);

                // Iterate over all of the fields in the packet class, looking for matches in the LLSD
                foreach (FieldInfo field in type.GetFields())
                {
                    if (body.ContainsKey(field.Name))
                    {
                        Type blockType = field.FieldType;

                        if (blockType.IsArray)
                        {
                            LLSDArray array = (LLSDArray)body[field.Name];
                            Type elementType = blockType.GetElementType();
                            object[] blockArray = (object[])Array.CreateInstance(elementType, array.Count);

                            for (int i = 0; i < array.Count; i++)
                            {
                                LLSDMap map = (LLSDMap)array[i];
                                blockArray[i] = ParseLLSDBlock(map, elementType);
                            }

                            field.SetValue(packet, blockArray);
                        }
                        else
                        {
                            LLSDMap map = (LLSDMap)((LLSDArray)body[field.Name])[0];
                            field.SetValue(packet, ParseLLSDBlock(map, blockType));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log(e.Message, Helpers.LogLevel.Error, e);
            }

            return packet;
        }
开发者ID:jhs,项目名称:libopenmetaverse,代码行数:59,代码来源:CapsToPacket.cs

示例2: ParseLLSDBlock

        private static object ParseLLSDBlock(LLSDMap blockData, Type blockType)
        {
            object block = Activator.CreateInstance(blockType);

            // Iterate over each field and set the value if a match was found in the LLSD
            foreach (FieldInfo field in blockType.GetFields())
            {
                if (blockData.ContainsKey(field.Name))
                {
                    Type fieldType = field.FieldType;

                    if (fieldType == typeof(ulong))
                    {
                        // ulongs come in as a byte array, convert it manually here
                        byte[] bytes = blockData[field.Name].AsBinary();
                        ulong value = Utils.BytesToUInt64(bytes);
                        field.SetValue(block, value);
                    }
                    else if (fieldType == typeof(uint))
                    {
                        // uints come in as a byte array, convert it manually here
                        byte[] bytes = blockData[field.Name].AsBinary();
                        uint value = Utils.BytesToUInt(bytes);
                        field.SetValue(block, value);
                    }
                    else if (fieldType == typeof(ushort))
                    {
                        // Just need a bit of manual typecasting love here
                        field.SetValue(block, (ushort)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(byte))
                    {
                        // Just need a bit of manual typecasting love here
                        field.SetValue(block, (byte)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(short))
                    {
                        field.SetValue(block, (short)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(string))
                    {
                        field.SetValue(block, blockData[field.Name].AsString());
                    }
                    else if (fieldType == typeof(bool))
                    {
                        field.SetValue(block, blockData[field.Name].AsBoolean());
                    }
                    else if (fieldType == typeof(float))
                    {
                        field.SetValue(block, (float)blockData[field.Name].AsReal());
                    }
                    else if (fieldType == typeof(double))
                    {
                        field.SetValue(block, blockData[field.Name].AsReal());
                    }
                    else if (fieldType == typeof(int))
                    {
                        field.SetValue(block, blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(UUID))
                    {
                        field.SetValue(block, blockData[field.Name].AsUUID());
                    }
                    else if (fieldType == typeof(Vector3))
                    {
                        Vector3 vec = ((LLSDArray)blockData[field.Name]).AsVector3();
                        field.SetValue(block, vec);
                    }
                    else if (fieldType == typeof(Vector4))
                    {
                        Vector4 vec = ((LLSDArray)blockData[field.Name]).AsVector4();
                        field.SetValue(block, vec);
                    }
                    else if (fieldType == typeof(Quaternion))
                    {
                        Quaternion quat = ((LLSDArray)blockData[field.Name]).AsQuaternion();
                        field.SetValue(block, quat);
                    }
                }
            }

            // Additional fields come as properties, Handle those as well.
            foreach (PropertyInfo property in blockType.GetProperties())
            {
                if (blockData.ContainsKey(property.Name))
                {
                    LLSDType proptype = blockData[property.Name].Type;
                    MethodInfo set = property.GetSetMethod();

                    if (proptype.Equals(LLSDType.Binary))
                    {
                        set.Invoke(block, new object[] { blockData[property.Name].AsBinary() });
                    }
                    else
                        set.Invoke(block, new object[] { Utils.StringToBytes(blockData[property.Name].AsString()) });
                }
            }

            return block;
        }
开发者ID:jhs,项目名称:libopenmetaverse,代码行数:100,代码来源:CapsToPacket.cs

示例3: ParseLLSDBlock

        private static object ParseLLSDBlock(LLSDMap blockData, Type blockType)
        {
            object block = Activator.CreateInstance(blockType);

            // Iterate over each field and set the value if a match was found in the LLSD
            foreach (FieldInfo field in blockType.GetFields())
            {
                if (blockData.ContainsKey(field.Name))
                {
                    Type fieldType = field.FieldType;

                    if (fieldType == typeof(ulong))
                    {
                        // ulongs come in as a byte array, convert it manually here
                        byte[] bytes = blockData[field.Name].AsBinary();
                        ulong value = Helpers.BytesToUInt64(bytes);
                        field.SetValue(block, value);
                    }
                    else if (fieldType == typeof(uint))
                    {
                        // uints come in as a byte array, convert it manually here
                        byte[] bytes = blockData[field.Name].AsBinary();
                        uint value = Helpers.BytesToUIntBig(bytes);
                        field.SetValue(block, value);
                    }
                    else if (fieldType == typeof(ushort))
                    {
                        // Just need a bit of manual typecasting love here
                        field.SetValue(block, (ushort)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(byte))
                    {
                        // Just need a bit of manual typecasting love here
                        field.SetValue(block, (byte)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(short))
                    {
                        field.SetValue(block, (short)blockData[field.Name].AsInteger());
                    }
                    else if (fieldType == typeof(LLUUID))
                    {
                        field.SetValue(block, blockData[field.Name].AsUUID());
                    }
                    else if (fieldType == typeof(LLVector3))
                    {
                        field.SetValue(block, LLVector3.FromLLSD(blockData[field.Name]));
                    }
                    else if (fieldType == typeof(LLVector4))
                    {
                        field.SetValue(block, LLVector4.FromLLSD(blockData[field.Name]));
                    }
                    else if (fieldType == typeof(LLQuaternion))
                    {
                        field.SetValue(block, LLQuaternion.FromLLSD(blockData[field.Name]));
                    }
                    else if (fieldType == typeof(string))
                    {
                        field.SetValue(block, blockData[field.Name].AsString());
                    }
                    else if (fieldType == typeof(bool))
                    {
                        field.SetValue(block, blockData[field.Name].AsBoolean());
                    }
                    else if (fieldType == typeof(float))
                    {
                        field.SetValue(block, (float)blockData[field.Name].AsReal());
                    }
                    else if (fieldType == typeof(double))
                    {
                        field.SetValue(block, blockData[field.Name].AsReal());
                    }
                    else if (fieldType == typeof(int))
                    {
                        field.SetValue(block, blockData[field.Name].AsInteger());
                    }
                }
            }

            // String fields are properties, pick those up as well
            foreach (PropertyInfo property in blockType.GetProperties())
            {
                if (blockData.ContainsKey(property.Name))
                {
                    MethodInfo set = property.GetSetMethod();
                    set.Invoke(block, new object[] { Helpers.StringToField(blockData[property.Name].AsString()) });
                }
            }

            return block;
        }
开发者ID:Belxjander,项目名称:Asuna,代码行数:90,代码来源:CapsToPacket.cs


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