遇到了试图比较两种类型的Catcall,如何避免通过另一个非专用方法(例如字符串,class_id或类似的东西)呢?
class_name_lowercase (a_string: STRING): STRING
-- a copy lowercased and pruned from preceding '!'
do
Result := a_string
if Result.index_of('!', 1) = 1 then
Result := Result.substring (2, Result.count)
Result.to_lower
else
Result := Result.as_lower
end
ensure
instance_free: class
end
relationship_from_secondary_type_equal (a_type: like relationships.item.secondary_type): detachable like relationships.item
-- Returns first instance of found relationship secondary type which equals given one
do
across
relationships as l_rel
until
Result /= Void
loop
-- if attached (a_type / l_rel.item.secondary_type) then -- Don't want conformance but equality
-- if attached (a_type.is_equal (l_rel.item.secondary_type)) then -- tried but as is_equal needs a like Current => Catcall
-- if attached (a_type.equal (a_type, l_rel.item.secondary_type)) then -- Catcall because b signature is like a
if {SIT_UTIL}.class_name_lowercase (a_type).is_equal({SIT_UTIL}.class_name_lowercase (l_rel.item.secondary_type)) then
Result := l_rel.item
end
end
check
not_found_relationship: Result /= Void
end
end
答案 0 :(得分:2)
一致性属性是反对称的,即如果 A→B 和 B→A ,则 A = B 。因此,两种类型相等是彼此一致的:
python manage.py runserver
(尽管 a_type.conforms_to (l_rel.item.secondary_type) and
l_rel.item.secondary_type.conforms_to (a_type)
比较对象的类型而不是对象本身,但是上面的表达式仍然可以,因为由于符合规则 A = B ,并且仅当 TYPE当 A 和 B 本身是类型时,[A] =类型[B] 。
如果连接了其中一种类型,而另一种是可分离的,则您可能仍希望将它们进行相等比较。在这种情况下,可以使用以下代码:
conforms_to
比较谓词忽略附加标记:
is_conforming (a_type, l_rel.item.secondary_type) and
is_conforming (l_rel.item.secondary_type, a_type)