public IMessagePackSingleObjectSerializer Get( SerializationContext context, Type targetType, object providerParameter ) { #if UNITY MethodInfo method; if ( !this._cache.TryGetValue( targetType.TypeHandle, out method ) || method == null ) { method = GetSerializer1Method.MakeGenericMethod( targetType ); this._cache[ targetType.TypeHandle ] = method; } return ( IMessagePackSingleObjectSerializer )method.InvokePreservingExceptionType( context, providerParameter ); #else Func<SerializationContext, object, IMessagePackSingleObjectSerializer> func; #if SILVERLIGHT || NETFX_35 || UNITY lock ( this._cache ) { #endif // SILVERLIGHT || NETFX_35 || UNITY if ( !this._cache.TryGetValue( targetType.TypeHandle, out func ) || func == null ) { #if !NETFX_CORE func = Delegate.CreateDelegate( typeof( Func<SerializationContext, object, IMessagePackSingleObjectSerializer> ), typeof( SerializerGetter<> ).MakeGenericType( targetType ).GetMethod( "Get" ) ) as Func<SerializationContext, object, IMessagePackSingleObjectSerializer>; #else var contextParameter = Expression.Parameter( typeof( SerializationContext ), "context" ); var providerParameterParameter = Expression.Parameter( typeof( Object ), "providerParameter" ); func = Expression.Lambda<Func<SerializationContext, object, IMessagePackSingleObjectSerializer>>( Expression.Call( null, typeof( SerializerGetter<> ).MakeGenericType( targetType ).GetRuntimeMethods().Single( m => m.Name == "Get" ), contextParameter, providerParameterParameter ), contextParameter, providerParameterParameter ).Compile(); #endif // !NETFX_CORE #if DEBUG && !UNITY Contract.Assert( func != null, "func != null" ); #endif // if DEBUG && !UNITY this._cache[ targetType.TypeHandle ] = func; } #if SILVERLIGHT || NETFX_35 || UNITY } #endif // SILVERLIGHT || NETFX_35 || UNITY return func( context, providerParameter ); #endif // UNITY }
public MessagePackSerializer Get( SerializationContext context, Type targetType, object providerParameter ) { #if UNITY MethodInfo method; if ( !this._cache.TryGetValue( targetType.TypeHandle, out method ) || method == null ) { method = GetSerializer1Method.MakeGenericMethod( targetType ); this._cache[ targetType.TypeHandle ] = method; } return ( MessagePackSerializer )method.InvokePreservingExceptionType( context, providerParameter ); #else Func<SerializationContext, object, MessagePackSerializer> func; #if !FEATURE_CONCURRENT lock ( this._cache ) { #endif // !FEATURE_CONCURRENT if ( !this._cache.TryGetValue( targetType.TypeHandle, out func ) || func == null ) { #if !NETSTANDARD1_1 && !NETSTANDARD1_3 func = Delegate.CreateDelegate( typeof( Func<SerializationContext, object, MessagePackSerializer> ), typeof( SerializerGetter<> ).MakeGenericType( targetType ).GetMethod( "Get" ) ) as Func<SerializationContext, object, MessagePackSerializer>; #else func = typeof( SerializerGetter<> ).MakeGenericType( targetType ).GetMethod( "Get" ).CreateDelegate( typeof( Func<SerializationContext, object, MessagePackSerializer> ) ) as Func<SerializationContext, object, MessagePackSerializer>; #endif // !NETSTANDARD1_1 && !NETSTANDARD1_3 Contract.Assert( func != null, "func != null" ); this._cache[ targetType.TypeHandle ] = func; } #if !FEATURE_CONCURRENT } #endif // !FEATURE_CONCURRENT return func( context, providerParameter ); #endif // UNITY }