Beispiel #1
0
        private void InitializeSteps()
        {
            Type type = this.GetType();

            MemberInfo[] members = NumberedMemberFinder.FindMembers(
                type,
                "Step",
                MemberTypes.Field | MemberTypes.Method | MemberTypes.NestedType,
                BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly);

            foreach (MemberInfo member in members)
            {
                if (member is FieldInfo)
                {
                    FieldInfo fieldInfo = (FieldInfo)member;
                    Add((WxeStep)fieldInfo.GetValue(this));
                }
                else if (member is MethodInfo)
                {
                    MethodInfo methodInfo = (MethodInfo)member;
                    Add(this, methodInfo);
                }
                else if (member is Type)
                {
                    Type subtype = member as Type;
                    if (typeof(WxeStep).IsAssignableFrom(subtype))
                    {
                        Add((WxeStep)Activator.CreateInstance(subtype));
                    }
                }
            }
        }
Beispiel #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));
            }
        }