public static void Write(this ProjectItem projectItem, CremaDataTable projectInfoTable) { if (FindTable(projectItem, projectInfoTable) is CremaDataTable dataTable) { var cultureInfo = projectItem.GetResourceCulture(); var valueName = cultureInfo == null ? "Value" : cultureInfo.Name.Replace('-', '_'); var path = projectItem.GetFullPath(); using (var writer = new ResXResourceWriter(path)) { foreach (var item in dataTable.Rows) { var name = $"{item["Type"]}" == "None" ? $"{item["Name"]}" : $"{item["Type"]}_{item["Name"]}"; var node = new ResXDataNode(name, item[valueName]) { Comment = $"{item["Comment"]}", }; writer.AddResource(node); } writer.Close(); } if (projectItem.GetCustomTool() == ResXFileCodeGenerator) { WriteDesigner(projectItem, dataTable, false); } else if (projectItem.GetCustomTool() == PublicResXFileCodeGenerator) { WriteDesigner(projectItem, dataTable, true); } } else { throw new Exception("항목을 찾을 수 없습니다."); } }
/// <summary> /// Returns new instance of ResXProjectItem using given project item /// </summary> /// <param name="item">Project item in Solution Explorer's file hierarchy</param> /// <param name="relationProject">Project used to created "referenced" relation</param> public static ResXProjectItem ConvertToResXItem(ProjectItem item, Project relationProject) { if (item == null) { throw new ArgumentNullException("item"); } if (relationProject == null) { throw new ArgumentNullException("relationProject"); } string projectPath = item.ContainingProject.FullName; if (string.IsNullOrEmpty(projectPath)) { return(new ResXProjectItem(item, item.Name, false)); } else { // create relative path from the project to the item Uri projectUri = new Uri(projectPath, UriKind.Absolute); Uri itemUri = new Uri(item.GetFullPath()); string displayName; if (item.ContainingProject.Kind.ToUpper() == StringConstants.WebSiteProject) { displayName = Uri.UnescapeDataString(projectUri.MakeRelativeUri(itemUri).ToString()); } else { displayName = item.ContainingProject.Name + "/" + Uri.UnescapeDataString(projectUri.MakeRelativeUri(itemUri).ToString()); } bool referenced = relationProject.UniqueName != item.ContainingProject.UniqueName; bool inter = item.GetCustomTool() != StringConstants.PublicResXTool; bool internalInReferenced = inter && referenced; return(new ResXProjectItem(item, displayName, internalInReferenced)); } }