public IReturnType ToDefaultDelegate() { IReturnType type = new GetClassReturnType(cu.ProjectContent, "System.Func", 0); List <IReturnType> parameters = new List <IReturnType>(); if (this.HasParameterList) { parameters = MethodParameters.Select(p => p.ReturnType ?? new GetClassReturnType(cu.ProjectContent, "System.Object", 0)).ToList(); } if (this.MethodReturnType != null && this.MethodReturnType.FullyQualifiedName == "System.Void") { type = new GetClassReturnType(cu.ProjectContent, "System.Action", 0); } else { var rt = this.MethodReturnType; if (rt == null) { rt = new GetClassReturnType(cu.ProjectContent, "System.Object", 0); } parameters.Add(rt); } return(new ConstructedReturnType(type, parameters)); }
private void AssertMethod() { // Check Method Return Type MethodInfo info; info = SUT.GetMethod(MemberName, BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); Assert.True(info.ReturnType == DataType, $"Expected the {MemberName} method to return a {DataType.Name}, but it returns a {info.ReturnType}"); // Check Method Parameters var actualParamTypes = string.Join(",", info.GetParameters().Select(p => p.ParameterType.Name)); var expectedParamTypes = string.Join(",", MethodParameters.Select(x => x.Name)); var expectedSignature = $"{DataType.Name} {MemberName}({expectedParamTypes})"; Assert.True(expectedParamTypes == actualParamTypes, $"Expected the {MemberName} method to have a method signature of {expectedSignature}"); switch (Access) { case AccessModifier.Public: Assert.True(info.IsPublic, $"Expected the {expectedSignature} to be public"); break; case AccessModifier.Private: Assert.True(info.IsPrivate, $"Expected the {expectedSignature} to NOT be public"); break; } switch (InstanceOrStatic) { case Declared.Static: Assert.True(info.IsStatic, $"Expected the {expectedSignature} to be static"); break; case Declared.Instance: Assert.True(!info.IsStatic, $"Expected the {expectedSignature} to be non-static (an instance method)"); break; } }