You could write a helper method for this type of functionality:
public Object flsGet(SObject record, SObjectField field)
{
return !field.getDescribe().isAccessible() ? null : record.get(field);
}
With this reusable method, you can now just one-line the check:
Contact someRecord = [SELECT Name FROM Contact LIMIT 1];
system.debug(flsGet(someRecord, Contact.Name));
If you're really worried about performance, you could write a caching mechanism. You may do more harm than good though. I certainly haven't profiled it. Your code could be structured something like:
public class FLS
{
public static Boolean isAccessible(SObjectType sObjectType, SObjectField field)
{
return getAccessibleFields(sObjectType).contains(field);
}
static Map<SObjectType, Set<SObjectField>> accessible;
public static Set<SObjectField> getAccessibleFields(SObjectType sObjectType)
{
if (accessible == null)
accessible = new Map<SObjectType, Set<SObjectField>>();
if (!accessible.containsKey(sObjectType))
accessible.put(sObjectType, getAccessibleFields(sObjectType));
return accessible.get(sObjectType);
}
static Set<SObjectField> getAccessibleFields(SObjectType sObjectType)
{
// implementation should be straightforward
}
}