private static Dictionary <Type, MessagePackSerializerProvider> InitializeSerializers(IList <Type> knownTypes) { var result = new Dictionary <Type, MessagePackSerializerProvider>(knownTypes.Count); foreach (var knownType in knownTypes) { if (knownType.GetIsInterface() || knownType.GetIsAbstract()) { // skip continue; } var serializerTypeName = "MsgPack.Serialization.GeneratedSerializers." + IdentifierUtility.EscapeTypeName(knownType) + "Serializer"; var serializerType = typeof(PreGeneratedSerializerActivator).GetAssembly().GetType(serializerTypeName); Type type = knownType; var serializer = new LazyMessagePackSerializerProvider( knownType, serializerType != null ? new Func <SerializationContext, PolymorphismSchema, MessagePackSerializer>(SerializerActivator.Create(knownType, serializerType, knownType).Activate) : ((c, s) => { throw new Exception( String.Format( CultureInfo.CurrentCulture, "Pre-generated serializer '{0}' for type '{1}' does not exist in this project.", serializerTypeName, type ) ); } ) ); try { result.Add(knownType, serializer); } catch (ArgumentException) { // ReSharper disable once NotResolvedInText throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "Key '{0}' is already added.", knownType), "key"); } } return(result); }
private static Dictionary<Type, MessagePackSerializerProvider> InitializeSerializers( IList<Type> knownTypes ) { var result = new Dictionary<Type, MessagePackSerializerProvider>( knownTypes.Count ); foreach ( var knownType in knownTypes ) { if ( knownType.GetIsInterface() || knownType.GetIsAbstract() ) { // skip continue; } var serializerTypeName = "MsgPack.Serialization.GeneratedSerializers." + IdentifierUtility.EscapeTypeName( knownType ) + "Serializer"; var serializerType = typeof( PreGeneratedSerializerActivator ).GetAssembly().GetType( serializerTypeName ); Type type = knownType; var serializer = new LazyMessagePackSerializerProvider( knownType, serializerType != null ? new Func<SerializationContext, PolymorphismSchema, MessagePackSerializer>( SerializerActivator.Create( knownType, serializerType, knownType ).Activate ) : ( ( c, s ) => { throw new Exception( String.Format( CultureInfo.CurrentCulture, "Pre-generated serializer '{0}' for type '{1}' does not exist in this project.", serializerTypeName, type ) ); } ) ); try { result.Add( knownType, serializer ); } catch ( ArgumentException ) { // ReSharper disable once NotResolvedInText throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, "Key '{0}' is already added.", knownType ), "key" ); } } return result; }