Exemple #1
0
        private static bool SetupDelegate()
        {
            Type appContextType = typeof(object).Assembly.GetType("System.AppContext");

            if (appContextType == null)
            {
                return(false);
            }

            MethodInfo method = appContextType.GetMethod(
                "TryGetSwitch",                            // the method name
                BindingFlags.Static | BindingFlags.Public, // binding flags
                null,                                      // use the default binder
                new Type[] { typeof(string), typeof(bool).MakeByRefType() },
                null);                                     // parameterModifiers - this is ignored by the default binder

            if (method == null)
            {
                return(false);
            }

            // Create delegate if we found the method.
            TryGetSwitchFromCentralAppContext = (TryGetSwitchDelegate)Delegate.CreateDelegate(typeof(TryGetSwitchDelegate), method);

            return(true);
        }
Exemple #2
0
        private static bool SetupDelegate()
        {
            Type appContextType = typeof(object).Assembly.GetType("System.AppContext");
            if (appContextType == null)
                return false;

            MethodInfo method = appContextType.GetMethod(
                                            "TryGetSwitch",  // the method name
                                            BindingFlags.Static | BindingFlags.Public,  // binding flags
                                            null, // use the default binder
                                            new Type[] { typeof(string), typeof(bool).MakeByRefType() },
                                            null); // parameterModifiers - this is ignored by the default binder 
            if (method == null)
                return false;

            // Create delegate if we found the method.
            TryGetSwitchFromCentralAppContext = (TryGetSwitchDelegate)Delegate.CreateDelegate(typeof(TryGetSwitchDelegate), method);

            return true;
        }