@@ -113,6 +113,23 @@ internal static IntPtr ToPython<T>(T value)
113
113
return ToPython ( value , typeof ( T ) ) ;
114
114
}
115
115
116
+ private static readonly Func < object , bool > IsTransparentProxy = GetIsTransparentProxy ( ) ;
117
+
118
+ private static bool Never ( object _ ) => false ;
119
+
120
+ private static Func < object , bool > GetIsTransparentProxy ( )
121
+ {
122
+ var remoting = typeof ( int ) . Assembly . GetType ( "System.Runtime.Remoting.RemotingServices" ) ;
123
+ if ( remoting is null ) return Never ;
124
+
125
+ var isProxy = remoting . GetMethod ( "IsTransparentProxy" , new [ ] { typeof ( object ) } ) ;
126
+ if ( isProxy is null ) return Never ;
127
+
128
+ return ( Func < object , bool > ) Delegate . CreateDelegate (
129
+ typeof ( Func < object , bool > ) , isProxy ,
130
+ throwOnBindFailure : true ) ;
131
+ }
132
+
116
133
internal static IntPtr ToPython ( object value , Type type )
117
134
{
118
135
if ( value is PyObject )
@@ -162,15 +179,8 @@ internal static IntPtr ToPython(object value, Type type)
162
179
var pyderived = value as IPythonDerivedType ;
163
180
if ( null != pyderived )
164
181
{
165
- #if NETSTANDARD
166
- return ClassDerivedObject . ToPython ( pyderived ) ;
167
- #else
168
- // if object is remote don't do this
169
- if ( ! System . Runtime . Remoting . RemotingServices . IsTransparentProxy ( pyderived ) )
170
- {
182
+ if ( ! IsTransparentProxy ( pyderived ) )
171
183
return ClassDerivedObject . ToPython ( pyderived ) ;
172
- }
173
- #endif
174
184
}
175
185
176
186
// hmm - from Python, we almost never care what the declared
0 commit comments