public static EIFFEL_TYPE_INFO create_like_object(EIFFEL_TYPE_INFO an_obj) // Given an Eiffel object `an_obj' create a new one of same type. { // Create a new instance of the same type of `an_obj' // If it is a generic type, we also need to set its type. return((EIFFEL_TYPE_INFO)create_instance (an_obj.GetType(), an_obj.____type())); }
/* * feature -- Status report */ public static bool conforms_to(object Current, object other) // Does type of current object conform to type // of `other' (as per Eiffel: The Language, chapter 13)? { bool Result = false; RT_GENERIC_TYPE l_current_type, l_other_type; EIFFEL_TYPE_INFO current_info = Current as EIFFEL_TYPE_INFO; EIFFEL_TYPE_INFO other_info = other as EIFFEL_TYPE_INFO; #if ASSERTIONS ASSERTIONS.REQUIRE("other_not_void", other != null); #endif if (Current == null) { generate_call_on_void_target_exception(); } else { if (other_info == null) { // `other' is not an Eiffel object, we simply check for .NET conformance Result = other.GetType().IsAssignableFrom(Current.GetType()); } else if (current_info == null) { // `other' is an Eiffel object, but not `Current', therefore there is // no conformance. We do nothing since `Result' is already initialized to // false. } else { l_current_type = current_info.____type(); l_other_type = other_info.____type(); if (l_other_type == null) { // Parent type represented by the `other' instance // is not generic, therefore `Current' should directly // conform to the parent type. Result = ISE_RUNTIME.interface_type(other_info.GetType()).IsAssignableFrom(Current.GetType()); } else if (l_current_type == null) { // Parent is generic, but not type represented by // `Current', so let's first check if it simply // conforms without looking at the generic parameter. Result = ISE_RUNTIME.interface_type(other_info.GetType()).IsAssignableFrom(Current.GetType()); if (Result) { // It does conform, so now we have to go through // the parents to make sure it has the same generic // derivation. // FIXME: we should use feature `conform_to' from RT_TYPE here. } } else { // Both types are generic. We first check if they // simply conforms. #if ASSERTIONS ASSERTIONS.CHECK("l_current_type_not_void", l_current_type != null); ASSERTIONS.CHECK("l_other_type_not_void", l_other_type != null); #endif Result = ISE_RUNTIME.interface_type(other_info.GetType()).IsAssignableFrom(Current.GetType()); if (Result) { Result = l_current_type.conform_to(l_other_type); } } } } return(Result); }
// Given an Eiffel object `an_obj' create a new one of same type. public static EIFFEL_TYPE_INFO create_like_object(EIFFEL_TYPE_INFO an_obj) { // Create a new instance of the same type of `an_obj' // If it is a generic type, we also need to set its type. return (EIFFEL_TYPE_INFO) create_instance (an_obj.GetType (), an_obj.____type ()); }