public static ISerializer GetSerializer(SerializerType type) { var serializer = default(ISerializer); if (m_Pool.TryGetValue(type, out serializer)) { return(serializer); } if (type == SerializerType.None) { throw new ArgumentOutOfRangeException("type"); } if (!Enum.IsDefined(typeof(SerializerType), type)) { throw new ArgumentOutOfRangeException("type"); } var serializerType = default(Type); if (m_PreferTypePool.ContainsKey(type)) { serializerType = m_PreferTypePool[type]; } else { var attribute = type.GetCustomAttribute <RelativedTypeAttribute>(); Contract.Assert(attribute != null, String.Format("{0} should be append with RelativedTypeAttribute", Enum.GetName(typeof(SerializerType), type))); serializerType = attribute.Type; } serializer = Activator.CreateInstance(serializerType) as ISerializer; m_Pool[type] = serializer; return(serializer); }