Example #1
0
#pragma warning disable 56507 // check for null or empty strings

        private SrgsRule[] RunOnInit(bool stg)
        {
            SrgsRule[] extraRules    = null;
            bool       onInitInvoked = false;

            // Get the name of the onInit method to run
            string methodName = ScriptRef.OnInitMethod(_scripts, _ruleName);

            if (methodName != null)
            {
                if (_proxy != null)
                {
                    Exception appDomainException;
                    extraRules    = _proxy.OnInit(methodName, _parameters, _onInitParameters, out appDomainException);
                    onInitInvoked = true;
                    if (appDomainException != null)
                    {
                        ExceptionDispatchInfo.Throw(appDomainException);
                    }
                }
                else
                {
                    // call OnInit if any - should be based on Rule
                    Type[] types = new Type[_parameters.Length];

                    for (int i = 0; i < _parameters.Length; i++)
                    {
                        types[i] = _parameters[i].GetType();
                    }
                    MethodInfo onInit = GetType().GetMethod(methodName, types);

                    // If somehow we failed to find a constructor, let the system handle it
                    if (onInit != null)
                    {
                        System.Diagnostics.Debug.Assert(_parameters != null);
                        extraRules    = (SrgsRule[])onInit.Invoke(this, _parameters);
                        onInitInvoked = true;
                    }
                    else
                    {
                        throw new ArgumentException(SR.Get(SRID.RuleScriptInvalidParameters, _ruleName, _ruleName));
                    }
                }
            }

            // Cannot have onInit parameters if onInit has not been invoked.
            if (!stg && !onInitInvoked && _parameters != null)
            {
                throw new ArgumentException(SR.Get(SRID.RuleScriptInvalidParameters, _ruleName, _ruleName));
            }
            return(extraRules);
        }
Example #2
0
        private SrgsRule[] RunOnInit(bool stg)
        {
            SrgsRule[] result = null;
            bool       flag   = false;
            string     text   = ScriptRef.OnInitMethod(_scripts, _ruleName);

            if (text != null)
            {
                if (_proxy != null)
                {
                    Exception exceptionThrown;
                    result = _proxy.OnInit(text, _parameters, _onInitParameters, out exceptionThrown);
                    flag   = true;
                    if (exceptionThrown != null)
                    {
                        throw exceptionThrown;
                    }
                }
                else
                {
                    Type[] array = new Type[_parameters.Length];
                    for (int i = 0; i < _parameters.Length; i++)
                    {
                        array[i] = _parameters[i].GetType();
                    }
                    MethodInfo method = GetType().GetMethod(text, array);
                    if (!(method != null))
                    {
                        throw new ArgumentException(SR.Get(SRID.RuleScriptInvalidParameters, _ruleName, _ruleName));
                    }
                    result = (SrgsRule[])method.Invoke(this, _parameters);
                    flag   = true;
                }
            }
            if (!stg && !flag && _parameters != null)
            {
                throw new ArgumentException(SR.Get(SRID.RuleScriptInvalidParameters, _ruleName, _ruleName));
            }
            return(result);
        }