CodeCommentStatementとは? わかりやすく解説

CodeCommentStatement クラス

単一コメントから成るステートメント表します

名前空間: System.CodeDom
アセンブリ: System (system.dll 内)
構文構文

<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class CodeCommentStatement
    Inherits CodeStatement
Dim instance As CodeCommentStatement
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class CodeCommentStatement : CodeStatement
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class CodeCommentStatement : public
 CodeStatement
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class CodeCommentStatement extends CodeStatement
SerializableAttribute 
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class CodeCommentStatement extends
 CodeStatement
解説解説

CodeCommentStatement使用して単一行のコメント ステートメントを表すことができますCodeCommentStatementステートメントのため、ステートメント コレクション挿入でき、単独の行として表示されます。また、CodeCommentStatement は、CodeNamespace のコメント コレクションや、CodeTypeMember から派生する任意のオブジェクト追加することもできます

使用例使用例

CodeCommentStatement使用してソース コード内のコメントを表す例を次に示します

' Create a CodeComment with some example comment text.
Dim comment As New CodeComment(
 _
   "This comment was generated from a System.CodeDom.CodeComment",
 _
   False) ' Whether the comment is a documentation
 comment.

' Create a CodeCommentStatement that contains the comment, in order
' to add the comment to a CodeTypeDeclaration Members collection.
Dim commentStatement As New
 CodeCommentStatement(comment)    

' A Visual Basic code generator produces the following source code for
 the preceeding example code:
    
' 'This comment was generated from a System.CodeDom.CodeComment
// Create a CodeComment with some example comment text.
CodeComment comment = new CodeComment(
    // The text of the comment.
    "This comment was generated from a System.CodeDom.CodeComment",
    // Whether the comment is a comment intended for documentation purposes.
    false );

// Create a CodeCommentStatement that contains the comment, in order
// to add the comment to a CodeTypeDeclaration Members collection.
CodeCommentStatement commentStatement = new CodeCommentStatement(
 comment );

// A C# code generator produces the following source code for the preceeding
 example code:

// // This comment was generated from a System.CodeDom.CodeComment
// Create a CodeComment with some example comment text.

// The text of the comment.
// Whether the comment is a comment intended for documentation purposes.
CodeComment^ comment = gcnew CodeComment( "This comment was generated from a
 System.CodeDom.CodeComment",false );

// Create a CodeCommentStatement that contains the comment, in order
// to add the comment to a CodeTypeDeclaration Members collection.
CodeCommentStatement^ commentStatement = gcnew CodeCommentStatement( comment );

// A C# code generator produces the following source code for the preceeding
 example code:
// // This comment was generated from a System.CodeDom.CodeComment
// Create a CodeComment with some example comment text.
CodeComment comment = new CodeComment("This comment was generated
 "
    + "from a System.CodeDom.CodeComment", false);
// The text of the comment.
// Whether the comment is a comment intended for documentation purposes.
// Create a CodeCommentStatement that contains the comment, in order
// to add the comment to a CodeTypeDeclaration Members collection.
CodeCommentStatement commentStatement = new 
    CodeCommentStatement(comment);
// A VJ# code generator produces the following source code for the 
// preceeding example code:
// This comment was generated from a System.CodeDom.CodeComment
継承階層継承階層
System.Object
   System.CodeDom.CodeObject
     System.CodeDom.CodeStatement
      System.CodeDom.CodeCommentStatement
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

CodeCommentStatement コンストラクタ ()


CodeCommentStatement コンストラクタ (String, Boolean)

テキストドキュメント コメント フラグ指定して、CodeCommentStatement クラス新しインスタンス初期化します。

名前空間: System.CodeDom
アセンブリ: System (system.dll 内)
構文構文

Public Sub New ( _
    text As String, _
    docComment As Boolean _
)
Dim text As String
Dim docComment As Boolean

Dim instance As New CodeCommentStatement(text,
 docComment)
public CodeCommentStatement (
    string text,
    bool docComment
)
public:
CodeCommentStatement (
    String^ text, 
    bool docComment
)
public CodeCommentStatement (
    String text, 
    boolean docComment
)
public function CodeCommentStatement (
    text : String, 
    docComment : boolean
)

パラメータ

text

コメント内容

docComment

コメントドキュメント コメント場合trueそれ以外場合false

解説解説
使用例使用例

CodeCommentStatement(String,Boolean) コンストラクタ使用してXML コメント フィールドとして使用するコメント ステートメント作成する方法次のコード例示します。この例は、後に示す例の一部です。

' Declare a new code entry point method.
Dim start As New CodeEntryPointMethod()
start.Comments.Add(New CodeCommentStatement("<summary>",
 True))
start.Comments.Add(New CodeCommentStatement("Main
 method for HelloWorld application.", True))
start.Comments.Add(New CodeCommentStatement("<para>Add
 a new paragraph to the description.</para>", True))
start.Comments.Add(New CodeCommentStatement("</summary>",
 True))
// Declare a new code entry point method.
CodeEntryPointMethod start = new CodeEntryPointMethod();
start.Comments.Add(new CodeCommentStatement("<summary>",
 true));
start.Comments.Add(new CodeCommentStatement("Main method
 for HelloWorld application.", true));
start.Comments.Add(new CodeCommentStatement(@"<para>Add
 a new paragraph to the description.</para>", true));
start.Comments.Add(new CodeCommentStatement("</summary>",
 true));

簡単な "Hello World" コンソール アプリケーション作成しコンパイル済みアプリケーションXML ドキュメント ファイル生成する方法次のコード例示します

Imports System
Imports System.CodeDom
Imports System.CodeDom.Compiler
Imports System.IO
Imports System.Text.RegularExpressions



Class Program
    Private Shared providerName As
 String = "vb"
    Private Shared sourceFileName As
 String = "test.vb"

    Shared Sub Main(ByVal
 args() As String)
        Dim provider As CodeDomProvider = CodeDomProvider.CreateProvider(providerName)

        LogMessage("Building CodeDOM graph...")

        Dim cu As New CodeCompileUnit()

        cu = BuildHelloWorldGraph()

        Dim sw As New StringWriter()

        LogMessage("Generating code...")
        provider.GenerateCodeFromCompileUnit(cu, sw, Nothing)

        Dim output As String
 = sw.ToString()
        output = Regex.Replace(output, "Runtime Version:[^"
 + vbCr + vbLf + "]*", "Runtime
 Version omitted for demo")

        LogMessage("Dumping source...")
        LogMessage(output)

        LogMessage("Writing source to file...")
        Dim s As Stream = File.Open(sourceFileName,
 FileMode.Create)
        Dim t As New StreamWriter(s)
        t.Write(output)
        t.Close()
        s.Close()

        Dim opt As New CompilerParameters(New
 String() {"System.dll"})
        opt.GenerateExecutable = True
        opt.OutputAssembly = "HelloWorld.exe"
        opt.TreatWarningsAsErrors = True
        opt.IncludeDebugInformation = True
        opt.GenerateInMemory = True
        opt.CompilerOptions = "/doc"

        Dim results As CompilerResults

        LogMessage(("Compiling with " + providerName))
        results = provider.CompileAssemblyFromFile(opt, sourceFileName)

        OutputResults(results)
        If results.NativeCompilerReturnValue <> 0 Then
            LogMessage("")
            LogMessage("Compilation failed.")
        Else
            LogMessage("")
            LogMessage("Demo completed successfully.")
        End If
        File.Delete(sourceFileName)

    End Sub 'Main


    ' Build a Hello World program graph using 
    ' System.CodeDom types.
    Public Shared Function
 BuildHelloWorldGraph() As CodeCompileUnit
        ' Create a new CodeCompileUnit to contain 
        ' the program graph.
        Dim compileUnit As New
 CodeCompileUnit()

        ' Declare a new namespace called Samples.
        Dim samples As New
 CodeNamespace("Samples")
        ' Add the new namespace to the compile unit.
        compileUnit.Namespaces.Add(samples)

        ' Add the new namespace import for the System namespace.
        samples.Imports.Add(New CodeNamespaceImport("System"))

        ' Declare a new type called Class1.
        Dim class1 As New
 CodeTypeDeclaration("Class1")

        class1.Comments.Add(New CodeCommentStatement("<summary>",
 True))
        class1.Comments.Add(New CodeCommentStatement("Create
 a Hello World application.", True))
        class1.Comments.Add(New CodeCommentStatement("<seealso
 cref=" + ControlChars.Quote + "Class1.Main"
 + ControlChars.Quote + "/>", True))
        class1.Comments.Add(New CodeCommentStatement("</summary>",
 True))

        ' Add the new type to the namespace type collection.
        samples.Types.Add(class1)

        ' Declare a new code entry point method.
        Dim start As New
 CodeEntryPointMethod()
        start.Comments.Add(New CodeCommentStatement("<summary>",
 True))
        start.Comments.Add(New CodeCommentStatement("Main
 method for HelloWorld application.", True))
        start.Comments.Add(New CodeCommentStatement("<para>Add
 a new paragraph to the description.</para>", True))
        start.Comments.Add(New CodeCommentStatement("</summary>",
 True))
        ' Create a type reference for the System.Console class.
        Dim csSystemConsoleType As New
 CodeTypeReferenceExpression("System.Console")

        ' Build a Console.WriteLine statement.
        Dim cs1 As New CodeMethodInvokeExpression(csSystemConsoleType,
 "WriteLine", New CodePrimitiveExpression("Hello
 World!"))

        ' Add the WriteLine call to the statement collection.
        start.Statements.Add(cs1)

        ' Build another Console.WriteLine statement.
        Dim cs2 As New CodeMethodInvokeExpression(csSystemConsoleType,
 "WriteLine", New CodePrimitiveExpression("Press
 the Enter key to continue."))

        ' Add the WriteLine call to the statement collection.
        start.Statements.Add(cs2)

        ' Build a call to System.Console.ReadLine.
        Dim csReadLine As New
 CodeMethodInvokeExpression(csSystemConsoleType, "ReadLine")

        ' Add the ReadLine statement.
        start.Statements.Add(csReadLine)

        ' Add the code entry point method to
        ' the Members collection of the type.
        class1.Members.Add(start)

        Return compileUnit

    End Function 'BuildHelloWorldGraph

    Shared Sub LogMessage(ByVal
 [text] As String)
        Console.WriteLine([text])

    End Sub 'LogMessage


    Shared Sub OutputResults(ByVal
 results As CompilerResults)
        LogMessage(("NativeCompilerReturnValue=" +
 results.NativeCompilerReturnValue.ToString()))
        Dim s As String
        For Each s In results.Output
            LogMessage(s)
        Next s

    End Sub 'OutputResults
End Class 'Program
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.IO;
using System.Text.RegularExpressions;

namespace BasicCodeDomApp
{
    class Program
    {
        static string providerName = "cs";
        static string sourceFileName = "test.cs";
        static void Main(string[]
 args)
        {
            CodeDomProvider provider = CodeDomProvider.CreateProvider(providerName);

            LogMessage("Building CodeDOM graph...");

            CodeCompileUnit cu = new CodeCompileUnit();

            cu = BuildHelloWorldGraph();

            StringWriter sw = new StringWriter();

            LogMessage("Generating code...");
            provider.GenerateCodeFromCompileUnit(cu, sw, null);

            string output = sw.ToString();
            output = Regex.Replace(output, "Runtime Version:[^\r\n]*",
                "Runtime Version omitted for demo");

            LogMessage("Dumping source...");
            LogMessage(output);

            LogMessage("Writing source to file...");
            Stream s = File.Open(sourceFileName, FileMode.Create);
            StreamWriter t = new StreamWriter(s);
            t.Write(output);
            t.Close();
            s.Close();

            CompilerParameters opt = new CompilerParameters(new
 string[]{
                                      "System.dll" });
            opt.GenerateExecutable = true;
            opt.OutputAssembly = "HelloWorld.exe";
            opt.TreatWarningsAsErrors = true;
            opt.IncludeDebugInformation = true;
            opt.GenerateInMemory = true;
            opt.CompilerOptions = "/doc:HelloWorldDoc.xml";

            CompilerResults results;

            LogMessage("Compiling with " + providerName);
            results = provider.CompileAssemblyFromFile(opt, sourceFileName);

            OutputResults(results);
            if (results.NativeCompilerReturnValue != 0)
            {
                LogMessage("");
                LogMessage("Compilation failed.");
            }
            else
            {
                LogMessage("");
                LogMessage("Demo completed successfully.");
            }
            File.Delete(sourceFileName);
        }

        // Build a Hello World program graph using 
        // System.CodeDom types.
        public static CodeCompileUnit BuildHelloWorldGraph()
        {
            // Create a new CodeCompileUnit to contain 
            // the program graph.
            CodeCompileUnit compileUnit = new CodeCompileUnit();

            // Declare a new namespace called Samples.
            CodeNamespace samples = new CodeNamespace("Samples");
            // Add the new namespace to the compile unit.
            compileUnit.Namespaces.Add(samples);

            // Add the new namespace import for the System namespace.
            samples.Imports.Add(new CodeNamespaceImport("System"));

            // Declare a new type called Class1.
            CodeTypeDeclaration class1 = new CodeTypeDeclaration("Class1");

            class1.Comments.Add(new CodeCommentStatement("<summary>",
 true));
            class1.Comments.Add(new CodeCommentStatement("Create
 a Hello World application.", true));
            class1.Comments.Add(new CodeCommentStatement(@"<seealso
 cref=" + '"' + "Class1.Main" + '"' + "/>",
 true));
            class1.Comments.Add(new CodeCommentStatement("</summary>",
 true));

            // Add the new type to the namespace type collection.
            samples.Types.Add(class1);

            // Declare a new code entry point method.
            CodeEntryPointMethod start = new CodeEntryPointMethod();
            start.Comments.Add(new CodeCommentStatement("<summary>",
 true));
            start.Comments.Add(new CodeCommentStatement("Main method
 for HelloWorld application.", true));
            start.Comments.Add(new CodeCommentStatement(@"<para>Add
 a new paragraph to the description.</para>", true));
            start.Comments.Add(new CodeCommentStatement("</summary>",
 true));

            // Create a type reference for the System.Console class.
            CodeTypeReferenceExpression csSystemConsoleType = new
 CodeTypeReferenceExpression("System.Console");

            // Build a Console.WriteLine statement.
            CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression(
                csSystemConsoleType, "WriteLine",
                new CodePrimitiveExpression("Hello World!"));

            // Add the WriteLine call to the statement collection.
            start.Statements.Add(cs1);

            // Build another Console.WriteLine statement.
            CodeMethodInvokeExpression cs2 = new CodeMethodInvokeExpression(
                csSystemConsoleType, "WriteLine",
                new CodePrimitiveExpression("Press the Enter
 key to continue."));

            // Add the WriteLine call to the statement collection.
            start.Statements.Add(cs2);

            // Build a call to System.Console.ReadLine.
            CodeMethodInvokeExpression csReadLine = new CodeMethodInvokeExpression(
                csSystemConsoleType, "ReadLine");

            // Add the ReadLine statement.
            start.Statements.Add(csReadLine);

            // Add the code entry point method to
            // the Members collection of the type.
            class1.Members.Add(start);

            return compileUnit;
        }
        static void LogMessage(string
 text)
        {
            Console.WriteLine(text);
        }

        static void OutputResults(CompilerResults
 results)
        {
            LogMessage("NativeCompilerReturnValue=" +
                results.NativeCompilerReturnValue.ToString());
            foreach (string s in
 results.Output)
            {
                LogMessage(s);
            }
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
CodeCommentStatement クラス
CodeCommentStatement メンバ
System.CodeDom 名前空間

CodeCommentStatement コンストラクタ (CodeComment)


CodeCommentStatement コンストラクタ (String)


CodeCommentStatement コンストラクタ

CodeCommentStatement クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
CodeCommentStatement () CodeCommentStatement クラス新しインスタンス初期化します。
CodeCommentStatement (CodeComment) コメント指定してCodeCommentStatement クラス新しインスタンス初期化します。
CodeCommentStatement (String) 内容としてテキスト指定してCodeCommentStatement クラス新しインスタンス初期化します。
CodeCommentStatement (String, Boolean) テキストドキュメント コメント フラグ指定してCodeCommentStatement クラス新しインスタンス初期化します。
参照参照

関連項目

CodeCommentStatement クラス
CodeCommentStatement メンバ
System.CodeDom 名前空間

CodeCommentStatement プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Comment コメント内容取得または設定します
パブリック プロパティ EndDirectives  終了ディレクティブを含む CodeDirectiveCollection オブジェクト取得します。 ( CodeStatement から継承されます。)
パブリック プロパティ LinePragma  コード ステートメントのある行を取得または設定します。 ( CodeStatement から継承されます。)
パブリック プロパティ StartDirectives  開始ディレクティブを含む CodeDirectiveCollection オブジェクト取得します。 ( CodeStatement から継承されます。)
パブリック プロパティ UserData  現在のオブジェクトユーザー定義可能なデータ取得または設定します。 ( CodeObject から継承されます。)
参照参照

関連項目

CodeCommentStatement クラス
System.CodeDom 名前空間
CodeComment クラス

CodeCommentStatement メソッド


CodeCommentStatement メンバ

単一コメントから成るステートメント表します

CodeCommentStatement データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド CodeCommentStatement オーバーロードされます。 CodeCommentStatement クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Comment コメント内容取得または設定します
パブリック プロパティ EndDirectives  終了ディレクティブを含む CodeDirectiveCollection オブジェクト取得します。(CodeStatement から継承されます。)
パブリック プロパティ LinePragma  コード ステートメントのある行を取得または設定します。 (CodeStatement から継承されます。)
パブリック プロパティ StartDirectives  開始ディレクティブを含む CodeDirectiveCollection オブジェクト取得します。(CodeStatement から継承されます。)
パブリック プロパティ UserData  現在のオブジェクトユーザー定義可能なデータ取得または設定します。(CodeObject から継承されます。)
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

CodeCommentStatement クラス
System.CodeDom 名前空間
CodeComment クラス


このページでは「.NET Framework クラス ライブラリ リファレンス」からCodeCommentStatementを検索した結果を表示しています。
Weblioに収録されているすべての辞書からCodeCommentStatementを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からCodeCommentStatement を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「CodeCommentStatement」の関連用語

CodeCommentStatementのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



CodeCommentStatementのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS