Skip to content

Couchbase.Extensions.Session - GetObject extension throws exception if object not in session #59

Description

@mgroves

For example, if there is no "user" object in the session store yet, then this:

HttpContext.Session.GetObject<dynamic>("user");

Will throw a NullReferenceException. A workaround would be:

if(HttpContext.Session.Get("user") != null)
    model.User = HttpContext.Session.GetObject<dynamic>("user");

But that's probably too much extra code, and worse case maybe it results in 2 get operations, when only 1 is necessary?

Maybe a TryGetObject extension is in order? Or some sort of overload of GetObject to supply a default value? Or both?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions