本文整理汇总了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);
}
}
}