Beispiel #1
0
        private void WriteCode()
        {
            // create writer
            var writer = new CodeWriter();

            // create generator
            var propertyGenerator = new CodeGenerator();
            var classGenerator    = new ClassGenerator();

            classGenerator.Init(buildArgs.type, propertyGenerator);
            propertyGenerator.Init(buildArgs);

            // generate code
            CodeGeneratorUtility.GenerateCode(classGenerator, writer);

            // generate output path
            string fileName = buildArgs.type.FullName;

            if (!string.IsNullOrEmpty(buildArgs.type.Namespace))
            {
                fileName = buildArgs.type.FullName.Substring(buildArgs.type.Namespace.Length + 1);
            }

            string outputPath = string.Format("{0}/{1}.Code.cs", settings.outputDirectory, fileName);

            Debug.LogFormat("Write code to \"{0}\"", outputPath);
            CodeGeneratorUtility.WriteCode(settings.templatePath, outputPath, writer);

            // save it
            lastOutputPath = outputPath;
        }
        public void GenerateCode()
        {
            if (buildArgs == null)
            {
                Debug.LogWarning("Type is not loaded");
                return;
            }

            // create writer
            var writer = new CodeWriter();

            // create generator
            var propertyGenerator = new CodeGenerator();
            var classGenerator    = new ClassGenerator();

            var outputType = typeof(ImplicitConverter);

            classGenerator.Init(outputType, propertyGenerator);
            propertyGenerator.Init(buildArgs);

            // generate code
            CodeGeneratorUtility.GenerateCode(classGenerator, writer);

            // generate output path
            string fileName = outputType.FullName;

            if (!string.IsNullOrEmpty(outputType.Namespace))
            {
                fileName = outputType.FullName.Substring(outputType.Namespace.Length + 1);
            }

            string outputPath = string.Format("{0}/{1}.Code.cs", settings.outputDirectory, fileName);

            Debug.LogFormat("Write code to \"{0}\"", outputPath);
            CodeGeneratorUtility.WriteCode(settings.templatePath, outputPath, writer);

            // save it
            lastOutputPath = outputPath;
        }