Rediger

Del via


ElementInit Class

Definition

Represents an initializer for a single element of an IEnumerable collection.

public ref class ElementInit sealed : System::Linq::Expressions::IArgumentProvider
public ref class ElementInit sealed
public sealed class ElementInit : System.Linq.Expressions.IArgumentProvider
public sealed class ElementInit
type ElementInit = class
    interface IArgumentProvider
type ElementInit = class
Public NotInheritable Class ElementInit
Implements IArgumentProvider
Public NotInheritable Class ElementInit
Inheritance
ElementInit
Implements

Examples

The following example creates an ElementInit that represents the initialization of an element of a dictionary collection.

string tree = "maple";

System.Reflection.MethodInfo addMethod = typeof(Dictionary<int, string>).GetMethod("Add");

// Create an ElementInit that represents calling
// Dictionary<int, string>.Add(tree.Length, tree).
System.Linq.Expressions.ElementInit elementInit =
    System.Linq.Expressions.Expression.ElementInit(
        addMethod,
        System.Linq.Expressions.Expression.Constant(tree.Length),
        System.Linq.Expressions.Expression.Constant(tree));

Console.WriteLine(elementInit.ToString());

// This code produces the following output:
//
// Void Add(Int32, System.String)(5,"maple")
Dim tree As String = "maple"

Dim addMethod As System.Reflection.MethodInfo = _
    Type.GetType("System.Collections.Generic.Dictionary`2[System.Int32, System.String]").GetMethod("Add")

' Create an ElementInit that represents calling
' Dictionary(Of Integer, String).Add(tree.Length, tree).
Dim elementInit As System.Linq.Expressions.ElementInit = _
    System.Linq.Expressions.Expression.ElementInit( _
        addMethod, _
        System.Linq.Expressions.Expression.Constant(tree.Length), _
        System.Linq.Expressions.Expression.Constant(tree))

Console.WriteLine(elementInit.ToString())

' This code produces the following output:
'
' Void Add(Int32, System.String)(5,"maple")

Properties

AddMethod

Gets the instance method that is used to add an element to an IEnumerable collection.

Arguments

Gets the collection of arguments that are passed to a method that adds an element to an IEnumerable collection.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a textual representation of an ElementInit object.

Update(IEnumerable<Expression>)

Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will return this expression.

Explicit Interface Implementations

IArgumentProvider.ArgumentCount

Returns the number of arguments to the expression tree node. You should not use this member. It is only public due to assembly refactoring, and it is used internally for performance optimizations.

IArgumentProvider.GetArgument(Int32)

Returns the argument at index, throwing if index is out of bounds. You should not use this member. It is only public due to assembly refactoring, and it is used internally for performance optimizations.

Applies to