/// <summary> /// Fügt einer Eigenschaft den Contract Aspekt hinzu. /// </summary> /// <param name="contractList">Liste mit den übergebenen Kontrakten.</param> /// <param name="aspectCollection">Collection mit allen Membern denen der Aspekt zugewiesen wurde.</param> /// <param name="property">PropertyInfo Objekt der Eigenschaft an der der Kontrakt definiert wurde.</param> private void AddAspectToProperty(List<string> contractList, LaosReflectionAspectCollection aspectCollection, PropertyInfo property) { // Klassennamen erzeugen string contractClassName = AspectController.Instance.CreateContractClassName(property.DeclaringType.Assembly); MethodModel getContractModel = null; MethodModel setContractModel = null; // Kontraktmodelle erzeugen: if (contractList.Count == 4) { setContractModel = new MethodModel(contractList[0], contractList[2], property, DbcAccessType, DbcCheckTime, contractClassName, DbcExceptionType, DbcExceptionString); getContractModel = new MethodModel(contractList[1], contractList[3], property, DbcAccessType, DbcCheckTime, contractClassName, DbcExceptionType, DbcExceptionString); } else { string requireContract = string.Empty; string ensureContract = string.Empty; if (contractList.Count == 2) { requireContract = contractList[0]; ensureContract = contractList[1]; } else if (contractList.Count == 1) { requireContract = contractList[0]; ensureContract = contractList[0]; } switch (DbcCheckTime) { case CheckTime.OnlyRequire: setContractModel = new MethodModel(requireContract, string.Empty, property, DbcAccessType, DbcCheckTime, contractClassName, DbcExceptionType, DbcExceptionString); getContractModel = new MethodModel(requireContract, string.Empty, property, DbcAccessType, DbcCheckTime, contractClassName, DbcExceptionType, DbcExceptionString); break; case CheckTime.OnlyEnsure: setContractModel = new MethodModel(string.Empty, ensureContract, property, DbcAccessType, DbcCheckTime, contractClassName, DbcExceptionType, DbcExceptionString); getContractModel = new MethodModel(string.Empty, ensureContract, property, DbcAccessType, DbcCheckTime, contractClassName, DbcExceptionType, DbcExceptionString); break; default: setContractModel = new MethodModel(requireContract, ensureContract, property, DbcAccessType, DbcCheckTime, contractClassName, DbcExceptionType, DbcExceptionString); getContractModel = new MethodModel(requireContract, ensureContract, property, DbcAccessType, DbcCheckTime, contractClassName, DbcExceptionType, DbcExceptionString); break; } } // Die Aspekte den Get bzw. Set Methoden zuweisen. if ((property.GetGetMethod(true) != null) && (DbcAccessType != AccessType.OnlyOnSet)) aspectCollection.AddAspect(property.GetGetMethod(true), new MethodBoundaryAspect(getContractModel)); if ((property.GetSetMethod(true) != null) && (DbcAccessType != AccessType.OnlyOnGet)) aspectCollection.AddAspect(property.GetSetMethod(true), new MethodBoundaryAspect(setContractModel)); }
/// <summary> /// Konsturktor /// </summary> /// <param name="contactModel">Kontraktinformationen für die Methode</param> internal MethodBoundaryAspect(MethodModel contactModel) { mContractModel = contactModel; }
/// <summary> /// Fügt einer Methode den Contract Aspekt hinzu. /// </summary> /// <param name="contractList">Liste mit den übergebenen Kontrakten.</param> /// <param name="aspectCollection">Collection mit allen Membern denen der Aspekt zugewiesen wurde.</param> /// <param name="method">MethodInfo Objekt der Methode an der der Kontrakt definiert wurde.</param> private void AddAspectToMethod(List<string> contractList, LaosReflectionAspectCollection aspectCollection, MethodInfo method) { // Klassennamen erzeugen string contractClassName = AspectController.Instance.CreateContractClassName(method.DeclaringType.Assembly); MethodModel contractModel = null; // Kontraktmodell erzeugen: string requireContract = string.Empty; string ensureContract = string.Empty; if (contractList.Count == 2) { requireContract = contractList[0]; ensureContract = contractList[1]; } else if (contractList.Count == 1) { requireContract = contractList[0]; ensureContract = contractList[0]; } switch (DbcCheckTime) { case CheckTime.OnlyRequire: contractModel = new MethodModel(requireContract, string.Empty, method, DbcAccessType, DbcCheckTime, contractClassName, DbcExceptionType, DbcExceptionString); break; case CheckTime.OnlyEnsure: contractModel = new MethodModel(string.Empty, ensureContract, method, DbcAccessType, DbcCheckTime, contractClassName, DbcExceptionType, DbcExceptionString); break; default: contractModel = new MethodModel(requireContract, ensureContract, method, DbcAccessType, DbcCheckTime, contractClassName, DbcExceptionType, DbcExceptionString); break; } aspectCollection.AddAspect(method, new MethodBoundaryAspect(contractModel)); }