目录

类 TypePrefixSubscription

命名空间
Microsoft.AutoGen.Contracts
程序集
Microsoft.AutoGen.Core.dll

此订阅基于类型的前缀匹配主题,并使用主题的来源作为代理键映射到代理。此订阅导致每个来源都有其自己的代理实例。

public class TypePrefixSubscription : ISubscriptionDefinition
继承
TypePrefixSubscription
实现
继承的成员

备注

示例

var subscription = new TypePrefixSubscription("t1", "a1");

在这种情况下

  • 类型为 "t1" 且来源为 "s1"TopicId 将由类型为 "a1" 且键为 "s1" 的代理处理。
  • 类型为 "t1" 且来源为 "s2"TopicId 将由类型为 "a1" 且键为 "s2" 的代理处理。
  • 类型为 "t1SUFFIX" 且来源为 "s2"TopicId 将由类型为 "a1" 且键为 "s2" 的代理处理。

构造函数

TypePrefixSubscription(string, AgentType, string?)

初始化 TypePrefixSubscription 类的新实例。

public TypePrefixSubscription(string topicTypePrefix, AgentType agentType, string? id = null)

参数

topicTypePrefix string

要匹配的主题类型前缀。

agentType AgentType

处理此订阅的代理类型。

id string

订阅的唯一标识符。 如果未提供,将生成新的 UUID。

属性

AgentType

获取处理此订阅的代理类型。

public AgentType AgentType { get; }

属性值

AgentType

Id

获取订阅的唯一标识符。

public string Id { get; }

属性值

string

TopicTypePrefix

获取用于匹配的主题类型前缀。

public string TopicTypePrefix { get; }

属性值

string

方法

Equals(object?)

确定指定的对象是否等于当前订阅。

public override bool Equals(object? obj)

参数

obj object

要与当前实例进行比较的对象。

返回值

bool

如果指定的对象等于此实例,则为 true;否则,为 false

GetHashCode()

返回此实例的哈希代码。

public override int GetHashCode()

返回值

int

此实例的哈希代码,适合在哈希算法和数据结构中使用。

MapToAgent(TopicId)

TopicId 映射到 AgentId。 只有在 Matches(TopicId) 返回 true 时才应调用。

public AgentId MapToAgent(TopicId topic)

参数

topic TopicId

要映射的主题。

返回值

AgentId

一个 AgentId,表示应该处理该主题的代理。

异常

InvalidOperationException

如果主题与订阅不匹配,则抛出。

Matches(TopicId)

检查给定的 TopicId 是否基于其类型前缀与订阅匹配。

public bool Matches(TopicId topic)

参数

topic TopicId

要检查的主题。

返回值

bool

如果主题的类型以订阅的前缀开头,则为 true;否则为 false