Пример #1
0
        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));
        }