Поделиться через


CodeParameterDeclarationExpression Класс

Определение

Представляет объявление параметров для метода, свойства или конструктора.

public ref class CodeParameterDeclarationExpression : System::CodeDom::CodeExpression
public class CodeParameterDeclarationExpression : System.CodeDom.CodeExpression
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeParameterDeclarationExpression : System.CodeDom.CodeExpression
type CodeParameterDeclarationExpression = class
    inherit CodeExpression
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeParameterDeclarationExpression = class
    inherit CodeExpression
Public Class CodeParameterDeclarationExpression
Inherits CodeExpression
Наследование
CodeParameterDeclarationExpression
Атрибуты

Примеры

В следующем примере показано использование CodeParameterDeclarationExpression для объявления параметров метода с помощью разных FieldDirection описателей ссылочного типа поля.

// Declares a method.
CodeMemberMethod method1 = new CodeMemberMethod();
method1.Name = "TestMethod";

// Declares a string parameter passed by reference.
CodeParameterDeclarationExpression param1 = new CodeParameterDeclarationExpression("System.String", "stringParam");
param1.Direction = FieldDirection.Ref;
method1.Parameters.Add(param1);

// Declares a Int32 parameter passed by incoming field.
CodeParameterDeclarationExpression param2 = new CodeParameterDeclarationExpression("System.Int32", "intParam");
param2.Direction = FieldDirection.Out;
method1.Parameters.Add(param2);

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

//        private void TestMethod(ref string stringParam, out int intParam) {
//        }
           ' Declares a method.
           Dim method1 As New CodeMemberMethod()
           method1.Name = "TestMethod"

           ' Declares a string parameter passed by reference.
           Dim param1 As New CodeParameterDeclarationExpression("System.String", "stringParam")
           param1.Direction = FieldDirection.Ref
           method1.Parameters.Add(param1)

           ' Declares a Int32 parameter passed by incoming field.
           Dim param2 As New CodeParameterDeclarationExpression("System.Int32", "intParam")
           param2.Direction = FieldDirection.Out
           method1.Parameters.Add(param2)

           ' A Visual Basic code generator produces the following source code for the preceeding example code:

           '	 Private Sub TestMethod(ByRef stringParam As String, ByRef intParam As Integer)
           '    End Sub

Комментарии

CodeParameterDeclarationExpression можно использовать для представления кода, объявляющего параметр для метода, свойства или конструктора.

Свойство Name задает имя параметра. Свойство Type задает тип данных параметра. Свойство Direction задает модификатор направления параметра. Свойство CustomAttributes задает атрибуты, связанные с параметром.

Конструкторы

Имя Описание
CodeParameterDeclarationExpression()

Инициализирует новый экземпляр класса CodeParameterDeclarationExpression.

CodeParameterDeclarationExpression(CodeTypeReference, String)

Инициализирует новый экземпляр класса с помощью указанного CodeParameterDeclarationExpression типа параметра и имени.

CodeParameterDeclarationExpression(String, String)

Инициализирует новый экземпляр класса с помощью указанного CodeParameterDeclarationExpression типа параметра и имени.

CodeParameterDeclarationExpression(Type, String)

Инициализирует новый экземпляр класса с помощью указанного CodeParameterDeclarationExpression типа параметра и имени.

Свойства

Имя Описание
CustomAttributes

Возвращает или задает настраиваемые атрибуты для объявления параметров.

Direction

Возвращает или задает направление поля.

Name

Возвращает или задает имя параметра.

Type

Возвращает или задает тип параметра.

UserData

Возвращает определяемые пользователем данные для текущего объекта.

(Унаследовано от CodeObject)

Методы

Имя Описание
Equals(Object)

Определяет, равен ли указанный объект текущему объекту.

(Унаследовано от Object)
GetHashCode()

Служит хэш-функцией по умолчанию.

(Унаследовано от Object)
GetType()

Возвращает Type текущего экземпляра.

(Унаследовано от Object)
MemberwiseClone()

Создает неглубокую копию текущей Object.

(Унаследовано от Object)
ToString()

Возвращает строку, представляющую текущий объект.

(Унаследовано от Object)

Применяется к

См. также раздел