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


C# ParsingEvent.GetType方法代码示例

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


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

示例1: AssertCurrent

        private void AssertCurrent(Parser parser, ParsingEvent expected)
        {
            Console.WriteLine(expected.GetType().Name);
            Assert.True(expected.GetType().IsAssignableFrom(parser.Current.GetType()), string.Format("The event is not of the expected type. Exprected: {0}, Actual: {1}", expected.GetType().Name, parser.Current.GetType().Name));

            foreach (var property in expected.GetType().GetProperties()) {
                if(property.PropertyType != typeof(Mark) && property.CanRead) {
                    object value = property.GetValue(parser.Current, null);
                    object expectedValue = property.GetValue(expected, null);
                    if(expectedValue != null && Type.GetTypeCode(expectedValue.GetType()) == TypeCode.Object && expectedValue is IEnumerable) {
                        Console.Write("\t{0} = {{", property.Name);
                        bool isFirst = true;
                        foreach(var item in (IEnumerable)value) {
                            if(isFirst) {
                                isFirst = false;
                            } else {
                                Console.Write(", ");
                            }
                            Console.Write(item);
                        }
                        Console.WriteLine("}");

                        if(expectedValue is ICollection && value is ICollection) {
                            Assert.Equal(((ICollection)expectedValue).Count, ((ICollection)value).Count);
                        }

                        IEnumerator values = ((IEnumerable)value).GetEnumerator();
                        IEnumerator expectedValues = ((IEnumerable)expectedValue).GetEnumerator();
                        while(expectedValues.MoveNext()) {
                            Assert.True(values.MoveNext());
                            Assert.Equal(expectedValues.Current, values.Current);
                        }

                        Assert.False(values.MoveNext());
                    } else {
                        Console.WriteLine("\t{0} = {1}", property.Name, value);
                        Assert.Equal(expectedValue, value);
                    }
                }
            }
        }
开发者ID:igor-toporet,项目名称:YamlDotNet,代码行数:41,代码来源:ParserTests.cs

示例2: AssertEvent

        private void AssertEvent(ParsingEvent expected, ParsingEvent actual, int eventNumber)
        {
            actual.GetType().Should().Be(expected.GetType(), "Parse event {0} is not of the expected type.", eventNumber);

            foreach (var property in expected.GetType().GetProperties())
            {
                if (property.PropertyType == typeof(Mark) || !property.CanRead)
                {
                    continue;
                }

                var value = property.GetValue(actual, null);
                var expectedValue = property.GetValue(expected, null);
                if (expectedValue is IEnumerable && !(expectedValue is string))
                {
                    Dump.Write("\t{0} = {{", property.Name);
                    Dump.Write(string.Join(", ", (IEnumerable)value));
                    Dump.WriteLine("}");

                    if (expectedValue is ICollection && value is ICollection)
                    {
                        var expectedCount = ((ICollection)expectedValue).Count;
                        var valueCount = ((ICollection)value).Count;
                        valueCount.Should().Be(expectedCount, "Compared size of collections in property {0} in parse event {1}",
                            property.Name, eventNumber);
                    }

                    var values = ((IEnumerable)value).GetEnumerator();
                    var expectedValues = ((IEnumerable)expectedValue).GetEnumerator();
                    while (expectedValues.MoveNext())
                    {
                        values.MoveNext().Should().BeTrue("Property {0} in parse event {1} had too few elements", property.Name, eventNumber);
                        values.Current.Should().Be(expectedValues.Current,
                            "Compared element in property {0} in parse event {1}", property.Name, eventNumber);
                    }
                    values.MoveNext().Should().BeFalse("Property {0} in parse event {1} had too many elements", property.Name, eventNumber);
                }
                else
                {
                    Dump.WriteLine("\t{0} = {1}", property.Name, value);
                    value.Should().Be(expectedValue, "Compared property {0} in parse event {1}", property.Name, eventNumber);
                }
            }
        }
开发者ID:rogernorling,项目名称:YamlDotNet,代码行数:44,代码来源:ParserTests.cs


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