コード例 #1
0
        public void Test()
        {
            var mgi = new ModelsGeneratorInput()
            {
                ClassName = "RuntimeGeneratedModel",
                //Convert to Param.
                Params = Params.ToParam().ToList()
            };

            var modelGenerator = new ModelsGenerator(
                //Can build one or more models with one ModelsGenerator with common SourceFileContext.
                new ModelsGeneratorInput[] { mgi },
                namespaceStr: "MyGeneratedNamespace",
                baseClassName: typeof(IRuntimeGeneratedModel).FullName
                );
            var codeGenResult = modelGenerator.Generate();

            //Register used type.
            codeGenResult.Context.UsedType(typeof(IRuntimeGeneratedModel));

            var asm            = codeGenResult.Compile();
            var generatedType  = asm.GetType("MyGeneratedNamespace.RuntimeGeneratedModel");
            var generatedModel = (IRuntimeGeneratedModel)Activator.CreateInstance(generatedType);

            generatedModel.Num1 = 1;
            generatedModel.Num2 = 2;
            generatedModel.Num3 = 3;
            var res = MethodToInvoke(
                generatedModel.Num1,
                generatedModel.Num2,
                generatedModel.Num3
                );

            Assert.AreEqual(6, res);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder();

            builder.AddUserSecrets <Program>();
            var configuration = builder.Build();
            var root          = configuration["root"];

            var asmNames = new string[]
            {
                "QiaoDan.Core.dll",
                "QiaoDan.ViewModels.Abstractions.dll",
                "QiaoDan.Admin.ViewModels.dll",
                "QiaoDan.OA.Core.dll",
                "QiaoDan.OA.ViewModels.dll",
                "QiaoDan.HR.Core.dll",
                "QiaoDan.HR.ViewModels.dll",
            }
            ;

            ModelsGenerator.Generate(
                asmNames.Select(n => Assembly.LoadFrom(Path.Combine(root, n))).Append(typeof(Program).Assembly),
                "../ts.g",
                opt =>
            {
                opt.TypeFilter     = t => t.GetInterface("IViewModel") != null || t.IsEnum || (t.IsAbstract && t.IsSealed);
                opt.PropertyFilter = p => !p.GetCustomAttributes().Any(a => a.GetType().Name == "JsonIgnoreAttribute");
                opt.CodeSnippets   = t =>
                {
                    if (t.GetCustomAttributes().Any(a => a.GetType().Name == "DynamicValidateAttribute"))
                    {
                        return(@$ "static _assemblyName = " "{t.Assembly.GetName().Name}" ";
                                      static _className = " "{t.FullName}" ";");
コード例 #3
0
ファイル: Program.cs プロジェクト: MEOFIXBUG/micro-ORMv2
        static void Main(string[] args)
        {
            var readerParameters = new ReaderParameters();
            var result           = readerParameters.ParseArguments(args);

            switch (result)
            {
            case ParserResult.Invalid:
                Console.Write(readerParameters.Usage);
                break;

            case ParserResult.Failure:
                Console.Write(readerParameters.ErrorMessage);
                break;

            case ParserResult.Success:
                try
                {
                    ModelsGenerator.Generate(readerParameters);
                    Console.WriteLine("Completed successfully.");
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                    Console.WriteLine(exception.StackTrace);
                }

                break;
            }

            Console.ReadKey();
        }