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


C# EventReader.Accept方法代码示例

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


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

示例1: ParseNode

		/// <summary>
		/// Parses the node represented by the next event in <paramref name="events" />.
		/// </summary>
		/// <param name="events">The events.</param>
		/// <param name="state">The state.</param>
		/// <returns>Returns the node that has been parsed.</returns>
		static internal YamlNode ParseNode(EventReader events, DocumentLoadingState state)
		{
			if (events.Accept<Scalar>())
			{
				return new YamlScalarNode(events, state);
			}

			if (events.Accept<SequenceStart>())
			{
				return new YamlSequenceNode(events, state);
			}

			if (events.Accept<MappingStart>())
			{
				return new YamlMappingNode(events, state);
			}

			if (events.Accept<AnchorAlias>())
			{
				AnchorAlias alias = events.Expect<AnchorAlias>();
				return state.GetNode(alias.Value, false, alias.Start, alias.End) ?? new YamlAliasNode(alias.Value);
			}

			throw new ArgumentException("The current event is of an unsupported type.", "events");
		}
开发者ID:czcz1024,项目名称:EventStore,代码行数:31,代码来源:YamlNode.cs

示例2: while

		bool INodeDeserializer.Deserialize(EventReader reader, Type expectedType, Func<EventReader, Type, object> nestedObjectDeserializer, out object value)
		{
			if (!typeof(IList).IsAssignableFrom(expectedType))
			{
				value = false;
				return false;
			}

			reader.Expect<SequenceStart>();

			var list = (IList)_objectFactory.Create(expectedType);
			while (!reader.Accept<SequenceEnd>())
			{
				var item = nestedObjectDeserializer(reader, typeof(object));
				var promise = item as IValuePromise;
				if (promise == null)
				{
					list.Add(item);
				}
				else
				{
					var index = list.Count;
					list.Add(null);
					promise.ValueAvailable += v => list[index] = v;
				}
			}
			value = list;

			reader.Expect<SequenceEnd>();

			return true;
		}
开发者ID:ChelseaLing,项目名称:AssetGraph,代码行数:32,代码来源:NonGenericListNodeDeserializer.cs

示例3: YamlDocument

		/// <summary>
		/// Initializes a new instance of the <see cref="YamlDocument"/> class.
		/// </summary>
		/// <param name="events">The events.</param>
		internal YamlDocument(EventReader events)
		{
			DocumentLoadingState state = new DocumentLoadingState();

			events.Expect<DocumentStart>();

			while (!events.Accept<DocumentEnd>())
			{
				Debug.Assert(RootNode == null);
				RootNode = YamlNode.ParseNode(events, state);

				if (RootNode is YamlAliasNode)
				{
					throw new YamlException();
				}
			}

			state.ResolveAliases();

#if DEBUG
			foreach (var node in AllNodes)
			{
				if (node is YamlAliasNode)
				{
					throw new InvalidOperationException("Error in alias resolution.");
				}
			}
#endif

			events.Expect<DocumentEnd>();
		}
开发者ID:Cyberbanan,项目名称:Projeny,代码行数:35,代码来源:YamlDocument.cs

示例4: Start

 // Use this for initialization
 void Start () {
     var input = new StringReader(Document);
     
     var deserializer = new Deserializer();
     
     var reader = new EventReader(new Parser(input));
     
     // Consume the stream start event "manually"
     reader.Expect<StreamStart>();
     
     var output = new StringBuilder();
     while(reader.Accept<DocumentStart>())
     {
         // Deserialize the document
         var doc = deserializer.Deserialize<List<string>>(reader);
     
         output.AppendLine("## Document");
         foreach(var item in doc)
         {
             output.AppendLine(item);
         }
     }    
     Debug.Log(output);
     
 }
开发者ID:Phrohdoh,项目名称:Projeny,代码行数:26,代码来源:Deserializing_multiple_documents.cs

示例5: GetData

    private static object GetData(EventReader r)
    {
        if(r.Accept<Scalar>())
        {
            return r.Expect<Scalar>().Value;
        }
        else if(r.Accept<SequenceStart>()) {
            var seq = new ArrayList();

            r.Expect<SequenceStart>();

            while(!r.Accept<SequenceEnd>())
            {
                seq.Add(GetData(r));
            }

            r.Expect<SequenceEnd>();

            // Arrays are IStructuralEquatable, ArrayLists are not.
            return seq.ToArray();
        }
        else if(r.Accept<MappingStart>())
        {
            // Since we use sequences as keys...
            var map = new OrderedDictionary(StructuralComparisons.StructuralEqualityComparer);

            r.Expect<MappingStart>();

            while(!r.Accept<MappingEnd>())
            {
                object key = GetData(r);
                object value = GetData(r);
                map.Add(key, value);
            }

            r.Expect<MappingEnd>();

            return map;
        }
        else {
            throw new YamlException();
        }
    }
开发者ID:miracle2k,项目名称:onkyo-eiscp-dotnet,代码行数:43,代码来源:Program.cs

示例6: ReadConfigYAML

        public static void ReadConfigYAML()
        {
            var input = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"/AME.yaml");

            var deserializer = new Deserializer();

            var reader = new EventReader(new Parser(input));

            // Deserialize the document
            reader.Expect<StreamStart>();
            reader.Accept<DocumentStart>();
            var settings = deserializer.Deserialize<AMESettings>(reader);

            reader.Accept<DocumentStart>();
            var behaviorManifests = deserializer.Deserialize<BehaviorManifests>(reader);

            foreach (var behavior in behaviorManifests.FRLGBehaviors)
            {
                if(behavior.Value[0] == '&')
                    behaviorManifests.FRLGBehaviors[behavior.Key] = InternalStrings.ResourceManager.GetString(behavior.Value);
                Console.WriteLine("[{0}] {1}", behavior.Key.ToString("X"), behavior.Value);
            }
        }
开发者ID:Diegoisawesome,项目名称:AwesomeMapEditor-old,代码行数:23,代码来源:ConfigReader.cs

示例7: while

		bool INodeDeserializer.Deserialize(EventReader reader, Type expectedType, Func<EventReader, Type, object> nestedObjectDeserializer, out object value)
		{
			var mapping = reader.Allow<MappingStart>();
			if (mapping == null)
			{
				value = null;
				return false;
			}
			
			value = _objectFactory.Create(expectedType);
			while (!reader.Accept<MappingEnd>())
			{
				var propertyName = reader.Expect<Scalar>();
				var property = _typeDescriptor.GetProperty(expectedType, null, propertyName.Value, _ignoreUnmatched);
				if (property == null)
				{
					reader.SkipThisAndNestedEvents();
					continue;
				}

				var propertyValue = nestedObjectDeserializer(reader, property.Type);
				var propertyValuePromise = propertyValue as IValuePromise;
				if (propertyValuePromise == null)
				{
					var convertedValue = TypeConverter.ChangeType(propertyValue, property.Type);
					property.Write(value, convertedValue);
				}
				else
				{
					var valueRef = value;
					propertyValuePromise.ValueAvailable += v =>
					{
						var convertedValue = TypeConverter.ChangeType(v, property.Type);
						property.Write(valueRef, convertedValue);
					};
				}
			}

			reader.Expect<MappingEnd>();
			return true;
		}
开发者ID:Cyberbanan,项目名称:Projeny,代码行数:41,代码来源:ObjectNodeDeserializer.cs

示例8: while

        bool INodeDeserializer.Deserialize(EventReader reader, Type expectedType, Func<EventReader, Type, object> nestedObjectDeserializer, out object value)
        {
            if(!typeof(IDictionary).IsAssignableFrom(expectedType))
            {
                value = false;
                return false;
            }

            reader.Expect<MappingStart>();

            var dictionary = (IDictionary)_objectFactory.Create(expectedType);
            while (!reader.Accept<MappingEnd>())
            {
                var key = nestedObjectDeserializer(reader, typeof(object));
                var keyPromise = key as IValuePromise;

                var keyValue = nestedObjectDeserializer(reader, typeof(object));
                var valuePromise = keyValue as IValuePromise;

                if (keyPromise == null)
                {
                    if (valuePromise == null)
                    {
                        // Happy path: both key and value are known
                        dictionary.Add(key, keyValue);
                    }
                    else
                    {
                        // Key is known, value is pending
                        valuePromise.ValueAvailable += v => dictionary.Add(key, v);
                    }
                }
                else
                {
                    if (valuePromise == null)
                    {
                        // Key is pending, value is known
                        keyPromise.ValueAvailable += v => dictionary.Add(v, keyValue);
                    }
                    else
                    {
                        // Both key and value are pending. We need to wait until both of them becom available.
                        var hasFirstPart = false;

                        keyPromise.ValueAvailable += v =>
                        {
                            if (hasFirstPart)
                            {
                                dictionary.Add(v, keyValue);
                            }
                            else
                            {
                                key = v;
                                hasFirstPart = true;
                            }
                        };

                        valuePromise.ValueAvailable += v =>
                        {
                            if (hasFirstPart)
                            {
                                dictionary.Add(key, v);
                            }
                            else
                            {
                                keyValue = v;
                                hasFirstPart = true;
                            }
                        };
                    }
                }
            }
            value = dictionary;

            reader.Expect<MappingEnd>();

            return true;
        }
开发者ID:pablinos,项目名称:YamlDotNet,代码行数:78,代码来源:NonGenericDictionaryNodeDeserializer.cs

示例9: DeserializeHelper

        private static void DeserializeHelper(Type tKey, Type tValue, EventReader reader, Type expectedType, Func<EventReader, Type, object> nestedObjectDeserializer, IDictionary result)
        {
            reader.Expect<MappingStart>();
            while (!reader.Accept<MappingEnd>())
            {
                var key = nestedObjectDeserializer(reader, tKey);
                var keyPromise = key as IValuePromise;

                var value = nestedObjectDeserializer(reader, tValue);
                var valuePromise = value as IValuePromise;

                if (keyPromise == null)
                {
                    if (valuePromise == null)
                    {
                        // Happy path: both key and value are known
                        result[key] = value;
                    }
                    else
                    {
                        // Key is known, value is pending
                        valuePromise.ValueAvailable += v => result[key] = v;
                    }
                }
                else
                {
                    if (valuePromise == null)
                    {
                        // Key is pending, value is known
                        keyPromise.ValueAvailable += v => result[v] = value;
                    }
                    else
                    {
                        // Both key and value are pending. We need to wait until both of them becom available.
                        var hasFirstPart = false;

                        keyPromise.ValueAvailable += v =>
                        {
                            if (hasFirstPart)
                            {
                                result[v] = value;
                            }
                            else
                            {
                                key = v;
                                hasFirstPart = true;
                            }
                        };

                        valuePromise.ValueAvailable += v =>
                        {
                            if (hasFirstPart)
                            {
                                result[key] = v;
                            }
                            else
                            {
                                value = v;
                                hasFirstPart = true;
                            }
                        };
                    }
                }
            }
            reader.Expect<MappingEnd>();
        }
开发者ID:nbarbettini,项目名称:YamlDotNet,代码行数:66,代码来源:DictionaryNodeDeserializer.cs

示例10: DeserializeValue

        private object DeserializeValue(EventReader reader, Type expectedType, object context)
        {
            if (reader.Accept<AnchorAlias>())
            {
                throw new NotImplementedException();
                //return context.Anchors[reader.Expect<AnchorAlias>().Value];
            }

            var nodeEvent = (NodeEvent)reader.Parser.Current;

            if (IsNull(nodeEvent))
            {
                reader.Expect<NodeEvent>();
                AddAnchoredObject(nodeEvent, null, context.Anchors);
                return null;
            }

            object result = DeserializeValueNotNull(reader, context, nodeEvent, expectedType);
            return ObjectConverter.Convert(result, expectedType);
        }
开发者ID:imgen,项目名称:YamlDotNet,代码行数:20,代码来源:Deserializer.cs

示例11: MigrateAssetIfNeeded

        public static bool MigrateAssetIfNeeded(AssetMigrationContext context, PackageLoadingAssetFile loadAsset, string dependencyName, PackageVersion untilVersion = null)
        {
            var assetFullPath = loadAsset.FilePath.FullPath;

            // Determine if asset was Yaml or not
            var assetFileExtension = Path.GetExtension(assetFullPath);
            if (assetFileExtension == null)
                return false;

            assetFileExtension = assetFileExtension.ToLowerInvariant();

            var serializer = AssetFileSerializer.FindSerializer(assetFileExtension);
            if (!(serializer is YamlAssetSerializer))
                return false;

            // We've got a Yaml asset, let's get expected and serialized versions
            var serializedVersion = PackageVersion.Zero;
            PackageVersion expectedVersion;
            Type assetType;

            // Read from Yaml file the asset version and its type (to get expected version)
            // Note: It tries to read as few as possible (SerializedVersion is expected to be right after Id, so it shouldn't try to read further than that)
            using (var assetStream = loadAsset.OpenStream())
            using (var streamReader = new StreamReader(assetStream))
            {
                var yamlEventReader = new EventReader(new Parser(streamReader));

                // Skip header
                yamlEventReader.Expect<StreamStart>();
                yamlEventReader.Expect<DocumentStart>();
                var mappingStart = yamlEventReader.Expect<MappingStart>();

                var tagTypeRegistry = AssetYamlSerializer.Default.GetSerializerSettings().TagTypeRegistry;
                bool typeAliased;
                assetType = tagTypeRegistry.TypeFromTag(mappingStart.Tag, out typeAliased);

                var expectedVersions = AssetRegistry.GetCurrentFormatVersions(assetType);
                expectedVersion = expectedVersions?.FirstOrDefault(x => x.Key == dependencyName).Value ?? PackageVersion.Zero;

                Scalar assetKey;
                while ((assetKey = yamlEventReader.Allow<Scalar>()) != null)
                {
                    // Only allow Id before SerializedVersion
                    if (assetKey.Value == nameof(Asset.Id))
                    {
                        yamlEventReader.Skip();
                    }
                    else if (assetKey.Value == nameof(Asset.SerializedVersion))
                    {
                        // Check for old format: only a scalar
                        var scalarVersion = yamlEventReader.Allow<Scalar>();
                        if (scalarVersion != null)
                        {
                            serializedVersion = PackageVersion.Parse("0.0." + Convert.ToInt32(scalarVersion.Value, CultureInfo.InvariantCulture));

                            // Let's update to new format
                            using (var yamlAsset = loadAsset.AsYamlAsset())
                            {
                                yamlAsset.DynamicRootNode.RemoveChild(nameof(Asset.SerializedVersion));
                                AssetUpgraderBase.SetSerializableVersion(yamlAsset.DynamicRootNode, dependencyName, serializedVersion);

                                var baseBranch = yamlAsset.DynamicRootNode["~Base"];
                                if (baseBranch != null)
                                {
                                    var baseAsset = baseBranch["Asset"];
                                    if (baseAsset != null)
                                    {
                                        baseAsset.RemoveChild(nameof(Asset.SerializedVersion));
                                        AssetUpgraderBase.SetSerializableVersion(baseAsset, dependencyName, serializedVersion);
                                    }
                                }
                            }
                        }
                        else
                        {
                            // New format: package => version mapping
                            yamlEventReader.Expect<MappingStart>();

                            while (!yamlEventReader.Accept<MappingEnd>())
                            {
                                var packageName = yamlEventReader.Expect<Scalar>().Value;
                                var packageVersion = PackageVersion.Parse(yamlEventReader.Expect<Scalar>().Value);

                                // For now, we handle only one dependency at a time
                                if (packageName == dependencyName)
                                {
                                    serializedVersion = packageVersion;
                                }
                            }

                            yamlEventReader.Expect<MappingEnd>();
                        }
                        break;
                    }
                    else
                    {
                        // If anything else than Id or SerializedVersion, let's stop
                        break;
                    }
                }
//.........这里部分代码省略.........
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:101,代码来源:AssetMigration.cs

示例12: DeserializeHelper

        internal static void DeserializeHelper(Type tItem, EventReader reader, Type expectedType, Func<EventReader, Type, object> nestedObjectDeserializer, IList result, bool canUpdate)
        {
            reader.Expect<SequenceStart>();
            while (!reader.Accept<SequenceEnd>())
            {
                var current = reader.Parser.Current;

                var value = nestedObjectDeserializer(reader, tItem);
                var promise = value as IValuePromise;
                if (promise == null)
                {
                    result.Add(TypeConverter.ChangeType(value, tItem));
                }
                else if (canUpdate)
                {
                    var index = result.Add(tItem.IsValueType() ? Activator.CreateInstance(tItem) : null);
                    promise.ValueAvailable += v => result[index] = TypeConverter.ChangeType(v, tItem);
                }
                else
                {
                    throw new ForwardAnchorNotSupportedException(
                        current.Start,
                        current.End,
                        "Forward alias references are not allowed because this type does not implement IList<>"
                    );
                }
            }
            reader.Expect<SequenceEnd>();
        }
开发者ID:t4world,项目名称:AssetGraph,代码行数:29,代码来源:CollectionNodeDeserializer.cs


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