11using System . Reflection ;
2+ using ExpressiveSharp . Mapping ;
3+ using ExpressiveSharp . Services ;
24using MongoDB . Bson . Serialization ;
35using MongoDB . Bson . Serialization . Conventions ;
46
@@ -33,12 +35,19 @@ public sealed class ExpressiveMongoIgnoreConvention : ConventionBase, IClassMapC
3335 /// </summary>
3436 public const string ConventionPackName = "ExpressiveSharp.MongoDB" ;
3537
38+ // The resolver's caches are static, so a single shared instance is sufficient. Used
39+ // to detect properties synthesized via [ExpressiveProperty] / [ExpressiveFor] — these
40+ // carry no CLR marker attribute, so we identify them through the generated registry.
41+ private static readonly IExpressiveResolver _resolver = new ExpressiveResolver ( ) ;
42+
3643 public ExpressiveMongoIgnoreConvention ( ) : base ( "ExpressiveSharpIgnore" ) { }
3744
3845 /// <summary>
3946 /// Runs during class-map construction. Inspects the class's CLR properties directly
4047 /// (instead of <see cref="BsonClassMap.DeclaredMemberMaps"/>, which may not be populated
41- /// yet at this stage) and unmaps any that carry <see cref="ExpressiveAttribute"/>.
48+ /// yet at this stage) and unmaps any that carry <see cref="ExpressiveAttribute"/> or
49+ /// <see cref="ExpressiveForAttribute"/>, or that are registered as synthesized by
50+ /// <c>[ExpressiveProperty]</c> in the runtime expression registry.
4251 /// </summary>
4352 public void Apply ( BsonClassMap classMap )
4453 {
@@ -53,7 +62,10 @@ public void Apply(BsonClassMap classMap)
5362 {
5463 continue ;
5564 }
56- if ( property . GetCustomAttribute < ExpressiveAttribute > ( inherit : false ) is null )
65+
66+ if ( property . GetCustomAttribute < ExpressiveAttribute > ( inherit : false ) is null
67+ && property . GetCustomAttribute < ExpressiveForAttribute > ( inherit : false ) is null
68+ && _resolver . FindExternalExpression ( property ) is null )
5769 {
5870 continue ;
5971 }
0 commit comments