public static object create_like_object(object an_obj) // Given an Eiffel object `an_obj' create a new one of same type. { EIFFEL_TYPE_INFO l_obj_info; RT_GENERIC_TYPE l_type = null; // Create a new instance of the same type of `an_obj' l_obj_info = an_obj as EIFFEL_TYPE_INFO; if (l_obj_info != null) { // If it is a generic type, we also need to set its type. l_type = l_obj_info.____type(); } return(create_instance(an_obj.GetType(), l_type)); }
internal static object create_instance(Type type, RT_GENERIC_TYPE computed_type) // Create instance of a given `type' with the type information // `computed_type' (if any). { // Note: We use the `Activator' class because it is much faster than // creating an instance by getting the associated `ConstructorInfo'. if (computed_type == null) { // Use argumentless constructor. return(Activator.CreateInstance(type)); } else { // Use constructor with a type parameter. return(Activator.CreateInstance(type, new Object [] { computed_type })); } }