Assuming the problem to be fairly simple where Listing isn't null, and therefore, all it underlying attributes aren't null either you can type something like this:
<%= encode( (Listing ?? (new Listing(AddressObj))).Address.Line1 ) %>
Your can write the Listing class here with a constructor such that Address.Line1 will always have value.
Now if your problem is fairly complex, where in you Listing object may have a valid instance but its underlying attribute may not: the best way is to wrap the encode method into another method or property which will return the expected result, and call that in the markup.
public string EncodedAddress
{
get
{
if (Listing == null)
return string.Empty;
if (Listing.Address == null)
return string.Empty;
return encode(Listing.Address.Line1);
}
}
In the markup you do something like:
<%= EncodedAddress %>