C#
C#

help

Root Question Message

artem
artem3/8/2023
How can I work around this exception?

artem
artem3/8/2023
Note: I cannot just write where T : IRealmObject, because it will broke interface implementation
phaseshift
phaseshift3/8/2023
That's all you can do
artem
artem3/8/2023
can't I show that T is acceptable Type somehow else?
artem
artem3/8/2023
like cast it
phaseshift
phaseshift3/8/2023
That's whatwhere is for
phaseshift
phaseshift3/8/2023
Where is compile time. You're trying to fix a compile problem with a run time check. No bueno
phaseshift
phaseshift3/8/2023
You can change All<T> to All<IRealm...> Then also use OfType I guess
phaseshift
phaseshift3/8/2023
That would not be efficient, I'm presuming
Message Not Public

Sign In and Join Server To See

3/8/2023
Message Not Public

Sign In and Join Server To See

3/8/2023
artem
artem3/8/2023
public IQueryable<T> Select<T>()
        {
            if (!typeof(T).IsSubclassOf(typeof(IRealmObject)))
                throw new TypeAccessException($"{typeof(T).Name} is not a subclass of {typeof(IRealmObject).Name}");

            return realm?.All<IRealmObject>().OfType<T>();
        }

At least it works this way
Message Not Public

Sign In and Join Server To See

3/8/2023
Message Not Public

Sign In and Join Server To See

3/8/2023
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy