コード例 #1
0
        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;
            }
        }