protected override byte [] GenerateCode(string inputFileName, string inputFileContent) { ThreadHelper.ThrowIfNotOnUIThread( ); var fileBased = ProjectItem.Properties.Item("ItemType").Value?.ToString( ) != "EmbeddedResource"; var hasLinguist = Project.HasReference("Linguist"); var hasLinguistWPF = Project.HasReference("Linguist.WPF"); var hasLinguistXamarinForms = Project.HasReference("Linguist.Xamarin.Forms"); hasLinguist = hasLinguist || hasLinguistWPF || hasLinguistXamarinForms; var resourceSet = ResourceExtractor.ExtractResources(inputFileName, inputFileContent); var settings = new ResourceTypeSettings( ); var baseName = Path.GetFileNameWithoutExtension(inputFileName); var manifestPath = GetDefaultNamespace( ); var relativePath = Path.Combine(Project.Name, Path.Combine(manifestPath.Substring(Project.Name.Length).Split('.'))); settings.ClassName = baseName; settings.Namespace = FileNamespace ?? manifestPath; settings.AccessModifiers = AccessModifier; settings.CustomToolType = GetType( ); settings.Extension = hasLinguistWPF ? ResourceTypeExtension.WPF : hasLinguistXamarinForms ? ResourceTypeExtension.XamarinForms : ResourceTypeExtension.None; if (fileBased) { settings.ConfigureFileBasedResourceManager(baseName, Path.Combine(relativePath, Path.GetFileName(inputFileName))); } else if (hasLinguist) { settings.ConfigureResourceManager(manifestPath + '.' + baseName); } else { settings.ConfigureWithoutLocalizer(manifestPath + '.' + baseName); } var builder = new ResourceTypeBuilder(CodeDomProvider, resourceSet, settings); var code = builder.Build( ); var errors = builder.GetErrors( ); var source = new StringBuilder( ); var generator = new ExtendedCodeGenerator(CodeDomProvider); using (var writer = new StringWriter(source)) generator.GenerateCodeFromCompileUnit(code, writer, null); if (errors != null) { foreach (var error in errors) { GeneratorErrorCallback(error.IsWarning, default, error.ErrorText, error.Line, error.Column);
protected string GenerateCode(CodeDomProvider codeDomProvider, string rootNamespace, string inputFileName, IResource [] resourceSet, bool hasLinguist, bool hasLinguistWPF, bool hasLinguistXamarinForms, out string baseName, out string manifestPath) { var fileBased = false; hasLinguist = hasLinguist || hasLinguistWPF || hasLinguistXamarinForms; var settings = new ResourceTypeSettings( ); baseName = Path.GetFileNameWithoutExtension(inputFileName); var basePath = Path.GetDirectoryName(inputFileName).Replace('\\', '.').Replace('\\', '.'); manifestPath = rootNamespace; if (!string.IsNullOrEmpty(basePath)) { manifestPath += "." + basePath; } var relativePath = Path.Combine(rootNamespace, Path.Combine(manifestPath.Substring(rootNamespace.Length).Split('.'))); var accessModifier = System.CodeDom.MemberAttributes.Assembly | System.CodeDom.MemberAttributes.Static; settings.ClassName = baseName; settings.Namespace = manifestPath; settings.AccessModifiers = accessModifier; settings.CustomToolType = GetType( ); settings.Extension = hasLinguistWPF ? ResourceTypeExtension.WPF : hasLinguistXamarinForms ? ResourceTypeExtension.XamarinForms : ResourceTypeExtension.None; if (fileBased) { settings.ConfigureFileBasedResourceManager(baseName, Path.Combine(relativePath, Path.GetFileName(inputFileName))); } else if (hasLinguist) { settings.ConfigureResourceManager(manifestPath + '.' + baseName); } else { settings.ConfigureWithoutLocalizer(manifestPath + '.' + baseName); } var builder = new ResourceTypeBuilder(codeDomProvider, resourceSet, settings); var code = builder.Build( ); var errors = builder.GetErrors( ); var source = new StringBuilder( ); var generator = new ExtendedCodeGenerator(codeDomProvider); using (var writer = new StringWriter(source)) generator.GenerateCodeFromCompileUnit(code, writer, null); if (errors != null) { foreach (var error in errors) { if (error.IsWarning) { Log.LogWarning(error.ToString( )); } else { Log.LogError(error.ToString( )); } } } var output = Path.ChangeExtension(inputFileName, codeDomProvider.FileExtension); using (var stream = File.Open(output, FileMode.Create, FileAccess.Write)) using (var writer = new StreamWriter(stream, Encoding.UTF8)) generator.GenerateCodeFromCompileUnit(code, writer, null); return(output); }