private static bool IsAnonymousType( object entity )
{
Type type = entity.GetType();
var typeInfo = type.GetTypeInfo();
return typeInfo.IsDefined( typeof( CompilerGeneratedAttribute ), false )
&& type.Name.Contains( "AnonymousType" )
&& ( type.Name.StartsWith( "<>" ) || type.Name.StartsWith( "VB$" ) )
&& ( typeInfo.Attributes & TypeAttributes.NotPublic ) == TypeAttributes.NotPublic;
}