This repository was archived by the owner on Dec 24, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,22 @@ public static TypeInfo GetTypeInfo(this Type type)
8989 }
9090#endif
9191
92+ #if NETSTANDARD
93+ private static readonly Func < Type , object > GetUninitializedObjectDelegate ;
94+
95+ static ReflectionExtensions ( )
96+ {
97+ var formatterServices = typeof ( string ) . GetTypeInfo ( ) . Assembly
98+ . GetType ( "System.Runtime.Serialization.FormatterServices" ) ;
99+ if ( formatterServices != null )
100+ {
101+ var method = formatterServices . GetMethod ( "GetUninitializedObject" ) ;
102+ if ( method != null )
103+ GetUninitializedObjectDelegate = ( Func < Type , object > ) method . CreateDelegate ( typeof ( Func < Type , object > ) ) ;
104+ }
105+ }
106+ #endif
107+
92108 public static TypeCode GetTypeCode ( this Type type )
93109 {
94110#if ( NETFX_CORE || PCL || NETSTANDARD )
@@ -522,7 +538,12 @@ public static EmptyCtorDelegate GetConstructorMethodToCache(Type type)
522538#endif
523539 }
524540
525- #if ( SL5 && ! WP ) || XBOX || NETSTANDARD
541+ #if ( SL5 && ! WP ) || XBOX
542+ return ( ) => Activator . CreateInstance ( type ) ;
543+ #elif NETSTANDARD
544+ if ( GetUninitializedObjectDelegate != null )
545+ return ( ) => GetUninitializedObjectDelegate ( type ) ;
546+
526547 return ( ) => Activator . CreateInstance ( type ) ;
527548#elif WP || PCL
528549 return System . Linq . Expressions . Expression . Lambda < EmptyCtorDelegate > (
You can’t perform that action at this time.
0 commit comments