Ejemplo n.º 1
0
        WxeStepList _stepList = null; // represents Then or Else step list, depending on result of If()

        public override void Execute(WxeContext context)
        {
            Type type = this.GetType();

            if (_stepList == null)
            {
                MethodInfo ifMethod = type.GetMethod(
                    "If", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly, null, new Type[0], null);
                if (ifMethod == null || ifMethod.ReturnType != typeof(bool))
                {
                    throw new WxeException("If-block " + type.FullName + " does not define method \"bool If()\".");
                }

                bool result = (bool)ifMethod.Invoke(this, new object[0]);
                if (result)
                {
                    _stepList = GetResultList("Then");
                    if (_stepList == null)
                    {
                        throw new WxeException("If-block " + type.FullName + " does not define nested class \"Then\".");
                    }
                }
                else
                {
                    _stepList = GetResultList("Else");
                }
            }

            if (_stepList != null)
            {
                _stepList.Execute(context);
            }
        }
Ejemplo n.º 2
0
        private void InitializeSteps()
        {
            Type type = this.GetType();

            Type tryBlockType = type.GetNestedType("Try", BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            if (tryBlockType == null)
            {
                throw new WxeException("Try/catch block type " + type.FullName + " has no nested type named \"Try\".");
            }
            if (!typeof(WxeStepList).IsAssignableFrom(tryBlockType))
            {
                throw new WxeException("Type " + tryBlockType.FullName + " must be derived from WxeTryBlock.");
            }
            _trySteps = (WxeStepList)Activator.CreateInstance(tryBlockType);
            _trySteps.SetParentStep(this);

            Type finallyBlockType = type.GetNestedType("Finally", BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            if (finallyBlockType != null)
            {
                if (!typeof(WxeStepList).IsAssignableFrom(finallyBlockType))
                {
                    throw new WxeException("Type " + finallyBlockType.FullName + " must be derived from WxeFinallyBlock.");
                }
                _finallySteps = (WxeStepList)Activator.CreateInstance(finallyBlockType);
                _finallySteps.SetParentStep(this);
            }
            else
            {
                _finallySteps = null;
            }

            MemberInfo[] catchBlockTypes = NumberedMemberFinder.FindMembers(
                type,
                "Catch",
                MemberTypes.NestedType,
                BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            _catchBlocks = new ArrayList();
            foreach (Type catchBlockType in catchBlockTypes)
            {
                if (!typeof(WxeCatchBlock).IsAssignableFrom(catchBlockType))
                {
                    throw new WxeException("Type " + catchBlockType.FullName + " must be derived from WxeCatchBlock.");
                }
                Add((WxeCatchBlock)Activator.CreateInstance(catchBlockType));
            }
        }
Ejemplo n.º 3
0
        private WxeStepList GetResultList(string name)
        {
            Type type         = this.GetType();
            Type stepListType = type.GetNestedType(name, BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            if (stepListType == null)
            {
                return(null);
            }
            if (!typeof(WxeStepList).IsAssignableFrom(stepListType))
            {
                throw new WxeException("Type " + stepListType.FullName + " must be derived from WxeStepList.");
            }

            WxeStepList resultList = (WxeStepList)System.Activator.CreateInstance(stepListType);

            resultList.SetParentStep(this);
            return(resultList);
        }
Ejemplo n.º 4
0
        public WxeTryCatch(Type tryStepListType, Type finallyStepListType, params Type[] catchBlockTypes)
        {
            _trySteps = (WxeStepList)Activator.CreateInstance(tryStepListType);
            _trySteps.SetParentStep(this);

            _catchBlocks = new ArrayList();
            if (catchBlockTypes != null)
            {
                foreach (Type catchBlockType in catchBlockTypes)
                {
                    Add((WxeCatchBlock)Activator.CreateInstance(catchBlockType));
                }
            }

            if (finallyStepListType != null)
            {
                _finallySteps = (WxeStepList)Activator.CreateInstance(finallyStepListType);
                _finallySteps.SetParentStep(this);
            }
            else
            {
                _finallySteps = null;
            }
        }