title: Generic Automapper Precondition for Struct type with `Value`and `HasValue`
body: <p>I'm using Automapper and Hot Chocolate. I am using a struct type on my source class properties named <code>Optional&lt;&gt;</code> which has the methods <code>.Value</code> and <code>.HasValue</code>, this is used to determine whether the client passed in these values or not. This is used for a partial update/patching from client to DB. So for example:</p>
  <p>My model/dto:
  <code>public Optional&lt;string&gt; Name { get; init; }</code></p>
  <p>In my automapper profile I can do this:</p>
  <pre><code>.ForMember(dest =&gt; dest.Name, opt =&gt; {
      opt.PreCondition(src =&gt; src.Name.HasValue))
      opt.MapFrom(src =&gt; src.Name.Value)
  })
  </code></pre>
  <p>This works and has the behaviour I want to have. However, I dont want to end up writing manual mapping code for all my attributes, that's why I'm using Automapper in the first place.</p>
  <p>Therefore, I'm attempting to make this behaviour generic of all source type properties of type <code>IOptional</code>.</p>
  <p>I've tried a bunch of different things. Extension methods and reflections, and using type converters.</p>
  <p>Automapper custom type converter won't work since you have to return a value and can't &quot;bail&quot; out of the mapping.</p>
  <p>I've tried to make extension methods for <code>PreCondition</code>, but I only have access to the AutoMapper's <code>ResolverContext</code>object, and I havent figured out how to utilize this. For example:</p>
  <pre><code>.ForAllOtherMembers(o =&gt; o.PreCondition((src, dest, rc) =&gt; 
      // what do    
  ));
  </code></pre>
  <p>Has anyone done anything similar? I suppose it's the same concept as a <code>Nullable&lt;&gt;</code> struct, but I couldnt find any implementations for that which worked for this case as well.</p>