Create <T>( Module parent = null, PreInitDelegate <T> preInitCallback = null) where T : Module, new() { try { if (!CanCreate(typeof(T))) { return(null); } var module = new T(); if (preInitCallback != null) { preInitCallback(module); } module.Init(parent); module.GetExecutionPolicy(Graph.Instance.Mode); AllModules.Add(module); return(module); } catch (ModuleCreationException exception) { // persist the module type from the inner-most module creation call throw exception; } catch (System.Exception exception) { throw new ModuleCreationException(typeof(T), exception); } }
Create <T>( Module parent = null, PreInitDelegate <T> preInitCallback = null, PostInitDelegate postInitCallback = null) where T : Module, new() { try { var stopwatch = System.Diagnostics.Stopwatch.StartNew(); if (!CanCreate(typeof(T))) { return(null); } var module = new T(); if (null != parent) { module.Macros.Add("parentmodulename", parent.Macros["modulename"]); var encapsulatingParent = parent.GetEncapsulatingReferencedModule(); module.Macros.Add("encapsulatedparentmodulename", encapsulatingParent.Macros["modulename"]); // since the parent might have been redirected module.AddRedirectedPackageDirectory(parent); } if (preInitCallback != null) { preInitCallback(module); } module.InitializeModuleConfiguration(); // required to run after the preInitCallback for referenced modules module.Init(parent); if (postInitCallback != null) { postInitCallback(module); } module.GetExecutionPolicy(Graph.Instance.Mode); AllModules.Add(module); stopwatch.Stop(); module.CreationTime = new System.TimeSpan(stopwatch.ElapsedTicks); return(module); } catch (UnableToBuildModuleException exception) { if (null == exception.ModuleType) { exception.ModuleType = typeof(T); throw exception; } throw; } catch (ModuleCreationException exception) { // persist the module type from the inner-most module creation call throw exception; } catch (System.Exception exception) { throw new ModuleCreationException(typeof(T), exception); } }
CloneWithPrivatePatches <T>( T source, Module parent = null, PreInitDelegate <T> preInitCallback = null, PostInitDelegate postInitCallback = null) where T : Module, new() { var clone = Create <T>(parent, preInitCallback, postInitCallback); if (null == clone) { throw new Exception("Making a clone has failed, even though the source module exists. This is unexpected behaviour. Please report it with details for reproduction."); } clone.PrivatePatches.AddRange(source.PrivatePatches); if (source is IChildModule) { clone.PrivatePatches.AddRange((source as IChildModule).Parent.PrivatePatches); } return(clone); }