private RealmObject FindByPKGeneric(Type type, object primaryKeyValue, bool isIntegerPK) { var genericArgument = isIntegerPK ? typeof(long?) : typeof(string); var genericMethod = _realm.GetType().GetMethod(nameof(Realm.Find), new[] { genericArgument }); object castPKValue; if (isIntegerPK) { if (primaryKeyValue == null) { castPKValue = (long?)null; } else { castPKValue = Convert.ToInt64(primaryKeyValue); } } else { castPKValue = (string)primaryKeyValue; } return((RealmObject)genericMethod.MakeGenericMethod(type).Invoke(_realm, new[] { castPKValue })); }
public void CanConvert_checkForRealm_expectTrue() { RealmConverter realmConverter = new RealmConverter(); Realm realm = new Realm("realm"); Assert.True(realmConverter.CanConvert(realm.GetType())); }
internal static Expansion GetRealmExpansion(this Realm val) { ExpansionAttribute[] attributes = (ExpansionAttribute[])val .GetType() .GetField(val.ToString()) .GetCustomAttributes(typeof(ExpansionAttribute), false); return(attributes.Length > 0 ? attributes[0].Expansion : Expansion.Undefined); }