Either <CompleterError, bool> IsBindable(IPropertySymbol property, BindableInfo bindableInfo) { if (bindableInfo?.IsBindable ?? false) { if (property.IsSealed) { return(CompleterError.CreatePropertyError(property, Messages.POCO_PropertyIsSealed)); } if (!property.IsVirtual) { return(CompleterError.CreatePropertyError(property, Messages.POCO_PropertyIsNotVirual)); } if (property.IsReadOnly) { return(CompleterError.CreatePropertyError(property, Messages.POCO_PropertyHasNoSetter)); } if (property.GetMethod.DeclaredAccessibility != Microsoft.CodeAnalysis.Accessibility.Public) { return(CompleterError.CreatePropertyError(property, Messages.POCO_PropertyHasNoPublicGetter)); } } return(property.IsVirtual && (bindableInfo?.IsBindable ?? true) && property.DeclaredAccessibility == Microsoft.CodeAnalysis.Accessibility.Public && property.GetMethod.DeclaredAccessibility == Microsoft.CodeAnalysis.Accessibility.Public && property.IsAutoImplemented() || bindableInfo.Return(bi => bi.IsBindable, () => false)); }
Either <CompleterError, string> GenerateProperty(IPropertySymbol property, BindableInfo bindableInfo) { Func <Chang, string, Either <CompleterError, MethodCallInfo> > getCallInfo = (chang, attributeMethodName) => { var methodName = attributeMethodName ?? $"On{property.Name}Chang{chang}".If(x => property.IsAutoImplemented()); if (methodName != null && GetMethods(methodName).Length > 1) { return(CompleterError.CreatePropertyError(property, Messages.POCO_MoreThanOnePropertyChangedMethod(chang))); } var method = methodName.With(x => GetMethods(x).SingleOrDefault()); if (method == null && attributeMethodName != null) { return(CompleterError.CreateForPropertyName(property, Messages.POCO_PropertyChangedMethodNotFound(chang).Format(attributeMethodName))); } if (method != null) { if (method.Parameters.Length > 1) { return(CompleterError.CreateMethodError(method, Messages.POCO_PropertyChangedCantHaveMoreThanOneParameter(chang))); } if (!method.ReturnsVoid) { return(CompleterError.CreateMethodError(method, Messages.POCO_PropertyChangedCantHaveReturnType(chang))); } if (method.Parameters.Length == 1 && method.Parameters.Single().Type != property.Type) { return(CompleterError.CreateParameterError(method.Parameters.Single(), Messages.POCO_PropertyChangedMethodArgumentTypeShouldMatchPropertyType(chang))); } } var needParameter = method.Return(x => x.Parameters.Length == 1, () => false); var valueName = needParameter ? (chang == Chang.ed ? "oldValue" : "value") : null; var methodCall = method.With(x => $"{x.Name}({valueName});".AddTabs(2)); return(new MethodCallInfo(methodCall, needParameter)); }; return(from changed in getCallInfo(Chang.ed, bindableInfo?.OnPropertyChangedMethodName) from changing in getCallInfo(Chang.ing, bindableInfo?.OnPropertyChangingMethodName) select GenerateProperty(property, changed, changing)); }