/// <summary> /// Fetches a converter that can serialize/deserialize the given type. /// </summary> private fsBaseConverter GetConverter(Type type) { fsBaseConverter converter; if (_cachedConverters.TryGetValue(type, out converter)) { return(converter); } // Check to see if the user has defined a custom converter for the type. If they // have, then we don't need to scan through all of the converters to check which // one can process the type; instead, we directly use the specified converter. { var attr = fsPortableReflection.GetAttribute <fsObjectAttribute>(type); if (attr != null && attr.Converter != null) { converter = (fsBaseConverter)Activator.CreateInstance(attr.Converter); converter.Serializer = this; return(_cachedConverters[type] = converter); } } // Check for a [fsForward] attribute. { var attr = fsPortableReflection.GetAttribute <fsForwardAttribute>(type); if (attr != null) { converter = new fsForwardConverter(attr); converter.Serializer = this; return(_cachedConverters[type] = converter); } } // There is no specific converter specified; try all of the general ones to see // which ones matches. if (_cachedConverters.TryGetValue(type, out converter) == false) { if (_availableDirectConverters.ContainsKey(type)) { converter = _availableDirectConverters[type]; return(_cachedConverters[type] = converter); } else { for (int i = 0; i < _availableConverters.Count; ++i) { if (_availableConverters[i].CanProcess(type)) { converter = _availableConverters[i]; return(_cachedConverters[type] = converter); } } } } throw new InvalidOperationException("Internal error -- could not find a converter for " + type); }
/// <summary> /// Fetches a converter that can serialize/deserialize the given type. /// 指定された型を直列化/逆直列化できるコンバータを取得します。 /// </summary> private fsBaseConverter GetConverter(Type type, Type overrideConverterType) { // Use an override converter type instead if that's what the user has requested. // ユーザーが要求したものであれば、代わりにオーバーライドコンバータタイプを使用してください。 if (overrideConverterType != null) { fsBaseConverter overrideConverter; if (_cachedConverterTypeInstances.TryGetValue(overrideConverterType, out overrideConverter) == false) { overrideConverter = (fsBaseConverter)Activator.CreateInstance(overrideConverterType); overrideConverter.Serializer = this; _cachedConverterTypeInstances[overrideConverterType] = overrideConverter; } return(overrideConverter); } // Try to lookup an existing converter. // 既存のコンバータを検索してみてください。 fsBaseConverter converter; if (_cachedConverters.TryGetValue(type, out converter)) { return(converter); } // Check to see if the user has defined a custom converter for the type. If they // have, then we don't need to scan through all of the converters to check which // one can process the type; instead, we directly use the specified converter. // ユーザーがその種類のカスタムコンバータを定義しているかどうかを確認します。 // もしそれらがあれば、どのタイプを処理できるかを調べるためにすべてのコンバータをスキャンする必要はありません。 // 代わりに、指定されたコンバータを直接使用します。 { var attr = fsPortableReflection.GetAttribute <fsObjectAttribute>(type); if (attr != null && attr.Converter != null) { converter = (fsBaseConverter)Activator.CreateInstance(attr.Converter); converter.Serializer = this; return(_cachedConverters[type] = converter); } } // Check for a [fsForward] attribute. //[fsForward]属性を確認してください。 { var attr = fsPortableReflection.GetAttribute <fsForwardAttribute>(type); if (attr != null) { converter = new fsForwardConverter(attr); converter.Serializer = this; return(_cachedConverters[type] = converter); } } // There is no specific converter specified; try all of the general ones to see // which ones matches. // 特定のコンバータは指定されていません。 一般的なものすべてを試して、一致するものを見てください。 if (_cachedConverters.TryGetValue(type, out converter) == false) { if (_availableDirectConverters.ContainsKey(type)) { converter = _availableDirectConverters[type]; return(_cachedConverters[type] = converter); } else { for (int i = 0; i < _availableConverters.Count; ++i) { if (_availableConverters[i].CanProcess(type)) { converter = _availableConverters[i]; return(_cachedConverters[type] = converter); } } } } throw new InvalidOperationException("Internal error -- could not find a converter for " + type); }
/// <summary> /// Fetches a converter that can serialize/deserialize the given type. /// </summary> private fsBaseConverter GetConverter(Type type, Type overrideConverterType) { // Use an override converter type instead if that's what the user has // requested. //if (typeof(SavedScriptable).IsAssignableFrom(type)) // Debug.Log(123); if (overrideConverterType != null) { fsBaseConverter overrideConverter; if (_cachedConverterTypeInstances.TryGetValue(overrideConverterType, out overrideConverter) == false) { overrideConverter = (fsBaseConverter)Activator.CreateInstance(overrideConverterType); overrideConverter.Serializer = this; _cachedConverterTypeInstances[overrideConverterType] = overrideConverter; } return(overrideConverter); } // Try to lookup an existing converter. fsBaseConverter converter; if (_cachedConverters.TryGetValue(type, out converter)) { return(converter); } // Check to see if the user has defined a custom converter for the // type. If they have, then we don't need to scan through all of the // converters to check which one can process the type; instead, we // directly use the specified converter. { var attr = fsPortableReflection.GetAttribute <fsObjectAttribute>(type); if (attr != null && attr.Converter != null) { converter = (fsBaseConverter)Activator.CreateInstance(attr.Converter); converter.Serializer = this; return(_cachedConverters[type] = converter); } } // Check for a [fsForward] attribute. { var attr = fsPortableReflection.GetAttribute <fsForwardAttribute>(type); if (attr != null) { converter = new fsForwardConverter(attr); converter.Serializer = this; return(_cachedConverters[type] = converter); } } // There is no specific converter specified; try all of the general // ones to see which ones matches. if (_cachedConverters.TryGetValue(type, out converter) == false) { if (_availableDirectConverters.ContainsKey(type)) { converter = _availableDirectConverters[type]; return(_cachedConverters[type] = converter); } else { for (int i = 0; i < _availableConverters.Count; ++i) { if (_availableConverters[i].CanProcess(type)) { converter = _availableConverters[i]; return(_cachedConverters[type] = converter); } } } } throw new InvalidOperationException("Internal error -- could not find a converter for " + type); }
/// Fetches a converter that can serialize/deserialize the given type. private fsBaseConverter GetConverter(Type type, Type overrideConverterType) { // Use an override converter type instead if that's what the user has requested. if (overrideConverterType != null) { fsBaseConverter overrideConverter; if (_cachedOverrideConverterInstances.TryGetValue(overrideConverterType, out overrideConverter) == false) { overrideConverter = (fsBaseConverter)Activator.CreateInstance(overrideConverterType); overrideConverter.Serializer = this; _cachedOverrideConverterInstances[overrideConverterType] = overrideConverter; } return(overrideConverter); } // Try to lookup an existing converter. fsBaseConverter converter; if (_cachedConverters.TryGetValue(type, out converter)) { return(converter); } // Check to see if the user has defined a custom converter for the type. If they // have, then we don't need to scan through all of the converters to check which // one can process the type; instead, we directly use the specified converter. { var attr = type.RTGetAttribute <fsObjectAttribute>(true); if (attr != null && attr.Converter != null) { converter = (fsBaseConverter)Activator.CreateInstance(attr.Converter); converter.Serializer = this; return(_cachedConverters[type] = converter); } } // Check for a [fsForward] attribute. { var attr = type.RTGetAttribute <fsForwardAttribute>(true); if (attr != null) { converter = new fsForwardConverter(attr); converter.Serializer = this; return(_cachedConverters[type] = converter); } } // No converter specified. Find match from general ones. { fsDirectConverter directConverter; if (_availableDirectConverters.TryGetValue(type, out directConverter)) { return(_cachedConverters[type] = directConverter); } for (var i = 0; i < _availableConverters.Count; i++) { if (_availableConverters[i].CanProcess(type)) { return(_cachedConverters[type] = _availableConverters[i]); } } } // No converter available return(_cachedConverters[type] = null); }
/// <summary> /// Fetches a converter that can serialize/deserialize the given type. /// </summary> private fsBaseConverter GetConverter(Type type, Type overrideConverterType) { // 如果overrideConverterType不为空,就直接用overrideConverterType, // 并加入overrideConverterType的实例到_cachedConverterTypeInstances中 // Use an override converter type instead if that's what the user has requested. if (overrideConverterType != null) { fsBaseConverter overrideConverter; if (_cachedConverterTypeInstances.TryGetValue(overrideConverterType, out overrideConverter) == false) { overrideConverter = (fsBaseConverter)Activator.CreateInstance(overrideConverterType); overrideConverter.Serializer = this; _cachedConverterTypeInstances[overrideConverterType] = overrideConverter; } return(overrideConverter); } // Try to lookup an existing converter. fsBaseConverter converter; if (_cachedConverters.TryGetValue(type, out converter)) { return(converter); } // 检查有无[fsObject] attribute,有的话,就直接用指定的converter // Check to see if the user has defined a custom converter for the type. If they // have, then we don't need to scan through all of the converters to check which // one can process the type; instead, we directly use the specified converter. { var attr = fsPortableReflection.GetAttribute <fsObjectAttribute>(type); if (attr != null && attr.Converter != null) { converter = (fsBaseConverter)Activator.CreateInstance(attr.Converter); converter.Serializer = this; return(_cachedConverters[type] = converter); } } // 检查有无[fsForward] attribute,有的话,就直接用指定的converter // Check for a [fsForward] attribute. { var attr = fsPortableReflection.GetAttribute <fsForwardAttribute>(type); if (attr != null) { converter = new fsForwardConverter(attr); converter.Serializer = this; return(_cachedConverters[type] = converter); } } // 如果用户没有指定converter,那么就看缓存_cachedConverters,如果没有话就,就再看 // _availableConverters和_availableConverters // There is no specific converter specified; try all of the general ones to see // which ones matches. if (_cachedConverters.TryGetValue(type, out converter) == false) { if (_availableDirectConverters.ContainsKey(type)) { converter = _availableDirectConverters[type]; return(_cachedConverters[type] = converter); } else { for (int i = 0; i < _availableConverters.Count; ++i) { if (_availableConverters[i].CanProcess(type)) { converter = _availableConverters[i]; return(_cachedConverters[type] = converter); } } } } throw new InvalidOperationException("Internal error -- could not find a converter for " + type); }