Esempio n. 1
0
        public static void AddTestExpr(this MetadataContext cx, Expression expr, params ParameterExpression[] parameters)
        {
            var typeCount = cx.DefinedTypes.Count;
            var name      = typeCount < 15 ? ((char)('C' + typeCount)).ToString() : "C" + typeCount;
            var ns        = ((TypeOrNamespace.NamespaceSignatureCase)cx.DefinedTypes.FirstOrDefault()?.Signature.Parent)?.Item ??
                            new NamespaceSignature("NS", NamespaceSignature.Global);
            var type      = TypeSignature.Class(name, ns, Accessibility.APublic);
            var method    = new MethodSignature(type, parameters.Select(p => new MethodParameter(p.Type, p.Name)).ToImmutableArray(), "M", expr.Type(), true, Accessibility.APublic, false, false, false, false, ImmutableArray <GenericParameter> .Empty);
            var methodDef = new MethodDef(method, parameters.ToImmutableArray(), expr);
            var typeDef   = TypeDef.Empty(type).With(members: ImmutableArray.Create <MemberDef>(methodDef));

            cx.AddType(typeDef);
            cx.CommitWaitingTypes();
        }