예제 #1
0
        /// <summary>
        /// Transforms this temamplet.
        /// </summary>
        internal bool Transform()
        {
            try
            {
                if (Arguments == null || Arguments.Count == 0)
                {
                    Output = transformer.Transform(template);
                }
                else if (Arguments.Count == 1)
                {
                    TemplateArgument argument = Arguments.First();
                    Output = transformer.Transform(template, argument.Name, argument.Value);
                }
                else
                {
                    Output = transformer.Transform(template, Arguments);
                }

                RefreshDomainProperties();

                CompilerErrors = null;
                return(true);
            }
            catch (TextTransformationException ex)
            {
                CompilerErrors = ex.CompilationErrors;
                Output         = null;
                return(false);
            }
        }
        internal static void Transform(TextTransformerBase transformer)
        {
            //Prepare the argument that will be passes to the template
            var class1 = new ClassDefinition
            {
                Name      = "TestClass",
                Namespace = "TC.CustomTemplating.Example.Generated"
            };

            class1.Properties.Add(new Property("Name", typeof(string)));
            class1.Properties.Add(new Property("Lenght", typeof(int)));
            class1.Properties.Add(new Property("L", typeof(int)));

            //Get template from the embedded resources
            string template = TemplateResources.Get("TC.CustomTemplating.Example.Class.tt", typeof(ClassTemplate));

            //Allows us to show the compiled class
            transformer.ClassDefinitionGenerated += Host_ClassDefinitionGenerated;

            //start the tranformation
            var output = transformer.Transform(template, "Class", class1);

            Console.WriteLine("--BEGIN OUTPUT--");
            Console.WriteLine(output);
            Console.WriteLine("--END OUTPUT--");

            transformer.ClassDefinitionGenerated -= Host_ClassDefinitionGenerated;
        }
예제 #3
0
        internal static void Transform(TextTransformerBase transformer)
        {
            //Prepare the argument that will be passes to the template
            var class1 = new ClassDefinition
            {
                Name = "TestClass",
                Namespace = "TC.CustomTemplating.Example.Generated"
            };
            class1.Properties.Add(new Property("Name", typeof(string)));
            class1.Properties.Add(new Property("Lenght", typeof(int)));
            class1.Properties.Add(new Property("L", typeof(int)));

            //Get template from the embedded resources
            string template = TemplateResources.Get("TC.CustomTemplating.Example.Class.tt", typeof(ClassTemplate));

            //Allows us to show the compiled class
            transformer.ClassDefinitionGenerated += Host_ClassDefinitionGenerated;

            //start the tranformation
            var output = transformer.Transform(template, "Class", class1);

            Console.WriteLine("--BEGIN OUTPUT--");
            Console.WriteLine(output);
            Console.WriteLine("--END OUTPUT--");

            transformer.ClassDefinitionGenerated -= Host_ClassDefinitionGenerated;
        }