Beispiel #1
0
    public bool TryGetSetterCode(string memberName, string literal, [MaybeNullWhen(false)] out string code, out Diagnostic?diagnostic)
    {
        // Returns false if memberName not found,
        // otherwise true even if literal does not match the pattern.

        if (_dic == null || _store == null || _ownerType == null || _ownerType == null || _dic.TryGetValue(memberName, out var data) == false)
        {
            code       = null;
            diagnostic = null;
            return(false);
        }
        if (data.Pattern.IsMatch(literal) == false)
        {
            code       = $"// Invalid literal. memberName: {memberName}, literal: {literal}";
            diagnostic = DiagnosticHelper.InvalidLiteralForMember(literal, memberName);
            return(true);
        }
        var replacePatterns = data.ReplacePatterns.Span;
        var replaces        = data.Replaces.Span;
        var ownerType       = _store.GetOrCreateType(_ownerType);

        code       = ownerType.ReplaceMetaVariable(EvalRegexReplace(literal, replacePatterns, replaces));
        diagnostic = null;
        return(true);
    }