public static string GetCollectionName(this Type type) { // if (typeof(Resource).IsAssignableFrom(type)) if (type.CanBeTreatedAsType(typeof(Resource))) { return(ModelInfo.GetResourceNameForType(type)); } else { throw new ArgumentException(String.Format( "Cannot determine collection name, type {0} is not a resource type", type.Name)); } }
/// <summary> /// Find all Resources in a Bundle with the given id. /// </summary> /// <param name="bundle">Bundle to search in</param> /// <param name="id">The resource's id to find</param> /// <returns>A list of Resources with the given id, or an empty list if none were found.</returns> public static IEnumerable <T> FindResourceById <T>(this Bundle bundle, string id) where T : Resource { if (id == null) { throw Error.ArgumentNull("id"); } if (bundle.Entry == null) { return(Enumerable.Empty <T>()); } return(FindResourceById(bundle, ModelInfo.GetResourceNameForType(typeof(T)), id).Cast <T>()); }