Beispiel #1
0
        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));
            }
        }
Beispiel #2
0
        public static void GetFunctionForMake() =>
        Assert.That(MethodTemplates.GetFunctionForMake("a", "b", "c", "d", "e", typeof(int)), Is.EqualTo(
                        @"ec d b
{
	a

	return default!;
}"));
Beispiel #3
0
        public static void GetFunctionForMake() =>
        Assert.That(MethodTemplates.GetFunctionForMake("a", "b", "c", "d", "e", typeof(int)), Is.EqualTo(
                        @"ec d b
{
	a

#pragma warning disable CS8762
	return default!;
#pragma warning restore CS8762
}"));