TypeParams() public static method

public static TypeParams ( CodeTypeParameterCollection typeParams ) : IEnumerable
typeParams System.CodeDom.CodeTypeParameterCollection
return IEnumerable
Esempio n. 1
0
        static CodeMemberMethod XF(int args)
        {
            var t = new CodeTypeReference("System.Linq.Expressions.Expression", Types.Func(args));
            var m = CreateMethod("XF", t, "expr", args, true);

            m.Comments.AddDocs(
                XmlDocs.TypeParams(m.TypeParameters, t),
                XmlDocs.Param("expr", "The " + XmlDocs.See(t) + " to return."),
                XmlDocs.Summary("Creates a " + XmlDocs.See(t) + " expression tree."),
                XmlDocs.Returns("Returns <paramref name=\"expr\" />.")
                );
            return(m);
        }
Esempio n. 2
0
        static CodeMemberMethod F(int args)
        {
            var t = Types.Func(args);
            var m = CreateMethod("F", t, "lambda", args, true);

            m.Comments.AddDocs(
                XmlDocs.TypeParams(m.TypeParameters, t),
                XmlDocs.Param("lambda", "The " + XmlDocs.See(t) + " to return."),
                XmlDocs.Summary("Creates a " + XmlDocs.See(t) + " delegate."),
                XmlDocs.Returns("Returns <paramref name=\"lambda\" />.")
                );
            return(m);
        }
Esempio n. 3
0
        static CodeMemberMethod RecFunc(int args)
        {
            var t = Types.Func(args);
            var m = new CodeMemberMethod()
            {
                Attributes = MemberAttributes.Static | MemberAttributes.Public,
                Name       = "RecFunc",
                ReturnType = t,
            };

            m.TypeParameters.AddRange(Types.GetTypeParameters(args, true).ToArray());
            var a = "lambda";

            m.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference("Func", t, t), a));
            m.Statements.ThrowWhenArgumentIsNull(a);
            var expr = AppendArgs(new StringBuilder(), args);

            expr.Append(" => lambda (RecFunc (lambda))");
            AppendArgs(expr, args);
            m.Statements.Add(new CodeMethodReturnStatement(new CodeSnippetExpression(expr.ToString())));
            m.Comments.AddRange("From: http://blogs.msdn.com/madst/archive/2007/05/11/recursive-lambda-expressions.aspx");
            m.Comments.AddDocs(
                XmlDocs.TypeParams(m.TypeParameters, t),
                XmlDocs.Param("lambda", "The " + XmlDocs.See(t) + " to use."),
                XmlDocs.Summary("Creates a " + XmlDocs.See(t) + " delegate, which may be recursive."),
                XmlDocs.Returns("Returns a " + XmlDocs.See(t) + " which (eventually) invokes <paramref name=\"lambda\"/>."),
                XmlDocs.ArgumentNullException("lambda"),
                XmlDocs.Remarks(
                    "<para>",
                    "  The following example makes use of a recursive lambda:",
                    "</para>",
                    "<code lang=\"C#\">",
                    "  Func<int, int> factorial = Lambda.RecFunc<int, int> (".Replace("<", "&lt;"),
                    "      fac => x => x == 0 ? 1 : x * fac (x-1));",
                    "  Console.WriteLine (factorial (5));  // prints \"120\"",
                    "</code>"
                    )
                );
            return(m);
        }
Esempio n. 4
0
        CodeTypeDeclaration CreateEither(int n)
        {
            var either = new CodeTypeDeclaration("Either")
            {
                TypeAttributes = TypeAttributes.Public | TypeAttributes.Abstract,
            };

            either.BaseTypes.Add(new CodeTypeReference("IEquatable", GetEitherType(n)));
            either.TypeParameters.AddRange(Types.GetTypeParameters(n, false));
            either.Members.Add(new CodeConstructor()
            {
                Attributes = MemberAttributes.Private,
            });
            for (int i = 0; i < n; ++i)
            {
                either.Members.Add(CreateCreator(either, i, n));
            }
            either.Members.Add(CreateFold(either, n));
            either.Members.Add(CreateCheckFolders(n));
            either.Members.Add(CreateEqualsObject());
            either.Members.Add(CreateEquals(n));
            either.Members.Add(CreateGetHashCode());
            for (int i = 0; i < n; ++i)
            {
                either.Members.Add(CreateHandler(i, n));
            }
            either.Comments.AddDocs(
                XmlDocs.TypeParams(either.TypeParameters),
                XmlDocs.Summary("A union of " + n + " values."),
                "<remarks>",
                "  <para>",
                "   An <c>Either</c> is an immutable, strongly typed union of variously ",
                "   typed values with each value lacking an otherwise meaningful name aside ",
                "   from its position, which is not exposed.  It stores only one (non-null) ",
                "   value from a set of types (as determined by the type parameter list).",
                "  </para>",
                "  <para>",
                "   The value held by a " + XmlDocs.See(DefaultNamespace, either) + " instance",
                "   can be converted into a value by using the ",
                "   <see cref=\"" + XmlDocs.Cref(DefaultNamespace, either, either.GetMethods("Fold").First()) + "\" /> method.",
                "   <c>Fold</c> takes a list of delegates to perform the conversion; the",
                "   delegate used to perform the conversion is based upon the internal ",
                "   position of the value stored.",
                "  </para>",
                "  <para>",
                "   <c>Either</c> instances are created through one of the following",
                "   creation methods:",
                "  </para>",
                "  <list type=\"bullet\">",
                GetCreators(either, n),
                "  </list>",
                "  <code lang=\"C#\">",
                "  var a = Either&lt;double, string&gt;.A (Math.PI);   // value stored in 1st position",
                "  ",
                "  int r = a.Fold (",
                "          v => (int) v,                                 // 1st position converter",
                "          v => v.Length);                               // 2nd position converter",
                "  ",
                "  Console.WriteLine (r);                        // prints 3</code>",
                "</remarks>"
                );
            for (int i = 0; i < n; ++i)
            {
                AddCreatorDocs(either, either.GetMethods(A(i)).First(), i, n);
            }
            AddFoldDocs(either, either.GetMethods("Fold").First(), n);
            AddEqualsObjectDocs(either,
                                either.GetMethods("Equals").First(m => m.Parameters [0].Type.BaseType == "System.Object"), n);
            AddEqualsDocs(either,
                          either.GetMethods("Equals").First(m => m.Parameters [0].Type.BaseType != "System.Object"), n);
            AddGetHashCodeDocs(either, either.GetMethods("GetHashCode").First(), n);
            return(either);
        }