/// <summary> /// <para>Generates a strongly-typed class for a given WMI class. This function generates code for Visual Basic, /// C#, or JScript, depending on the input parameters.</para> /// </summary> /// <param name='lang'>The language of the code to be generated.</param> /// <param name='filePath'>The path of the file where the code is to be written.</param> /// <param name='classNamespace'>The .NET namespace into which the class should be generated. If this is empty, the namespace will be generated from the WMI namespace.</param> /// <returns> /// <para><see langword='true'/>, if the method succeeded; /// otherwise, <see langword='false'/> .</para> /// </returns> /// <example> /// <code lang='C#'>using System; /// using System.Management; /// /// ManagementClass cls = new ManagementClass(null,"Win32_LogicalDisk",null,""); /// cls.GetStronglyTypedClassCode(CodeLanguage.CSharp,"C:\temp\Logicaldisk.cs",String.Empty); /// </code> /// </example> public bool GetStronglyTypedClassCode(CodeLanguage lang, String filePath,String classNamespace) { // Ensure that the object is valid Get(); ManagementClassGenerator classGen = new ManagementClassGenerator(this); return classGen.GenerateCode(lang , filePath,classNamespace); }
public bool GetStronglyTypedClassCode(CodeLanguage lang, string filePath, string classNamespace) { base.Get(); ManagementClassGenerator generator = new ManagementClassGenerator(this); return generator.GenerateCode(lang, filePath, classNamespace); }
/// <overload> /// <para>Generates a strongly-typed class for a given WMI class.</para> /// </overload> /// <summary> /// <para>Generates a strongly-typed class for a given WMI class.</para> /// </summary> /// <param name='includeSystemClassInClassDef'><see langword='true'/> if the class for managing system properties must be included; otherwise, <see langword='false'/>.</param> /// <param name='systemPropertyClass'><see langword='true'/> if the generated class will manage system properties; otherwise, <see langword='false'/>.</param> /// <returns> /// <para>A <see cref='System.CodeDom.CodeTypeDeclaration'/> instance /// representing the declaration for the strongly-typed class.</para> /// </returns> /// <example> /// <code lang='C#'>using System; /// using System.Management; /// using System.CodeDom; /// using System.IO; /// using System.CodeDom.Compiler; /// using Microsoft.CSharp; /// /// void GenerateCSharpCode() /// { /// string strFilePath = "C:\\temp\\LogicalDisk.cs"; /// CodeTypeDeclaration ClsDom; /// /// ManagementClass cls1 = new ManagementClass(null,"Win32_LogicalDisk",null); /// ClsDom = cls1.GetStronglyTypedClassCode(false,false); /// /// ICodeGenerator cg = (new CSharpCodeProvider()).CreateGenerator (); /// CodeNamespace cn = new CodeNamespace("TestNamespace"); /// /// // Add any imports to the code /// cn.Imports.Add (new CodeNamespaceImport("System")); /// cn.Imports.Add (new CodeNamespaceImport("System.ComponentModel")); /// cn.Imports.Add (new CodeNamespaceImport("System.Management")); /// cn.Imports.Add(new CodeNamespaceImport("System.Collections")); /// /// // Add class to the namespace /// cn.Types.Add (ClsDom); /// /// //Now create the filestream (output file) /// TextWriter tw = new StreamWriter(new /// FileStream (strFilePath,FileMode.Create)); /// /// // And write it to the file /// cg.GenerateCodeFromNamespace (cn, tw, new CodeGeneratorOptions()); /// /// tw.Close(); /// } /// </code> /// </example> public CodeTypeDeclaration GetStronglyTypedClassCode(bool includeSystemClassInClassDef, bool systemPropertyClass) { // Ensure that the object is valid Get(); ManagementClassGenerator classGen = new ManagementClassGenerator(this); return classGen.GenerateCode(includeSystemClassInClassDef,systemPropertyClass); }
public CodeTypeDeclaration GetStronglyTypedClassCode(bool includeSystemClassInClassDef, bool systemPropertyClass) { base.Get(); ManagementClassGenerator generator = new ManagementClassGenerator(this); return generator.GenerateCode(includeSystemClassInClassDef, systemPropertyClass); }