/// <summary> /// Fast count all objects of a given class. /// </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. /// </remarks> public int Count() { if (_allRecords) { // use the type captured at build based on generic T var tableHandle = _realm.Metadata[ElementType].Table; return((int)NativeTable.count_all(tableHandle)); } // normally we would be in RealmQRealmResultsr.VisitMethodCall, not here // however, if someone CASTS a RealmResults<blah> variable from a Where call to // a RealmResults<blah> they change its compile-time type from IQueryable<blah> (which invokes LINQ) // to RealmResults<blah> and thus ends up here. // as in the unit test CountFoundWithCasting return((int)NativeResults.count(ResultsHandle)); }