public void Should_Return_Correctly_Generated_Wrapper_For_Non_Generic_Type_With_Argument() { const string expected = "public void NonGeneric_ExtensionMethodWithParameter(System.Int32 value){" + "Cake.Core.Tests.Fixtures.MethodAliasGeneratorFixture.NonGeneric_ExtensionMethodWithParameter" + "(GetContext(),value);}"; var method = typeof(MethodAliasGeneratorFixture).GetMethod("NonGeneric_ExtensionMethodWithParameter"); // When var result = MethodAliasGenerator.Generate(method); // Then Assert.Equal(expected, result); }
public void Should_Return_Correctly_Generated_Wrapper_For_Generic_Type_With_Generic_Return_Value() { const string expected = "public TTest Generic_ExtensionMethodWithGenericReturnValue<TTest>(TTest value){" + "return Cake.Core.Tests.Fixtures.MethodAliasGeneratorFixture.Generic_ExtensionMethodWithGenericReturnValue<TTest>" + "(GetContext(),value);}"; var method = typeof(MethodAliasGeneratorFixture).GetMethods().SingleOrDefault(x => x.Name == "Generic_ExtensionMethodWithGenericReturnValue"); // When var result = MethodAliasGenerator.Generate(method); // Then Assert.Equal(expected, result); }
public void Should_Return_Correctly_Generated_Wrapper_For_Method_With_Return_Value() { const string expected = "public System.String NonGeneric_ExtensionMethodWithReturnValue(){" + "return Cake.Core.Tests.Fixtures.MethodAliasGeneratorFixture.NonGeneric_ExtensionMethodWithReturnValue" + "(GetContext());}"; var method = typeof(MethodAliasGeneratorFixture).GetMethod("NonGeneric_ExtensionMethodWithReturnValue"); // When var result = MethodAliasGenerator.Generate(method); // Then Assert.Equal(expected, result); }
private static string GenerateCode(MethodInfo method) { string code; if (method.IsDefined(typeof(CakeMethodAliasAttribute))) { code = MethodAliasGenerator.Generate(method); } else if (method.IsDefined(typeof(CakePropertyAliasAttribute))) { code = PropertyAliasGenerator.Generate(method); } else { throw new InvalidOperationException("Unknown alias type."); } return(code); }
private static string GetAliasCode(Script context) { var result = new Dictionary <string, string>(); foreach (var alias in context.Aliases) { string hash, code = alias.Type == ScriptAliasType.Method ? MethodAliasGenerator.Generate(alias.Method, out hash) : PropertyAliasGenerator.Generate(alias.Method, out hash); string @namespace = alias.Method.DeclaringType.Namespace ?? "@null"; if (result.ContainsKey(hash)) { var message = $"{alias.Type.ToString().ToLowerInvariant()} \"{alias.Name}\" excluded from code generation and will need to be fully qualified on ICakeContext."; if (context.ExcludedNamespaces.ContainsKey(@namespace)) { context.ExcludedNamespaces[@namespace].Add(message); } else { context.ExcludedNamespaces.Add(@namespace, new List <string>() { message }); } continue; } else if (context.ExcludedNamespaces.ContainsKey(@namespace)) { var message = $"{alias.Type.ToString().ToLowerInvariant()} \"{alias.Name}\" was included in code generation, but will need to be fully qualified on ICakeContext."; context.ExcludedNamespaces[@namespace].Add(message); } result.Add(hash, code); } return(string.Join("\r\n", result.Values)); }
public string Generate(string name) { var method = _methods.SingleOrDefault(x => x.Name == name); return(MethodAliasGenerator.Generate(method).NormalizeGeneratedCode()); }