ListInitExpression Sınıf
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Koleksiyon başlatıcısı olan bir oluşturucu çağrısını temsil eder.
public ref class ListInitExpression sealed : System::Linq::Expressions::Expression
public sealed class ListInitExpression : System.Linq.Expressions.Expression
type ListInitExpression = class
inherit Expression
Public NotInheritable Class ListInitExpression
Inherits Expression
- Devralma
Örnekler
Aşağıdaki örnek, iki anahtar-değer çifti olan yeni bir sözlük örneğinin başlatılmasını temsil eden bir oluşturur ListInitExpression .
string tree1 = "maple";
string tree2 = "oak";
System.Reflection.MethodInfo addMethod = typeof(Dictionary<int, string>).GetMethod("Add");
// Create two ElementInit objects that represent the
// two key-value pairs to add to the Dictionary.
System.Linq.Expressions.ElementInit elementInit1 =
System.Linq.Expressions.Expression.ElementInit(
addMethod,
System.Linq.Expressions.Expression.Constant(tree1.Length),
System.Linq.Expressions.Expression.Constant(tree1));
System.Linq.Expressions.ElementInit elementInit2 =
System.Linq.Expressions.Expression.ElementInit(
addMethod,
System.Linq.Expressions.Expression.Constant(tree2.Length),
System.Linq.Expressions.Expression.Constant(tree2));
// Create a NewExpression that represents constructing
// a new instance of Dictionary<int, string>.
System.Linq.Expressions.NewExpression newDictionaryExpression =
System.Linq.Expressions.Expression.New(typeof(Dictionary<int, string>));
// Create a ListInitExpression that represents initializing
// a new Dictionary<> instance with two key-value pairs.
System.Linq.Expressions.ListInitExpression listInitExpression =
System.Linq.Expressions.Expression.ListInit(
newDictionaryExpression,
elementInit1,
elementInit2);
Console.WriteLine(listInitExpression.ToString());
// This code produces the following output:
//
// new Dictionary`2() {Void Add(Int32, System.String)(5,"maple"),
// Void Add(Int32, System.String)(3,"oak")}
Dim tree1 As String = "maple"
Dim tree2 As String = "oak"
Dim addMethod As System.Reflection.MethodInfo = _
Type.GetType("System.Collections.Generic.Dictionary`2[System.Int32, System.String]").GetMethod("Add")
' Create two ElementInit objects that represent the
' two key-value pairs to add to the Dictionary.
Dim elementInit1 As System.Linq.Expressions.ElementInit = _
System.Linq.Expressions.Expression.ElementInit( _
addMethod, _
System.Linq.Expressions.Expression.Constant(tree1.Length), _
System.Linq.Expressions.Expression.Constant(tree1))
Dim elementInit2 As System.Linq.Expressions.ElementInit = _
System.Linq.Expressions.Expression.ElementInit( _
addMethod, _
System.Linq.Expressions.Expression.Constant(tree2.Length), _
System.Linq.Expressions.Expression.Constant(tree2))
' Create a NewExpression that represents constructing
' a new instance of Dictionary(Of Integer, String).
Dim newDictionaryExpression As System.Linq.Expressions.NewExpression = _
System.Linq.Expressions.Expression.[New](Type.GetType("System.Collections.Generic.Dictionary`2[System.Int32, System.String]"))
' Create a ListInitExpression that represents initializing
' a new Dictionary(Of T) instance with two key-value pairs.
Dim listInitExpression As System.Linq.Expressions.ListInitExpression = _
System.Linq.Expressions.Expression.ListInit( _
newDictionaryExpression, _
elementInit1, _
elementInit2)
Console.WriteLine(listInitExpression.ToString())
' This code produces the following output:
'
' new Dictionary`2() {Void Add(Int32, System.String)(5,"maple"),
' Void Add(Int32, System.String)(3,"oak")
Açıklamalar
ListInit Oluşturmak ListInitExpressioniçin fabrika yöntemlerini kullanın.
özelliğinin NodeTypeListInitExpression değeridir ListInit.
Özellikler
| Name | Description |
|---|---|
| CanReduce |
İfade ağacı düğümünü azaltılıp azaltılamayacağını gösteren bir değer alır. |
| Initializers |
Bir koleksiyonu başlatmak için kullanılan öğe başlatıcılarını alır. |
| NewExpression |
Koleksiyon türünün oluşturucusunun çağrısını içeren ifadeyi alır. |
| NodeType |
Bunun Expressiondüğüm türünü döndürür. |
| NodeType |
Bu Expressiondüğüm türünü alır. (Devralındığı yer: Expression) |
| Type |
Bunun Expression temsil ettiği ifadenin statik türünü alır. |
| Type |
Bunun Expression temsil ettiği ifadenin statik türünü alır. (Devralındığı yer: Expression) |
Yöntemler
| Name | Description |
|---|---|
| Accept(ExpressionVisitor) |
Bu düğüm türü için belirli bir ziyaret yöntemine gönderilir. Örneğin, MethodCallExpression öğesini çağırır VisitMethodCall(MethodCallExpression). (Devralındığı yer: Expression) |
| Equals(Object) |
Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler. (Devralındığı yer: Object) |
| GetHashCode() |
Varsayılan karma işlevi işlevi görür. (Devralındığı yer: Object) |
| GetType() |
Geçerli örneğin Type alır. (Devralındığı yer: Object) |
| MemberwiseClone() |
Geçerli Objectbasit bir kopyasını oluşturur. (Devralındığı yer: Object) |
| Reduce() |
İkili ifade düğümünü daha basit bir ifadeye küçültür. |
| ReduceAndCheck() |
Bu düğümü daha basit bir ifadeye küçültür. CanReduce true döndürürse, bu geçerli bir ifade döndürmelidir. Bu yöntem, azaltması gereken başka bir düğüm döndürebilir. (Devralındığı yer: Expression) |
| ReduceExtensions() |
İfadeyi bilinen bir düğüm türüne (Uzantı düğümü değildir) küçültür veya zaten bilinen bir türse yalnızca ifadeyi döndürür. (Devralındığı yer: Expression) |
| ToString() |
öğesinin metinsel gösterimini Expressiondöndürür. (Devralındığı yer: Expression) |
| Update(NewExpression, IEnumerable<ElementInit>) |
Bunun gibi, ancak sağlanan alt öğeleri kullanarak yeni bir ifade oluşturur. Tüm alt öğeler aynıysa, bu ifadeyi döndürür. |
| VisitChildren(ExpressionVisitor) |
Düğümü azaltır ve ardından azaltılmış ifadede ziyaretçi temsilcisini çağırır. Yöntem, düğüm azaltılabilir değilse bir özel durum oluşturur. (Devralındığı yer: Expression) |