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


C# KeyValuePair.GetType方法代码示例

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


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

示例1: Convert


//.........这里部分代码省略.........
                var simple_way = new OsmSharp.Osm.Way();
                simple_way.Id = way.id;
                simple_way.Nodes = new List<long>(way.refs.Count);
                long node_id = 0;
                for (int node_idx = 0; node_idx < way.refs.Count; node_idx++)
                {
                    node_id = node_id + way.refs[node_idx];
                    simple_way.Nodes.Add(node_id);
                }
                if (way.keys.Count > 0)
                {
                    simple_way.Tags = new TagsCollection();
                    for (int tag_idx = 0; tag_idx < way.keys.Count; tag_idx++)
                    {
                        string key = Encoding.UTF8.GetString(block.stringtable.s[(int)way.keys[tag_idx]]);
                        string value = Encoding.UTF8.GetString(block.stringtable.s[(int)way.vals[tag_idx]]);

                        if (!simple_way.Tags.ContainsKey(key))
                        {
                            simple_way.Tags.Add(new Tag(key, value));
                        }
                    }
                }
                if (way.info != null)
                { // add the metadata if any.
                    simple_way.ChangeSetId = way.info.changeset;
                    simple_way.TimeStamp = Utilities.FromUnixTime((long)way.info.timestamp *
                        (long)block.date_granularity);
                    simple_way.UserId = way.info.uid;
                    simple_way.UserName = Encoding.UTF8.GetString(block.stringtable.s[way.info.user_sid]);
                    simple_way.Version = (ulong)way.info.version;
                }
                simple_way.Visible = true;

                return simple_way;
            }
            else if (pbfPrimitive.Value is OsmSharp.Osm.PBF.Relation)
            {
                var relation = (pbfPrimitive.Value as OsmSharp.Osm.PBF.Relation);

                var simple_relation = new OsmSharp.Osm.Relation();
                simple_relation.Id = relation.id;
                if (relation.types.Count > 0)
                {
                    simple_relation.Members = new List<OsmSharp.Osm.RelationMember>();
                    long member_id = 0;
                    for (int member_idx = 0; member_idx < relation.types.Count; member_idx++)
                    {
                        member_id = member_id + relation.memids[member_idx];
                        string role = Encoding.UTF8.GetString(
                            block.stringtable.s[relation.roles_sid[member_idx]]);
                        var member = new OsmSharp.Osm.RelationMember();
                        member.MemberId = member_id;
                        member.MemberRole = role;
                        switch (relation.types[member_idx])
                        {
                            case Relation.MemberType.NODE:
                                member.MemberType = OsmSharp.Osm.OsmGeoType.Node;
                                break;
                            case Relation.MemberType.WAY:
                                member.MemberType = OsmSharp.Osm.OsmGeoType.Way;
                                break;
                            case Relation.MemberType.RELATION:
                                member.MemberType = OsmSharp.Osm.OsmGeoType.Relation;
                                break;
                        }

                        simple_relation.Members.Add(member);
                    }
                }
                if (relation.keys.Count > 0)
                {
                    simple_relation.Tags = new TagsCollection();
                    for (int tag_idx = 0; tag_idx < relation.keys.Count; tag_idx++)
                    {
                        string key = Encoding.UTF8.GetString(block.stringtable.s[(int)relation.keys[tag_idx]]);
                        string value = Encoding.UTF8.GetString(block.stringtable.s[(int)relation.vals[tag_idx]]);

                        if (!simple_relation.Tags.ContainsKey(key))
                        {
                            simple_relation.Tags.Add(new Tag(key, value));
                        }
                    }
                }
                if (relation.info != null)
                { // read metadata if any.
                    simple_relation.ChangeSetId = relation.info.changeset;
                    simple_relation.TimeStamp = Utilities.FromUnixTime((long)relation.info.timestamp *
                        (long)block.date_granularity);
                    simple_relation.UserId = relation.info.uid;
                    simple_relation.UserName = Encoding.UTF8.GetString(block.stringtable.s[relation.info.user_sid]);
                    simple_relation.Version = (ulong)relation.info.version;
                }
                simple_relation.Visible = true;

                return simple_relation;
            }
            throw new Exception(string.Format("PBF primitive with type {0} not supported!",
                pbfPrimitive.GetType().ToString()));
        }
开发者ID:nubix-biz,项目名称:OsmSharp,代码行数:101,代码来源:PBFOsmStreamSource.cs

示例2: Test

        /// <summary></summary>
        public static void Test()
        {
            XTrace.WriteLine("创建类型……");

            #region TypeX类型
            TypeX type = TypeX.Create(typeof(FastTest));
            Object obj = type.CreateInstance();
            Debug.Assert(obj != null, "创建实例出错!");

            obj = type.CreateInstance(123);
            Debug.Assert(obj != null, "创建实例出错!");

            //obj = type.CreateInstance("1234");
            //Debug.Assert(obj != null, "创建实例出错!");

            obj = type.CreateInstance(111, "aaa");
            Debug.Assert(obj != null, "创建实例出错!");

            XTrace.WriteLine("创建值类型实例");
            type = TypeX.Create(typeof(ConsoleKeyInfo));
            obj = type.CreateInstance();
            Debug.Assert(obj != null, "创建值类型实例出错!");

            XTrace.WriteLine("创建数组类型实例");
            type = TypeX.Create(typeof(ConsoleKeyInfo[]));
            obj = type.CreateInstance(5);
            Debug.Assert(obj != null, "创建数组类型实例出错!");
            #endregion

            #region 构造函数
            ConstructorInfoX ctr = ConstructorInfoX.Create(typeof(FastTest));
            obj = ctr.CreateInstance();
            Debug.Assert(obj != null, "创建实例出错!");

            ctr = ConstructorInfoX.Create(typeof(FastTest), new Type[] { typeof(Int32) });
            obj = ctr.CreateInstance(123);
            Debug.Assert(obj != null, "创建实例出错!");
            ctr = ConstructorInfoX.Create(typeof(FastTest), new Type[] { typeof(Int32), typeof(String) });
            obj = ctr.CreateInstance(111, "aaa");
            Debug.Assert(obj != null, "创建实例出错!");
            #endregion

            #region 字段
            FieldInfoX field = FieldInfoX.Create(typeof(FastTest), "_ID");
            (obj as FastTest).ID = 111;
            Int32 v = (Int32)field.GetValue(obj);
            Debug.Assert(v == 111, "字段取值出错!");
            field.SetValue(obj, 888);
            v = (Int32)field.GetValue(obj);
            Debug.Assert(v == 888, "字段赋值出错!");

            KeyValuePair<Int32, Int32> kv = new KeyValuePair<int, int>(123456, 222);
            field = FieldInfoX.Create(kv.GetType(), "Key");
            //field.SetValue(kv, 123456);
            v = (Int32)field.GetValue(kv);
            Debug.Assert(v == 123456, "字段取值出错!");

            field = FieldInfoX.Create(typeof(FastTest), "_Name");
            field.SetValue("动态赋值");
            String v2 = (String)field.GetValue();
            Debug.Assert(v2 == "动态赋值", "静态字段出错!");
            #endregion

            #region 属性
            PropertyInfoX p = typeof(FastTest).GetProperty("ID");

            v = (Int32)p.GetValue(obj);
            Debug.Assert(v == 888, "属性取值出错!");
            p.SetValue(obj, 999);
            v = (Int32)p.GetValue(obj);
            Debug.Assert(v == 999, "属性赋值出错!");

            p = PropertyInfoX.Create(typeof(FastTest), "Name");
            field.SetValue("属性动态赋值");
            v2 = (String)field.GetValue();
            Debug.Assert(v2 == "属性动态赋值", "静态字段出错!");
            #endregion

            #region 方法
            MethodInfoX method = MethodInfoX.Create(typeof(FastTest), "Test2");
            method.Invoke(obj);

            method = typeof(FastTest).GetMethod("GetFullName");
            Console.WriteLine(method.Invoke(null, 123, "abc"));
            #endregion
        }
开发者ID:BiYiTuan,项目名称:soa,代码行数:87,代码来源:FastTest.cs


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