private static string GenerateMethodWithNoRefOutParameters(MethodInfo baseMethod, string delegateCast, string argumentNameList, string outInitializers, string methodDescriptionWithOverride, string visibility, RequiresIsNewImplementation requiresIsNewImplementation, SortedSet <string> namespaces, bool isMake, bool hasEvents) { var expectationChecks = baseMethod.GetExpectationChecks(); var expectationExceptionMessage = baseMethod.GetExpectationExceptionMessage(); var requiresNew = requiresIsNewImplementation == RequiresIsNewImplementation.Yes ? "new" : string.Empty; var returnTypeName = $"{baseMethod.ReturnType.GetFullName(baseMethod.ReturnParameter)}"; if (baseMethod.ReturnType != typeof(void)) { var returnTypeAttributes = baseMethod.ReturnParameter.GetAttributes(true, namespaces); return(isMake ? MethodTemplates.GetFunctionForMake(outInitializers, methodDescriptionWithOverride, visibility, requiresNew, returnTypeAttributes, baseMethod.ReturnType) : baseMethod.ReturnType.RequiresExplicitCast() ? MethodTemplates.GetFunctionWithValueTypeReturnValue( baseMethod.MetadataToken, argumentNameList, returnTypeName, expectationChecks, delegateCast, outInitializers, expectationExceptionMessage, methodDescriptionWithOverride, visibility, requiresNew, returnTypeAttributes, hasEvents) : MethodTemplates.GetFunctionWithReferenceTypeReturnValue( baseMethod.MetadataToken, argumentNameList, returnTypeName, expectationChecks, delegateCast, outInitializers, expectationExceptionMessage, methodDescriptionWithOverride, visibility, requiresNew, returnTypeAttributes, hasEvents)); } else { return(isMake ? MethodTemplates.GetActionMethodForMake(outInitializers, methodDescriptionWithOverride, visibility) : MethodTemplates.GetActionMethod(baseMethod.MetadataToken, argumentNameList, expectationChecks, delegateCast, outInitializers, expectationExceptionMessage, methodDescriptionWithOverride, visibility, hasEvents)); } }
public static void GetActionMethodWhenHasEventsIsFalse() => Assert.That(MethodTemplates.GetActionMethod(1, "b", "c", "d", "e", "f", "g", "h", false), Is.EqualTo( @"h g { e if (this.handlers.TryGetValue(1, out var methodHandlers)) { var foundMatch = false; foreach(var methodHandler in methodHandlers) { if(c) { foundMatch = true; if(methodHandler.Method != null) { #pragma warning disable CS8604 ((d)methodHandler.Method)(b); #pragma warning restore CS8604 } methodHandler.IncrementCallCount(); break; } } if(!foundMatch) { throw new RE.ExpectationException($""No handlers were found for f""); } } else { throw new RE.ExpectationException($""No handlers were found for f""); } }"));