private static bool IsSystemXamlNonPublic(ref ThreeValuedBool methodIsSystemXamlNonPublic, MethodInfo method) { if (methodIsSystemXamlNonPublic == ThreeValuedBool.NotSet) { bool flag = SafeReflectionInvoker.IsSystemXamlNonPublic(method); methodIsSystemXamlNonPublic = flag ? ThreeValuedBool.True : ThreeValuedBool.False; } return (methodIsSystemXamlNonPublic == ThreeValuedBool.True); }
private static bool IsSystemXamlNonPublic(ref ThreeValuedBool methodIsSystemXamlNonPublic, MethodInfo method) { if (methodIsSystemXamlNonPublic == ThreeValuedBool.NotSet) { bool flag = SafeReflectionInvoker.IsSystemXamlNonPublic(method); methodIsSystemXamlNonPublic = flag ? ThreeValuedBool.True : ThreeValuedBool.False; } return(methodIsSystemXamlNonPublic == ThreeValuedBool.True); }
// returns true if a delegate is available, false if not private static bool EnsureConstructorDelegate(XamlTypeInvoker type) { if (type._constructorDelegate != null) { return(true); } if (!type.IsPublic) { return(false); } if (s_securityFailureWithCtorDelegate == ThreeValuedBool.NotSet) { s_securityFailureWithCtorDelegate = #if PARTIALTRUST !AppDomain.CurrentDomain.PermissionSet.IsUnrestricted() ? ThreeValuedBool.True : ThreeValuedBool.False; #else ThreeValuedBool.False; #endif } if (s_securityFailureWithCtorDelegate == ThreeValuedBool.True) { return(false); } try { Type underlyingType = type._xamlType.UnderlyingType.UnderlyingSystemType; // Look up public ctors only, for equivalence with Activator.CreateInstance ConstructorInfo tConstInfo = underlyingType.GetConstructor(Type.EmptyTypes); if (tConstInfo == null) { // Throwing MissingMethodException for equivalence with Activator.CreateInstance throw new MissingMethodException(SR.Get(SRID.NoDefaultConstructor, underlyingType.FullName)); } if ((tConstInfo.IsSecurityCritical && !tConstInfo.IsSecuritySafeCritical) || (tConstInfo.Attributes & MethodAttributes.HasSecurity) == MethodAttributes.HasSecurity || (underlyingType.Attributes & TypeAttributes.HasSecurity) == TypeAttributes.HasSecurity) { // We don't want to bypass security checks for a critical or demanding ctor, // so just treat it as if it were non-public type._isPublic = ThreeValuedBool.False; return(false); } IntPtr constPtr = tConstInfo.MethodHandle.GetFunctionPointer(); // This requires Reflection Permission Action <object> ctorDelegate = ctorDelegate = (Action <object>)s_actionCtor.Invoke(new object[] { null, constPtr }); type._constructorDelegate = ctorDelegate; return(true); } catch (SecurityException) { s_securityFailureWithCtorDelegate = ThreeValuedBool.True; return(false); } }
private static bool EnsureConstructorDelegate(XamlTypeInvoker type) { if (type._constructorDelegate != null) { return(true); } if (!type.IsPublic) { return(false); } if (s_securityFailureWithCtorDelegate == ThreeValuedBool.NotSet) { s_securityFailureWithCtorDelegate = !AppDomain.CurrentDomain.PermissionSet.IsUnrestricted() ? ThreeValuedBool.True : ThreeValuedBool.False; } if (s_securityFailureWithCtorDelegate == ThreeValuedBool.True) { return(false); } try { Type underlyingSystemType = type._xamlType.UnderlyingType.UnderlyingSystemType; ConstructorInfo constructor = underlyingSystemType.GetConstructor(Type.EmptyTypes); if (constructor == null) { throw new MissingMethodException(System.Xaml.SR.Get("NoDefaultConstructor", new object[] { underlyingSystemType.FullName })); } if ((constructor.IsSecurityCritical && !constructor.IsSecuritySafeCritical) || (((constructor.Attributes & MethodAttributes.HasSecurity) == MethodAttributes.HasSecurity) || ((underlyingSystemType.Attributes & TypeAttributes.HasSecurity) == TypeAttributes.HasSecurity))) { type._isPublic = ThreeValuedBool.False; return(false); } IntPtr functionPointer = constructor.MethodHandle.GetFunctionPointer(); object[] parameters = new object[2]; parameters[1] = functionPointer; type._constructorDelegate = (Action <object>)s_actionCtor.Invoke(parameters); return(true); } catch (SecurityException) { s_securityFailureWithCtorDelegate = ThreeValuedBool.True; return(false); } }
private static bool EnsureConstructorDelegate(XamlTypeInvoker type) { if (type._constructorDelegate != null) { return true; } if (!type.IsPublic) { return false; } if (s_securityFailureWithCtorDelegate == ThreeValuedBool.NotSet) { s_securityFailureWithCtorDelegate = !AppDomain.CurrentDomain.PermissionSet.IsUnrestricted() ? ThreeValuedBool.True : ThreeValuedBool.False; } if (s_securityFailureWithCtorDelegate == ThreeValuedBool.True) { return false; } try { Type underlyingSystemType = type._xamlType.UnderlyingType.UnderlyingSystemType; ConstructorInfo constructor = underlyingSystemType.GetConstructor(Type.EmptyTypes); if (constructor == null) { throw new MissingMethodException(System.Xaml.SR.Get("NoDefaultConstructor", new object[] { underlyingSystemType.FullName })); } if ((constructor.IsSecurityCritical && !constructor.IsSecuritySafeCritical) || (((constructor.Attributes & MethodAttributes.HasSecurity) == MethodAttributes.HasSecurity) || ((underlyingSystemType.Attributes & TypeAttributes.HasSecurity) == TypeAttributes.HasSecurity))) { type._isPublic = ThreeValuedBool.False; return false; } IntPtr functionPointer = constructor.MethodHandle.GetFunctionPointer(); object[] parameters = new object[2]; parameters[1] = functionPointer; type._constructorDelegate = (Action<object>) s_actionCtor.Invoke(parameters); return true; } catch (SecurityException) { s_securityFailureWithCtorDelegate = ThreeValuedBool.True; return false; } }