dadhi/FastExpressionCompiler

Fix the direct assignment of Try to Member expression because indirect assignment through tmp var works

dadhi opened this issue · 1 comments

Got it from the AutoMapper unit tests include_should_apply_null_substitute

At least the C# output of such assignment is fixed:

T __f<T>(System.Func<T> f) => f();
(Func<IncludedMappingShouldInheritBaseMappings.ModelSubObject, IncludedMappingShouldInheritBaseMappings.DtoSubObject, ResolutionContext, IncludedMappingShouldInheritBaseMappings.DtoSubObject>)((
    IncludedMappingShouldInheritBaseMappings.ModelSubObject source, 
    IncludedMappingShouldInheritBaseMappings.DtoSubObject destination, 
    ResolutionContext context) => //IncludedMappingShouldInheritBaseMappings.DtoSubObject
    (source == null) ? 
        (destination == null) ? 
            null : 
            destination : 
        __f(() => {
            IncludedMappingShouldInheritBaseMappings.DtoSubObject typeMapDestination = null;
            typeMapDestination = destination ?? new IncludedMappingShouldInheritBaseMappings.DtoSubObject();
            try
            {
                typeMapDestination.SubString = source.SubString;
            }
            catch (Exception ex)
            {
                throw TypeMapPlanBuilder.MemberMappingError(
                    ex,
                    default(PropertyMap)/*Please provide the non-default value for the constant!*/);
            }
            
            try
            {
                typeMapDestination.BaseString = 
                __f(() => {
                    try
                    {
                        return source.DifferentBaseString;
                    }
                    catch (NullReferenceException)
                    {
                        return (string)null;
                    }
                    catch (ArgumentNullException)
                    {
                        return (string)null;
                    }
                }) ?? "12345";
            }
            catch (Exception ex)
            {
                throw TypeMapPlanBuilder.MemberMappingError(
                    ex,
                    default(PropertyMap)/*Please provide the non-default value for the constant!*/);
            }
            
            return typeMapDestination;
        }));