# QueryEntities

|Class/Struct Info|
|:-------------------------------------------------------------------------------|
|public readonly struct QueryEntities : IEnumerable<IEntity> 查询核心类，包括查询基础功能和泛型实现。|

## Property Summary

|Name|Type|Description|
|:----|:---|:----------|
|Count|int|查询匹配的实体数量。|

## Method Summary

|Qualifier and Type|Method Name and Description|
|:-----------------|:---------------------------------------------------------------------------------------|
|string|[ToString](#section1031617010220)() 返回查询实体数量字符串。|
|EntitySet|[ToEntitySet](#section0531034154618)() 返回查询实体的列表。|
|EntitySet|[ToEntitySet](#section118636347467)(EntitySet set) 将查询实体放入输入的实体列表中。|
|EntitiesEnumerator|[GetEnumerator](#section4535123510461)() 获取实体枚举器，用于遍历查询结果的接口，foreach自动调用。|
|void|[ProcessBatchOnAll](#section1671183604612)(BatchProcessor processor) 将批处理应用到查询结果集中的所有实体。|

## Methods

### ToString

|Method|
|:----------------------------------------------|
|string ToString() 返回查询实体数量字符串，打印的组件和标签名字均会带命名域。|

**Return**

|Type|Description|
|:-----|:----------|
|string|查询实体数量。|

**Sample Code**

```screen
var world = new IECSWorld();
var query = world.Query();
// 打印查询实体数量。预设组件/标签命名域为"Pgd."，自定义组件/标签/共享组件根据实际情况而定
query.Entities.ToString(); // "Query: { Components:[], Tags:[Pgd.Inactive], SharedComponents:[]}"
```

### ToEntitySet

|Method|
|:---------------------------------|
|EntitySet ToEntitySet() 返回查询实体的列表。|

**Return**

|Type|Description|
|:--------|:----------|
|EntitySet|查询实体的列表。|

**Sample Code**

```screen
var world = new IECSWorld();
// 创建一个Query
var query = world.Query();
// 将QueryEntities匹配的所有实体转换成EntitySet
var entitySet = query.Entities.ToEntitySet();
```

### ToEntitySet

|Method|
|:----------------------------------------------------|
|EntitySet ToEntitySet(EntitySet set) 将查询实体放入输入的实体列表中。|

**Parameters**

|Name|Type|Description|
|:---|:--------|:----------|
|list|EntitySet|实体列表。|

**Return**

|Type|Description|
|:--------|:----------|
|EntitySet|查询实体的列表。|

**Sample Code**

```screen
var world = new IECSWorld();
// 创建一个Query
var query = world.Query();
// 将QueryEntities匹配的所有实体转换成EntitySet，指定输出集合
var entitySet = query.Entities.ToEntitySet(new EntitySet());
```

### GetEnumerator

|Method|
|:------------------------------------------------------------------|
|EntitiesEnumerator GetEnumerator() 获取实体枚举器，用于遍历查询结果的接口，foreach自动调用。|

**Return**

|Type|Description|
|:-----------------|:----------|
|EntitiesEnumerator|实体枚举器。|

**Sample Code**

```screen
var world = new IECSWorld();
// 创建一个Query
var query = world.Query();
// foreach自动调用GetEnumerator()，用QueryEntities进行查询迭代，遍历实体
foreach(var entity in query.Entities)
{
    /*处理逻辑*/
}
```

### ProcessBatchOnAll

|Method|
|:-------------------------------------------------------------------|
|void ProcessBatchOnAll(BatchProcessor processor) 将批处理应用到查询结果集中的所有实体。|

**Parameters**

|Name|Type|Description|
|:--------|:-------------|:----------------|
|processor|BatchProcessor|批处理器，包含一组组件和标签操作。|

**Sample Code**

```screen
var world = new IECSWorld();
var query = world.Query();
var batch = new BatchProcessor();
batch.Inactive();
batch.AddComponent(new PgdPosition());
// 将批处理器中的指令批量应用到查询匹配的所有实体上
query.Entities.ProcessBatchOnAll(batch);
```

