本文整理匯總了C#中System.Management.ManagementClass.GetStronglyTypedClassCode方法的典型用法代碼示例。如果您正苦於以下問題:C# ManagementClass.GetStronglyTypedClassCode方法的具體用法?C# ManagementClass.GetStronglyTypedClassCode怎麽用?C# ManagementClass.GetStronglyTypedClassCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了ManagementClass.GetStronglyTypedClassCode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using System;
using System.Management;
using System.CodeDom;
using System.IO;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
namespace ManagementSample
{
class GenerateCSharpCode
{
static void Main(string[] args)
{
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();
}
}
}
示例2: Main
//引入命名空間
using System;
using System.Management;
using System.CodeDom;
using System.IO;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
namespace ManagementSample
{
class GenerateCSharpCode
{
static void Main(string[] args)
{
ManagementClass cls1 = new ManagementClass(
null, "Win32_LogicalDisk",null);
cls1.GetStronglyTypedClassCode(
CodeLanguage.CSharp,
"C:\\temp\\Logicaldisk.cs",
String.Empty);
}
}
}