private static void CheckCalledMethod(ErrorsService errorsService, IHasMethods viewModelType, string calledMethodName, string propertyName) { if (calledMethodName.IsNullOrEmpty()) { return; } var calledMethodsBeforeGetProperty = viewModelType.GetMethods(calledMethodName).ToArray(); switch (calledMethodsBeforeGetProperty.Length) { case 0: errorsService.AddError($"Not found called method with name '{calledMethodName}', " + $"specified in '{nameof(PatchingPropertyAttribute)}' at property '{propertyName}'"); break; case 1: if (calledMethodsBeforeGetProperty.Single().ParameterTypes.Any()) { errorsService.AddError($"Called method '{calledMethodName}' can not have parameters, " + $"specified in '{nameof(PatchingPropertyAttribute)}' at property '{propertyName}'"); } break; default: errorsService.AddError($"Found several called methods with name '{calledMethodName}', " + $"specified in '{nameof(PatchingPropertyAttribute)}' at property '{propertyName}'"); break; } }
protected void Application_Start() { try { IocRetailerConnectModule.Register(); BundleConfig.RegisterBundles(BundleTable.Bundles); // Initilize logger log4net.Config.XmlConfigurator.Configure(); AreaRegistration.RegisterAllAreas(); RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); FluentValidationModelValidatorProvider.Configure(); Log.File.InfoFormat(Server.MapPath("~/license.key")); Stimulsoft.Base.StiLicense.LoadFromFile(Server.MapPath("~/license.key")); } catch (Exception ex) { var _error = new ErrorsService(); Log.File.ErrorFormat(_error.Msg.GenerateLogMsg(string.Format("Unhandled error on page. Error:{0}", ex.Message))); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_Error(object sender, EventArgs e) { //在出现未处理的错误时运行的代码 var context = HttpContext.Current; if (context != null) { Exception ex = HttpContext.Current.Server.GetLastError(); LogUtil.ErrorLog("\r\n错误开始===========================================" // + "\r\n客户机IP:" // + Request.UserHostAddress // + "\r\n错误地址:" // + Request.Url // + "\r\n异常信息:" // + Server.GetLastError().Message // + "\r\n错误结束===========================================", ex); //当在派生类中重写时,返回 System.Exception,它是一个或多个并发的异常的根源。 LogUtil.ErrorLog(ex.GetBaseException()); //记录用户登录系统日志 var errorService = new ErrorsService(); var errors = new t_errors { account_name = context.User.Identity.Name, account_ip = Request.UserHostAddress, account_id = 0, action_on = DateTime.Now, action_desc = Server.GetLastError().Message }; errorService.Add(errors); if (ex.Message.Equals("系统授权已到期,请贵公司及时续签维护合同,联系河南禄恒软件科技有限公司,联系人李彦江(18768868380),谢谢您的合作。")) { context.Response.Redirect("~/login.html"); return; } //var sb = new StringBuilder(); //sb.Append("<b>系统出现如下错误:</b><br/><br/>"); //sb.Append("<b>发生时间:</b> " + DateTime.Now + "<br/><br/>"); //sb.Append("<b>错误描述:</b> " + ex.Message.Replace("\r\n", "") + "<br/><br/>"); //sb.Append("<b>错误对象:</b> " + ex.Source + "<br/><br/>"); //sb.Append("<b>错误页面:</b> " + HttpContext.Current.Request.Url + "<br/><br/>"); //sb.Append("<b>浏览器IE:</b> " + HttpContext.Current.Request.UserAgent + "<br/><br/>"); //sb.Append("<b>服务器IP:</b> " + HttpContext.Current.Request.ServerVariables.Get("Local_Addr") + "<br/><br/>"); //sb.Append("<b>方法名称:</b> " + ex.TargetSite + "<br/><br/>"); //sb.Append("<b>C#类名称:</b> " + ex.TargetSite.DeclaringType + "<br/><br/>"); //sb.Append("<b>成员变量:</b> " + ex.TargetSite.MemberType + "<br/><br/>"); //Cookie.SetObj("Http_Errors", sb.ToString()); //Server.ClearError(); ////出错画面处理 //context.Response.Redirect("~/SystemError.aspx"); } }
public void CreateBrandShouldCreateBrand(string errorMessage, string hyperLink) { var errorsService = new ErrorsService(); var model = errorsService.CreateCreateionErrorViewModel(errorMessage, hyperLink); Assert.Equal(errorMessage, model.ErrorMessage); Assert.Equal(hyperLink, model.HyperLink); }
private void CheckPatchingMethodNames(IEnumerable <ICommonMethod> patchingMethods) { var methodsWithUseSearchByName = patchingMethods .Where(method => method.NotContainsAttribute <NotUseSearchByNameAttribute>() && (applicationPatcherWpfConfiguration.ConnectByNameIfExistConnectAttribute || method.NotContainsAttribute <ConnectMethodToMethodAttribute>() && method.NotContainsAttribute <ConnectMethodToPropertyAttribute>())); var errorsService = new ErrorsService() .AddErrors(methodsWithUseSearchByName .Where(method => !nameRulesService.IsNameValid(method.Name, UseNameRulesFor.CommandExecuteMethod)) .Select(method => $"Not valid patching command method name '{method.Name}'")); if (errorsService.HasErrors) { throw new ViewModelCommandPatchingException(errorsService); } }
private void CheckPatchingPropertyNames(IEnumerable <ICommonProperty> patchingProperties) { var propertiesWithUseSearchByName = patchingProperties .Where(property => property.NotContainsAttribute <NotUseSearchByNameAttribute>() && (applicationPatcherWpfConfiguration.ConnectByNameIfExistConnectAttribute || property.NotContainsAttribute <ConnectPropertyToFieldAttribute>())); var errorsService = new ErrorsService() .AddErrors(propertiesWithUseSearchByName .Where(property => !nameRulesService.IsNameValid(property.Name, UseNameRulesFor.DependencyProperty)) .Select(property => $"Not valid patching property name '{property.Name}'")); if (errorsService.HasErrors) { throw new FrameworkElementDependencyPatchingException(errorsService); } }
private static void CheckAssembly(ICommonAssembly assembly, ICommonType viewModelBaseType) { var typesWithPatchingViewModelAttribute = assembly.TypesFromThisAssembly.Where(type => type.ContainsReflectionAttribute <PatchingViewModelAttribute>()).ToArray(); var typesWithNotPatchingViewModelAttribute = assembly.TypesFromThisAssembly.Where(type => type.ContainsReflectionAttribute <NotPatchingViewModelAttribute>()).ToArray(); var errorsService = new ErrorsService() .AddErrors(typesWithPatchingViewModelAttribute .Where(type => type.IsNotInheritedFrom(viewModelBaseType)) .Select(type => $"Type '{type.FullName}' with attribute " + $"'{nameof(PatchingViewModelAttribute)}' must be inherited from '{viewModelBaseType.FullName}'")) .AddErrors(typesWithNotPatchingViewModelAttribute .Where(type => type.IsNotInheritedFrom(viewModelBaseType)) .Select(type => $"Type '{type.FullName}' with attribute " + $"'{nameof(NotPatchingViewModelAttribute)}' must be inherited from '{viewModelBaseType.FullName}'")) .AddErrors(typesWithPatchingViewModelAttribute .Intersect(typesWithNotPatchingViewModelAttribute) .Select(type => $"Patching type '{type.FullName}' can not have " + $"'{nameof(PatchingViewModelAttribute)}' and '{nameof(NotPatchingViewModelAttribute)}' at the same time")); if (errorsService.HasErrors) { throw new ViewModelPatchingException(errorsService); } }
public ViewModelCommandPatchingException(ErrorsService errorsService) : this(errorsService.Errors.Select((error, i) => $" {i + 1}) {error}").JoinToString("\n")) { }
public FrameworkElementDependencyPatchingException(ErrorsService errorsService) : this(errorsService.Errors.Select((error, i) => $" {i + 1}) {error}").JoinToString("\n")) { }
private static void CheckViewModel(IHasType commandType, ICommonType viewModelType) { var errorsService = new ErrorsService(); foreach (var property in viewModelType.Properties.Select(property => property)) { var patchingPropertyAttribute = property.GetCastedAttribute <PatchingPropertyAttribute>(); if (patchingPropertyAttribute != null) { if (property.IsInheritedFrom(commandType)) { errorsService.AddError($"Patching property '{property.Name}' can not inherited from '{KnownTypeNames.ICommand}'"); } if (property.ContainsAttribute <NotPatchingPropertyAttribute>()) { errorsService.AddError($"Patching property '{property.Name}' can not have " + $"'{nameof(PatchingPropertyAttribute)}' and '{nameof(NotPatchingPropertyAttribute)}' at the same time"); } CheckCalledMethod(errorsService, viewModelType, patchingPropertyAttribute.CalledMethodNameBeforeGetProperty, property.Name); CheckCalledMethod(errorsService, viewModelType, patchingPropertyAttribute.CalledMethodNameBeforeSetProperty, property.Name); CheckCalledMethod(errorsService, viewModelType, patchingPropertyAttribute.CalledMethodNameAfterSuccessSetProperty, property.Name); CheckCalledMethod(errorsService, viewModelType, patchingPropertyAttribute.CalledMethodNameAfterSetProperty, property.Name); } if (property.IsInheritedFrom(commandType)) { continue; } var connectPropertyToFieldAttributes = property.GetCastedAttributes <ConnectPropertyToFieldAttribute>().ToArray(); if (!connectPropertyToFieldAttributes.Any()) { continue; } if (property.ContainsAttribute <NotPatchingPropertyAttribute>()) { errorsService.AddError($"Patching property '{property.Name}' can not have '{nameof(NotPatchingPropertyAttribute)}', " + $"connection in '{nameof(ConnectPropertyToFieldAttribute)}' at property '{property.Name}'"); } foreach (var attribute in connectPropertyToFieldAttributes) { var field = viewModelType.GetField(attribute.ConnectingFieldName); if (field == null) { errorsService.AddError($"Not found field with name '{attribute.ConnectingFieldName}', " + $"specified in '{nameof(ConnectPropertyToFieldAttribute)}' at property '{property.Name}'"); } else if (property.IsNot(field)) { errorsService.AddError($"Types do not match between property '{property.Name}' and field '{field.Name}', " + $"connection in '{nameof(ConnectPropertyToFieldAttribute)}' at property '{property.Name}'"); } } } foreach (var field in viewModelType.Fields.Select(field => field).Where(field => field.IsNotInheritedFrom(commandType))) { foreach (var attribute in field.GetCastedAttributes <ConnectFieldToPropertyAttribute>()) { var property = viewModelType.GetProperty(attribute.ConnectingPropertyName); if (property == null) { errorsService.AddError($"Not found property with name '{attribute.ConnectingPropertyName}', " + $"specified in '{nameof(ConnectFieldToPropertyAttribute)}' at field '{field.Name}'"); } else { if (field.IsNot(property)) { errorsService.AddError($"Types do not match between field '{field.Name}' and property '{property.Name}', " + $"connection in '{nameof(ConnectFieldToPropertyAttribute)}' at field '{field.Name}'"); } if (property.ContainsAttribute <NotPatchingPropertyAttribute>()) { errorsService.AddError($"Patching property '{property.Name}' can not have '{nameof(NotPatchingPropertyAttribute)}', " + $"connection in '{nameof(ConnectFieldToPropertyAttribute)}' at field '{field.Name}'"); } } } } if (errorsService.HasErrors) { throw new ViewModelPropertyPatchingException(errorsService); } }
private static void CheckViewModel(IHasType commandType, ICommonType viewModelType) { var errorsService = new ErrorsService(); foreach (var method in viewModelType.Methods) { if (method.ContainsAttribute <PatchingCommandAttribute>()) { if (method.ParameterTypes.Any()) { errorsService.AddError($"Patching method '{method.Name}' can not have parameters"); } if (method.ContainsAttribute <NotPatchingCommandAttribute>()) { errorsService.AddError($"Patching method '{method.Name}' can not have " + $"'{nameof(PatchingCommandAttribute)}' and '{nameof(NotPatchingCommandAttribute)}' at the same time"); } if (method.ReturnType != typeof(void)) { errorsService.AddError($"Patching method '{method.Name}' can not have " + $"'{method.ReturnType.FullName}' return type, allowable types: '{typeof(void).FullName}'"); } } foreach (var attribute in method.GetCastedAttributes <ConnectMethodToMethodAttribute>()) { if (method.ParameterTypes.Any()) { errorsService.AddError($"Patching method '{method.Name}' can not have parameters"); } if (method.ContainsAttribute <NotPatchingCommandAttribute>()) { errorsService.AddError($"Patching method '{method.Name}' can not have '{nameof(NotPatchingCommandAttribute)}'"); } if (method.ReturnType != typeof(void) && method.ReturnType != typeof(bool)) { errorsService.AddError($"Patching method '{method.Name}' can not have " + $"'{method.ReturnType.FullName}' return type, allowable types: '{typeof(void).FullName}', '{typeof(bool).FullName}'"); } var methods = viewModelType.GetMethods(attribute.ConnectingMethodName).ToArray(); switch (methods.Length) { case 0: errorsService.AddError($"Not found method with name '{attribute.ConnectingMethodName}', " + $"specified in '{nameof(ConnectMethodToMethodAttribute)}' at method '{method.Name}'"); break; case 1: var singleMethod = methods.Single(); if (singleMethod.ParameterTypes.Any()) { errorsService.AddError($"Patching method '{singleMethod.Name}' can not have parameters, " + $"connection in '{nameof(ConnectMethodToMethodAttribute)}' at method '{method.Name}'"); } if (singleMethod.ContainsAttribute <NotPatchingCommandAttribute>()) { errorsService.AddError($"Patching method '{singleMethod.Name}' can not have '{nameof(NotPatchingCommandAttribute)}', " + $"connection in '{nameof(ConnectMethodToMethodAttribute)}' at method '{method.Name}'"); } if (singleMethod.ReturnType != typeof(void) && singleMethod.ReturnType != typeof(bool)) { errorsService.AddError($"Patching method '{singleMethod.Name}' can not have " + $"'{singleMethod.ReturnType.FullName}' return type, allowable types: '{typeof(void).FullName}', '{typeof(bool).FullName}', " + $"connection in '{nameof(ConnectMethodToMethodAttribute)}' at method '{method.Name}'"); } else { if (method.ReturnType == typeof(void) && singleMethod.ReturnType == typeof(void)) { errorsService.AddError($"Can not be connect two execute methods: '{method.Name}' and '{singleMethod.Name}', " + $"connection in '{nameof(ConnectMethodToMethodAttribute)}' at method '{method.Name}'"); } if (method.ReturnType == typeof(bool) && singleMethod.ReturnType == typeof(bool)) { errorsService.AddError($"Can not be connect two can execute methods: '{method.Name}' and '{singleMethod.Name}', " + $"connection in '{nameof(ConnectMethodToMethodAttribute)}' at method '{method.Name}'"); } } break; default: errorsService.AddError($"Found several methods with name '{attribute.ConnectingMethodName}', " + $"specified in '{nameof(ConnectMethodToMethodAttribute)}' at method '{method.Name}'"); break; } } foreach (var attribute in method.GetCastedAttributes <ConnectMethodToPropertyAttribute>()) { if (method.ParameterTypes.Any()) { errorsService.AddError($"Patching method '{method.Name}' can not have parameters"); } if (method.ContainsAttribute <NotPatchingCommandAttribute>()) { errorsService.AddError($"Patching method '{method.Name}' can not have '{nameof(NotPatchingCommandAttribute)}'"); } if (method.ReturnType != typeof(void)) { errorsService.AddError($"Patching method '{method.Name}' can not have " + $"'{method.ReturnType.FullName}' return type, allowable types: '{typeof(void).FullName}'"); } var property = viewModelType.GetProperty(attribute.ConnectingPropertyName); if (property == null) { errorsService.AddError($"Not found property with name '{attribute.ConnectingPropertyName}', " + $"specified in '{nameof(ConnectMethodToPropertyAttribute)}' at method '{method.Name}'"); } else if (property.IsNotInheritedFrom(commandType)) { errorsService.AddError($"Property '{property.Name}' can not have '{property.Type.FullName}' type, " + $"allowable types: all inherited from '{KnownTypeNames.ICommand}', " + $"connection in '{nameof(ConnectMethodToPropertyAttribute)}' at method '{method.Name}'"); } } } foreach (var property in viewModelType.Properties) { if (property.IsInheritedFrom(commandType)) { foreach (var attribute in property.GetCastedAttributes <ConnectPropertyToFieldAttribute>()) { var field = viewModelType.GetField(attribute.ConnectingFieldName); if (field == null) { errorsService.AddError($"Not found field with name '{attribute.ConnectingFieldName}', " + $"specified in '{nameof(ConnectPropertyToFieldAttribute)}' at property '{property.Name}'"); } else if (property.IsNot(field)) { errorsService.AddError($"Types do not match between property '{property.Name}' and field '{field.Name}', " + $"connection in '{nameof(ConnectPropertyToFieldAttribute)}' at property '{property.Name}'"); } } } var connectPropertyToMethodAttributes = property.GetCastedAttributes <ConnectPropertyToMethodAttribute>().ToArray(); if (!connectPropertyToMethodAttributes.Any()) { continue; } if (property.IsNotInheritedFrom(commandType)) { errorsService.AddError($"Patching property '{property.Name}' can not have '{property.Type.FullName}' type, " + $"allowable types: all inherited from '{KnownTypeNames.ICommand}'"); } foreach (var namesToMethods in connectPropertyToMethodAttributes.Select(attribute => attribute.ConnectingMethodNames.Select(name => new { Name = name, Methods = viewModelType.GetMethods(name).ToArray() }).ToArray())) { foreach (var nameToMethods in namesToMethods) { switch (nameToMethods.Methods.Length) { case 0: errorsService.AddError($"Not found method with name '{nameToMethods.Name}', " + $"specified in '{nameof(ConnectPropertyToMethodAttribute)}' at property '{property.Name}'"); break; case 1: var singleMethod = nameToMethods.Methods.Single(); if (singleMethod.ParameterTypes.Any()) { errorsService.AddError($"Patching method '{singleMethod.Name}' can not have parameters, " + $"connection in '{nameof(ConnectPropertyToMethodAttribute)}' at property '{property.Name}'"); } if (singleMethod.ContainsAttribute <NotPatchingCommandAttribute>()) { errorsService.AddError($"Patching method '{singleMethod.Name}' can not have '{nameof(NotPatchingCommandAttribute)}', " + $"connection in '{nameof(ConnectPropertyToMethodAttribute)}' at property '{property.Name}'"); } if (singleMethod.ReturnType != typeof(void) && singleMethod.ReturnType != typeof(bool)) { errorsService.AddError($"Patching method '{singleMethod.Name}' can not have " + $"'{singleMethod.ReturnType.FullName}' return type, allowable types: '{typeof(void).FullName}', '{typeof(bool).FullName}', " + $"connection in '{nameof(ConnectPropertyToMethodAttribute)}' at property '{property.Name}'"); } break; default: errorsService.AddError($"Found several methods with name '{nameToMethods.Name}', " + $"specified in '{nameof(ConnectPropertyToMethodAttribute)}' at property '{property.Name}'"); break; } } switch (namesToMethods.Length) { case 1: var singleNameToMethods = namesToMethods.Single(); if (singleNameToMethods.Methods.Length == 1 && singleNameToMethods.Methods.Single().ReturnType == typeof(bool)) { errorsService.AddError($"Can not be connect to can execute method '{singleNameToMethods.Methods.Single().Name}', " + $"connection in '{nameof(ConnectPropertyToMethodAttribute)}' at property '{property.Name}'"); } break; case 2: if (namesToMethods[0].Methods.Length == 1 && namesToMethods[1].Methods.Length == 1) { var singleFirstMethod = namesToMethods[0].Methods.Single(); var singleSecondMethod = namesToMethods[1].Methods.Single(); if (singleFirstMethod.ReturnType == typeof(void) && singleSecondMethod.ReturnType == typeof(void)) { errorsService.AddError($"Can not be connect to two execute methods: '{singleFirstMethod.Name}' and '{singleSecondMethod.Name}', " + $"connection in '{nameof(ConnectPropertyToMethodAttribute)}' at property '{property.Name}'"); } if (singleFirstMethod.ReturnType == typeof(bool) && singleSecondMethod.ReturnType == typeof(bool)) { errorsService.AddError($"Can not be connect to two can execute methods: '{singleFirstMethod.Name}' and '{singleSecondMethod.Name}', " + $"connection in '{nameof(ConnectPropertyToMethodAttribute)}' at property '{property.Name}'"); } } break; } } } foreach (var field in viewModelType.Fields.Where(field => field.IsInheritedFrom(commandType))) { foreach (var attribute in field.GetCastedAttributes <ConnectFieldToPropertyAttribute>()) { var property = viewModelType.GetProperty(attribute.ConnectingPropertyName); if (property == null) { errorsService.AddError($"Not found property with name '{attribute.ConnectingPropertyName}', " + $"specified in '{nameof(ConnectFieldToPropertyAttribute)}' at field '{field.Name}'"); } else if (field.IsNot(property)) { errorsService.AddError($"Types do not match between field '{field.Name}' and property '{property.Name}', " + $"connection in '{nameof(ConnectFieldToPropertyAttribute)}' at field '{field.Name}'"); } } } if (errorsService.HasErrors) { throw new ViewModelCommandPatchingException(errorsService); } }
protected void Application_Error() { Exception curException = Server.GetLastError(); var httpException = curException as HttpException; if (httpException == null) { Exception innerException = curException.InnerException; httpException = innerException as HttpException; } Server.ClearError(); var _error = new ErrorsService(); if (httpException != null) { int httpCode = httpException.GetHttpCode(); _error.ErrorMessage = httpException.Message; // here we can add custom pages for different HTTP codes switch (httpCode) { case 400: { Log.File.InfoFormat(_error.Msg.GenerateLogMsg(string.Format("Error {0}: {1}. ", httpCode, httpException.Message))); Log.File.ErrorFormat(_error.Msg.GenerateLogMsg(string.Format("Error {0}: {1}. ", httpCode, httpException.Message))); Response.Redirect("/Error/http400"); return; } case 404: { Log.File.InfoFormat(_error.Msg.GenerateLogMsg(string.Format("Error {0}: {1}. ", httpCode, httpException.Message))); Log.File.ErrorFormat(_error.Msg.GenerateLogMsg(string.Format("Url {0} was not found", Request.Url))); Response.Redirect("/Error/http404"); return; } case 500: { Log.File.InfoFormat(_error.Msg.GenerateLogMsg(string.Format("Error {0}: {1}. ", httpCode, httpException.Message))); Log.File.ErrorFormat(_error.Msg.GenerateLogMsg(string.Format("Error {0}: {1}. ", httpCode, httpException.Message))); Response.Redirect("/Error/http500"); return; } default: { Log.File.InfoFormat(_error.Msg.GenerateLogMsg(string.Format("Error {0}: {1}. ", httpCode, httpException.Message))); Log.File.ErrorFormat(_error.Msg.GenerateLogMsg(string.Format("Error {0}: {1}. ", httpCode, httpException.Message))); return; } } } else { Log.File.ErrorFormat(_error.Msg.GenerateLogMsg(string.Format("Unhandled error on page. Error:{0} {1}{2}", curException.Message, curException.InnerException, curException.Source))); Server.ClearError(); Response.Redirect("/Error/Unhandled"); } }
private static void CheckFrameworkElement(ICommonType frameworkElementType, ICommonType dependencyPropertyType) { var errorsService = new ErrorsService(); foreach (var property in frameworkElementType.Properties) { if (property.ContainsAttribute <PatchingPropertyAttribute>() && property.ContainsAttribute <NotPatchingPropertyAttribute>()) { errorsService.AddError($"Patching property '{property.Name}' can not have " + $"'{nameof(PatchingPropertyAttribute)}' and '{nameof(NotPatchingPropertyAttribute)}' at the same time"); } var connectPropertyToDependencyAttributes = property.GetCastedAttributes <ConnectPropertyToFieldAttribute>().ToArray(); if (!connectPropertyToDependencyAttributes.Any()) { continue; } if (property.ContainsAttribute <NotPatchingPropertyAttribute>()) { errorsService.AddError($"Patching property '{property.Name}' can not have '{nameof(NotPatchingPropertyAttribute)}', " + $"connection in '{nameof(ConnectPropertyToFieldAttribute)}' at property '{property.Name}'"); } foreach (var attribute in connectPropertyToDependencyAttributes) { var field = frameworkElementType.GetField(attribute.ConnectingFieldName); if (field == null) { errorsService.AddError($"Not found field with name '{attribute.ConnectingFieldName}', " + $"specified in '{nameof(ConnectPropertyToFieldAttribute)}' at property '{property.Name}'"); } else { if (!field.MonoCecil.IsStatic) { errorsService.AddError($"Patching field '{field.Name}' can not be non static, " + $"connection in '{nameof(ConnectPropertyToFieldAttribute)}' at property '{property.Name}'"); } if (field.IsNot(dependencyPropertyType)) { errorsService.AddError($"Patching field '{field.Name}' can not have " + $"'{field.Type.FullName}' type, allowable types: '{dependencyPropertyType.FullName}', " + $"connection in '{nameof(ConnectPropertyToFieldAttribute)}' at property '{property.Name}'"); } } } } foreach (var field in frameworkElementType.Fields) { var connectDependencyToPropertyAttributes = field.GetCastedAttributes <ConnectFieldToPropertyAttribute>().ToArray(); if (!connectDependencyToPropertyAttributes.Any()) { continue; } if (field.IsNot(dependencyPropertyType)) { errorsService.AddError($"Patching field '{field.Name}' can not have " + $"'{field.Type.FullName}' type, allowable types: '{dependencyPropertyType.FullName}', " + $"connection in '{nameof(ConnectFieldToPropertyAttribute)}' at field '{field.Name}'"); } foreach (var attribute in connectDependencyToPropertyAttributes) { var property = frameworkElementType.GetProperty(attribute.ConnectingPropertyName); if (property == null) { errorsService.AddError($"Not found property with name '{attribute.ConnectingPropertyName}', " + $"specified in '{nameof(ConnectFieldToPropertyAttribute)}' at field '{field.Name}'"); } else if (property.ContainsAttribute <NotPatchingPropertyAttribute>()) { errorsService.AddError($"Patching property '{property.Name}' can not have '{nameof(NotPatchingPropertyAttribute)}', " + $"connection in '{nameof(ConnectFieldToPropertyAttribute)}' at field '{field.Name}'"); } } } if (errorsService.HasErrors) { throw new FrameworkElementDependencyPatchingException(errorsService); } }