private ContractNodes (AssemblyNode assembly, Action<string> errorHandler) { CoreSystemTypes.ModuleDefinition = assembly.Modules.First ().Definition; if (errorHandler != null) ErrorFound += errorHandler; this.ContractClass = assembly.GetType (ContractNamespace, ContractClassName) as Class; if (this.ContractClass == null) return; IEnumerable<Method> methods = this.ContractClass.GetMethods (RequiresName, CoreSystemTypes.Instance.TypeBoolean); foreach (Method method in methods) { if (method.GenericParameters == null || method.GenericParameters.Count == 0) this.RequiresMethod = method; } if (this.RequiresMethod == null) { this.ContractClass = null; return; } methods = this.ContractClass.GetMethods (RequiresName, CoreSystemTypes.Instance.TypeBoolean, CoreSystemTypes.Instance.TypeString); foreach (Method method in methods) { if (method.GenericParameters == null || method.GenericParameters.Count == 0) this.RequiresWithMessageMethod = method; } this.EnsuresMethod = this.ContractClass.GetMethod (EnsuresName, CoreSystemTypes.Instance.TypeBoolean); this.EnsuresWithMessageMethod = this.ContractClass.GetMethod (EnsuresName, CoreSystemTypes.Instance.TypeBoolean, CoreSystemTypes.Instance.TypeString); this.AssertMethod = this.ContractClass.GetMethod (AssertName, CoreSystemTypes.Instance.TypeBoolean); this.AssertWithMessageMethod = this.ContractClass.GetMethod (AssertName, CoreSystemTypes.Instance.TypeBoolean, CoreSystemTypes.Instance.TypeString); this.AssumeMethod = this.ContractClass.GetMethod (AssumeName, CoreSystemTypes.Instance.TypeBoolean); this.AssumeWithMessageMethod = this.ContractClass.GetMethod (AssumeName, CoreSystemTypes.Instance.TypeBoolean, CoreSystemTypes.Instance.TypeString); this.EndContractBlock = this.ContractClass.GetMethod (EndContractBlockName); foreach (FieldInfo fieldInfo in typeof (ContractNodes).GetFields ()) { if (fieldInfo.GetValue (this) != null) continue; string runtimeName = null; bool isRequired = false; object[] attributes = fieldInfo.GetCustomAttributes (typeof (RepresentationForAttribute), false); foreach (object attribute in attributes) { var representationForAttribute = attribute as RepresentationForAttribute; if (representationForAttribute != null) { runtimeName = representationForAttribute.RuntimeName; isRequired = representationForAttribute.IsRequired; break; } } if (isRequired) { string message = string.Format ("Could not find contract node for '{0}'", fieldInfo.Name); if (runtimeName != null) message = string.Format ("Could not find the method/type '{0}'", runtimeName); FireErrorFound (message); ClearFields (); } } }