Beispiel #1
0
        public string ResolveString()
        {
            if (string.IsNullOrEmpty(RawPath) || !ContainsMacros)
            {
                return(RawPath);
            }
            if (ProjectFile == null)
            {
                Logger.Warn("Could not find any project file for macro resolution");
                return(RawPath);
            }

            var    macroValues = Resolver.ResolveHeavyMacros(RawMacros, ProjectFile);
            string result      = System.Environment.ExpandEnvironmentVariables(RawPath);

            return(MacroRegex.Replace(result, match =>
            {
                var group = match.Groups[1];
                string macro = group.Value;
                if (!group.Success)
                {
                    return macro;
                }
                if (!macroValues.TryGetValue(macro, out string value))
                {
                    return macro;
                }
                return value;
            }));
        }
        public void InitializeResolvedPath(
            IReadOnlyDictionary <string, string> resolveResults,
            IPsiSourceFile sourceFile,
            IProjectFile projectFile
            )
        {
            string expanded = Environment.ExpandEnvironmentVariables(RawPath ?? "");
            string result   = MacroRegex.Replace(expanded, match =>
            {
                var group    = match.Groups[1];
                string macro = group.Value;
                if (!group.Success)
                {
                    return(macro);
                }
                if (!resolveResults.TryGetValue(macro, out string value))
                {
                    return(macro);
                }
                return(value);
            });

            MyResolvedPath = new T4ResolvedPath(result, sourceFile, projectFile);
        }