public AssemblyType(Type type) { this.Type = type.FullName; this.Assembly = type.Assembly.FullName; ICodeModifier modifier = Activator.CreateInstance(type) as ICodeModifier; this.Any = modifier.XmlOptions; }
/// <summary> /// Generates the output. /// </summary> protected override string OnGenerateCode(string inputFileName, string inputFileContent) { #region load the configuration Configuration.Load(base.InputFilePath); StringBuilder output = new StringBuilder(); output.Append(CustomTool.GetToolGeneratedCodeWarning(typeof(XsdCodeGenerator))); #endregion #region read the schema(s) XmlSchema xsd; Directory.SetCurrentDirectory(Path.GetDirectoryName(base.InputFilePath)); using (FileStream fs = File.OpenRead(base.InputFilePath)) { xsd = XmlSchema.Read(fs, null); } #endregion #region create the class generator and set default options XsdClassGenerator xsdClassGenerator = new XsdClassGenerator(xsd); xsdClassGenerator.CodeGenerationOptions = CodeGenerationOptions.None; if (Configuration.Current.EnableDataBinding) { xsdClassGenerator.CodeGenerationOptions |= CodeGenerationOptions.EnableDataBinding; } if (Configuration.Current.GenerateOrder) { xsdClassGenerator.CodeGenerationOptions |= CodeGenerationOptions.GenerateOrder; } if (Configuration.Current.GenerateProperties) { xsdClassGenerator.CodeGenerationOptions |= CodeGenerationOptions.GenerateProperties; } xsdClassGenerator.CodeNamespaceString = base.FileNameSpace; xsdClassGenerator.CodeGeneratorOptions.GenerateCodeString = true; xsdClassGenerator.CodeGeneratorOptions.GenerateObjects = false; xsdClassGenerator.CodeGeneratorOptions.CompileAssembly = false; #endregion #region load the code modifiers foreach (AssemblyType assembly in Configuration.Current.CodeModifiers) { ObjectHandle handle = Activator.CreateInstance(assembly.Assembly, assembly.Type); if (handle == null) { output.AppendFormat("//\tWarning, could not create CodeModifier type {0} from assembly {0}", assembly.Type, assembly.Assembly); continue; } ICodeModifier modifier = handle.Unwrap() as ICodeModifier; if (modifier == null) { output.AppendFormat("//\tWarning CodeModifier {0} from assembly {0} does not derive from ICodeModifier", assembly.Type, assembly.Assembly); continue; } modifier.XmlOptions = assembly.Any; xsdClassGenerator.CodeModifiers.Add(modifier); } #endregion #region load the SchemaImporterExtensions foreach (AssemblyType assembly in Configuration.Current.SchemaImporterExtensions) { ObjectHandle handle = Activator.CreateInstance(assembly.Assembly, assembly.Type); if (handle == null) { output.AppendFormat("//\tWarning, could not create SchemaImporterExtensions type {0} from assembly {0}", assembly.Type, assembly.Assembly); continue; } SchemaImporterExtension extension = handle.Unwrap() as SchemaImporterExtension; if (extension == null) { output.AppendFormat("//\tWarning SchemaImporterExtensions {0} from assembly {0} does not derive from SchemaImporterExtension", assembly.Type, assembly.Assembly); continue; } xsdClassGenerator.SchemaImporterExtensions.Add(extension); } #endregion // generate code xsdClassGenerator.Compile(); // save config file and make sure it's added to the project Configuration.Save(base.InputFilePath); AddToProject(Configuration.GetConfigFileName(base.InputFilePath)); #region Workaround for known bug with fixed attributes: output.AppendLine(Resources.Message_1591); output.AppendLine(Resources.Pragma_1591_Disable); output.Append(xsdClassGenerator.CodeString); output.Append(Resources.Pragma_1591_Enable); #endregion return(output.ToString()); }