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)); } }
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); }
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; } }