Windows apps
Collapse the table of content
Expand the table of content

ElementInit Class

 

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

Namespace:   System.Linq.Expressions
Assembly:  System.Core (in System.Core.dll)

System.Object
  System.Linq.Expressions.ElementInit

public sealed class ElementInit : IArgumentProvider

NameDescription
System_CAPS_pubpropertyAddMethod

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

System_CAPS_pubpropertyArguments

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

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a textual representation of an ElementInit object.(Overrides Object.ToString().)

System_CAPS_pubmethodUpdate(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.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIArgumentProvider.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.

System_CAPS_pubinterfaceSystem_CAPS_privpropertyIArgumentProvider.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.

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")

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2017 Microsoft