【发布时间】:2019-06-30 03:20:11
【问题描述】:
有一个 Catcall 试图比较 2 种类型,我该如何避免通过另一个非专用方法(如字符串、class_id 或类似的东西)?
SIT_UTIL
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
CLIENT_CLASS
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
【问题讨论】:
-
relationships.item.secondary_type的类型是什么? -
对不起:
TYPE[detachable S]whereS -> DB_ENTITY create default_create endsoTYPE[detachable DB_ENTITY]
标签: eiffel