Exemplo n.º 1
0
        private static string GetSnippet(ContractTypes contractTypes)
        {
            var sb = new StringBuilder();

            sb.AppendLine("class TestClass {");

            sb.AppendLineIf(contractTypes.HasFlag(ContractTypes.Post), "[return: NonNull]");
            sb.Append("public string TestMethod(");
            sb.AppendIf(contractTypes.HasFlag(ContractTypes.Pre), "[NonNull]");
            sb.AppendLine("string text, string output) {");
            sb.AppendLine("return output; } }");
            return(sb.ToString());
        }
Exemplo n.º 2
0
        private static string GetSnippet(ContractTypes contractTypes, string result = null)
        {
            var sb = new StringBuilder();

            sb.AppendLine("class TestClass {");

            sb.AppendLineIf(contractTypes.HasFlag(ContractTypes.Post), "[return: NonNull]");
            sb.Append("public static explicit operator string(");
            sb.AppendIf(contractTypes.HasFlag(ContractTypes.Pre), "[NonNull]");
            sb.AppendLine("TestClass obj) {");
            sb.AppendLine($"return {(result == null ? "null" : $"\"{result}\"")};");
            sb.AppendLine("} }");
            return(sb.ToString());
        }
        private static string GetMethodSnippet(ContractTypes contractTypes, string result = null)
        {
            var sb = new StringBuilder();

            sb.AppendLine("class TestClass {");

            sb.AppendLineIf(contractTypes.HasFlag(ContractTypes.Post), "[return: NonNull]");
            sb.Append("public string TestMethod(");
            sb.AppendIf(contractTypes.HasFlag(ContractTypes.Pre), "[NonNull]");
            sb.AppendLine("string text) =>");
            sb.Append($"{(result == null ? "null" : $"\"{result}\"")};");
            sb.AppendLine("}");
            return(sb.ToString());
        }
Exemplo n.º 4
0
        public static string GetSnippet(string attributeName, string typeName, ContractTypes contractTypes)
        {
            var sb = new StringBuilder();

            sb.AppendLine("class TestClass {");

            sb.AppendLineIf(contractTypes.HasFlag(ContractTypes.Post), $"[return: {attributeName}]");

            sb.Append($"public {typeName} TestMethod(");

            sb.AppendIf(contractTypes.HasFlag(ContractTypes.Pre), $"[{attributeName}]");

            sb.AppendLine($"{typeName} value) {{");
            sb.AppendLine("return value; } }");
            return(sb.ToString());
        }
Exemplo n.º 5
0
        private static string GetMethodSnippet(ContractTypes contractTypes)
        {
            var sb = new StringBuilder();

            sb.AppendLine("abstract class BaseClass {");
            sb.AppendLineIf(contractTypes.HasFlag(ContractTypes.Post), "[return: NonNull]");
            sb.Append("public abstract string TestMethod(");
            sb.AppendIf(contractTypes.HasFlag(ContractTypes.Pre), "[NonNull]");
            sb.AppendLine("string text);");
            sb.AppendLine("}");

            sb.AppendLine("class TestClass : BaseClass {");
            sb.AppendLine("public override string TestMethod(string text) {");
            sb.AppendLine("return text;");
            sb.AppendLine("}");
            sb.AppendLine("}");
            return(sb.ToString());
        }
Exemplo n.º 6
0
        private static string GetMethodSnippet(ContractTypes contractTypes, bool explicitImplementation)
        {
            var sb = new StringBuilder();

            sb.AppendLine("interface ITest {");
            sb.AppendLineIf(contractTypes.HasFlag(ContractTypes.Post), "[return: NonNull]");
            sb.Append("string TestMethod(");
            sb.AppendIf(contractTypes.HasFlag(ContractTypes.Pre), "[NonNull]");
            sb.AppendLine("string text);");
            sb.AppendLine("}");

            sb.AppendLine("class TestClass : ITest {");
            sb.AppendIf(!explicitImplementation, "public ");
            sb.Append("string ");
            sb.AppendIf(explicitImplementation, "ITest.");
            sb.AppendLine("TestMethod(string text) {");
            sb.AppendLine("return text;");
            sb.AppendLine("}");
            sb.AppendLine("}");
            return(sb.ToString());
        }
Exemplo n.º 7
0
        private static string GetSnippet(ContractTypes contractTypes)
        {
            var sb = new StringBuilder();

            sb.AppendLine("class TestClass {");

            sb.AppendLineIf(contractTypes.HasFlag(ContractTypes.Post), "[return: NonNull]");
            sb.AppendLine("public string TestMethod() {");

            //This lambda's return statement should not be affected.
            sb.AppendLine(@"Func<string> someLambda = () => { return null; };");
            sb.AppendLine(@"var someResult = someLambda();");

            sb.AppendLine(@"return ""text"";");
            sb.AppendLine("}");

            sb.AppendLine("}");
            return(sb.ToString());
        }