コード例 #1
0
        private static void WriteDesigner(this ProjectItem projectItem, CremaDataTable dataTable, bool isPublic)
        {
            var project          = projectItem.ContainingProject;
            var projectPath      = Path.GetDirectoryName(project.GetFullName());
            var designerFileName = Path.Combine(projectPath, projectItem.GetCustomToolOutput());
            var resxFileName     = projectItem.GetFullPath();
            var ss            = StringUtility.SplitPath(Path.GetDirectoryName(projectItem.GetLocalPath()));
            var codeNamespace = $"{project.GetRootNamespace()}.{string.Join(".", ss)}";
            var baseName      = Path.GetFileNameWithoutExtension(projectItem.GetLocalPath());

            using (var sw = new StreamWriter(designerFileName))
            {
                var errors   = null as string[];
                var provider = new CSharpCodeProvider();
                var code     = StronglyTypedResourceBuilder.Create(resxFileName, baseName, codeNamespace, provider, isPublic == false, out errors);
                if (errors.Length > 0)
                {
                    foreach (var error in errors)
                    {
                        Console.WriteLine(error);
                    }
                    return;
                }

                provider.GenerateCodeFromCompileUnit(code, sw, new CodeGeneratorOptions());
                Console.WriteLine(designerFileName);
            }
        }