/// <summary> /// Fetches all of the processors for the given type. /// </summary> private List <fsObjectProcessor> GetProcessors(Type type) { List <fsObjectProcessor> processors; // Check to see if the user has defined a custom processor for the type. If they // have, then we don't need to scan through all of the processor to check which // one can process the type; instead, we directly use the specified processor. fsObjectAttribute attr = fsPortableReflection.GetAttribute <fsObjectAttribute>(type); if (attr != null && attr.Processor != null) { fsObjectProcessor processor = (fsObjectProcessor)Activator.CreateInstance(attr.Processor); processors = new List <fsObjectProcessor>(); processors.Add(processor); _cachedProcessors[type] = processors; } else if (_cachedProcessors.TryGetValue(type, out processors) == false) { processors = new List <fsObjectProcessor>(); for (int i = 0; i < _processors.Count; ++i) { fsObjectProcessor processor = _processors[i]; if (processor.CanProcess(type)) { processors.Add(processor); } } _cachedProcessors[type] = processors; } return(processors); }
/// <summary> /// Add a new processor to the serializer. Multiple processors can run at the same time in the /// same order they were added in. /// </summary> /// <param name="processor">The processor to add.</param> public void AddProcessor(fsObjectProcessor processor) { _processors.Add(processor); // We need to reset our cached processor set, as it could be invalid with the new // processor. Ideally, _cachedProcessors should be empty (as the user should fully setup // the serializer before actually using it), but there is no guarantee. _cachedProcessors = new Dictionary<Type, List<fsObjectProcessor>>(); }
/// <summary> /// Add a new processor to the serializer. Multiple processors can run at the same time in the /// same order they were added in. /// シリアライザに新しいプロセッサを追加します。 複数のプロセッサーは、 /// 追加されたのと同じ順序で同時に実行できます。 /// </summary> /// <param name="processor">The processor to add.</param> public void AddProcessor(fsObjectProcessor processor) { _processors.Add(processor); // We need to reset our cached processor set, as it could be invalid with the new // processor. Ideally, _cachedProcessors should be empty (as the user should fully setup // the serializer before actually using it), but there is no guarantee. // キャッシュされたプロセッサセットは、新しいプロセッサでは無効になる可能性があるため、 // リセットする必要があります。 理想的には_cachedProcessorsは空でなければなりません // (実際に使用する前にシリアライザを完全に設定する必要があります)が、保証はありません。 _cachedProcessors = new Dictionary <Type, List <fsObjectProcessor> >(); }
/// <summary> /// Register the given processor for usage in the serializer. /// </summary> public static void AddProcessor(fsObjectProcessor processor) { _serializer.AddProcessor(processor); }