ManagementClass.GetStronglyTypedClassCode Method (Boolean, Boolean)


Generates a strongly-typed class for a given WMI class.

Namespace:   System.Management
Assembly:  System.Management (in System.Management.dll)

public CodeTypeDeclaration GetStronglyTypedClassCode(
	bool includeSystemClassInClassDef,
	bool systemPropertyClass


Type: System.Boolean

true to include the class for managing system properties; otherwise, false.

Type: System.Boolean

true to have the generated class manage system properties; otherwise, false.

Return Value

Type: System.CodeDom.CodeTypeDeclaration

A CodeTypeDeclaration representing the declaration for the strongly-typed class.

Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.

The following example generates a strongly-typed class for the Win32_LogicalDisk class. The generated code is produced in C# or Visual Basic .NET.

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
                new CodeNamespaceImport("System"));
                new CodeNamespaceImport("System.ComponentModel"));
                new CodeNamespaceImport("System.Management"));
                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
                cn, tw, new CodeGeneratorOptions());


.NET Framework
Available since 1.1
Return to top