public void GenerateCode(FileProjectItem item, CustomToolContext context) { XmlDocument doc = new XmlDocument(); doc.Load(item.FileName); SettingsDocument setDoc = new SettingsDocument(doc.DocumentElement, DummySettingsEntryHost.Instance); string customToolNamespace = item.GetEvaluatedMetadata("CustomToolNamespace"); if (!string.IsNullOrEmpty(customToolNamespace)) { setDoc.GeneratedClassNamespace = customToolNamespace; } CodeCompileUnit ccu = new CodeCompileUnit(); var ns = ccu.AddNamespace(setDoc.GeneratedClassNamespace); ns.Types.Add(CreateClass(setDoc)); if (setDoc.UseMySettingsClassName) { ns.Types.Add(CreateMySettingsProperty(setDoc)); } context.WriteCodeDomToFile(item, context.GetOutputFileName(item, ".Designer"), ccu); }
public void GenerateCode(FileProjectItem item, CustomToolContext context) { /*context.GenerateCodeDomAsync(item, context.GetOutputFileName(item, ".Designer"), * delegate { * return GenerateCodeDom(); * });*/ string inputFilePath = item.FileName; // Ensure that the generated code will not conflict with an // existing class. if (context.Project != null) { IProjectContent pc = ParserService.GetProjectContent(context.Project); if (pc != null) { IClass existingClass = pc.GetClass(context.OutputNamespace + "." + StronglyTypedResourceBuilder.VerifyResourceName(Path.GetFileNameWithoutExtension(inputFilePath), pc.Language.CodeDomProvider), 0); if (existingClass != null) { if (!IsGeneratedResourceClass(existingClass)) { context.MessageView.AppendLine(String.Format(System.Globalization.CultureInfo.CurrentCulture, ResourceService.GetString("ResourceEditor.ResourceCodeGeneratorTool.ClassConflict"), inputFilePath, existingClass.FullyQualifiedName)); return; } } } } IResourceReader reader; if (string.Equals(Path.GetExtension(inputFilePath), ".resx", StringComparison.OrdinalIgnoreCase)) { reader = new ResXResourceReader(inputFilePath); ((ResXResourceReader)reader).BasePath = Path.GetDirectoryName(inputFilePath); } else { reader = new ResourceReader(inputFilePath); } Hashtable resources = new Hashtable(); foreach (DictionaryEntry de in reader) { resources.Add(de.Key, de.Value); } string[] unmatchable = null; context.WriteCodeDomToFile( item, context.GetOutputFileName(item, ".Designer"), StronglyTypedResourceBuilder.Create( resources, // resourceList Path.GetFileNameWithoutExtension(inputFilePath), // baseName context.OutputNamespace, // generatedCodeNamespace context.OutputNamespace, // resourcesNamespace context.Project.LanguageProperties.CodeDomProvider, // codeProvider createInternalClass, // internal class out unmatchable )); foreach (string s in unmatchable) { context.MessageView.AppendLine(String.Format(System.Globalization.CultureInfo.CurrentCulture, ResourceService.GetString("ResourceEditor.ResourceCodeGeneratorTool.CouldNotGenerateResourceProperty"), s)); } }