/// <summary> /// Defining reaction mechanism. /// /// <param name="descriptorClass">/// @throws Exception</param> /// </summary> public void SetMechanism(Type descriptorClass) { if (reactionMechanism == null) { var descriptor = descriptorClass.GetConstructor(Type.EmptyTypes).Invoke(Array.Empty <object>()); if (!(descriptor is IReactionMechanism)) { throw new CDKException("The passed reaction class must be a IReactionMechanism"); } reactionMechanism = (IReactionMechanism)descriptor; } }
/// <summary> /// Extract the mechanism necessary for this reaction. /// </summary> /// <param name="entry">The EntryReact object</param> private void ExtractMechanism(EntryReact entry) { string mechanismName = "NCDK.Reactions.Mechanisms." + entry.Mechanism; try { Mechanism = (IReactionMechanism)this.GetType().Assembly.GetType(mechanismName).GetConstructor(Type.EmptyTypes).Invoke(Array.Empty <object>()); Trace.TraceInformation("Loaded mechanism: ", mechanismName); } catch (ArgumentException exception) { Trace.TraceError($"Could not find this IReactionMechanism: {mechanismName}"); Debug.WriteLine(exception); } catch (Exception exception) { Trace.TraceError($"Could not load this IReactionMechanism: {mechanismName}"); Debug.WriteLine(exception); } }