/// <summary> /// Fast count all objects of a given class, or in a RealmResults after casting. /// </summary> /// <remarks> /// Resolves to this method instead of the LINQ static extension <c>Count<T>(this IEnumerable<T>)</c>, when used directly on Realm.All. /// <br> /// if someone CASTS a RealmResults<T> variable from a Where call to /// a RealmResults<T> they change its compile-time type from IQueryable<blah> (which invokes LINQ) /// to RealmResults<T> and thus ends up here. /// </remarks> /// <returns>Count of all objects in a class or in the results of a search, without instantiating them.</returns> public int Count() { if (_allRecords) { // use the type captured at build based on generic T var tableHandle = _realm.Metadata [ObjectSchema.Name].Table; return((int)NativeTable.CountAll(tableHandle)); } // normally we would be in RealmQRealmResultsr.VisitMethodCall, not here // however, casting as described in the remarks above can cause this method to be invoked. // as in the unit test CountFoundWithCasting return((int)ResultsHandle.Count()); }