function applyCodegenParamsFromMdl(this, mdlName)
%

%   Copyright 2012-2022 The MathWorks, Inc.

params = this.getModelParams(mdlName);

if ~isempty(params) && ~isempty(this.CLI)
    % Protect against the CLI handle going bad during complicated renaming
    % sequences.
    if ~isa(this.CLI, 'hdlcoderprops.CLI')
        this.createCLI;
    end
    
    % Filter out any transient params that may have gotten incorrectly saved
    % onto a model.
    params = this.CLI.removeTransientParams(params);

    % Ideally, a property forwarding mechanism will also precede the 
    % set param.
    for ii = 1:2:length(params)
        % Fix up newlines etc. in the HDLSubsystem specification.
        if strcmpi(params{ii}, 'HDLSubsystem')
            params{ii+1} = hdlfixblockname(params{ii+1});
        end
        try
            this.CLI.set(params{ii},params{ii+1});             
        catch mEx
             switch mEx.identifier
                case {'MATLAB:noSuchMethodOrField','MATLAB:class:InvalidProperty'}
                    % Usually some property not found on CLI, or invalid
                    % property value.
                otherwise
                    rethrow(mEx)
             end
        end
    end
end

end
