Exemplo n.º 1
0
        private void Initialize()
        {
            string?currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location);
            string templatesFolder  = Path.Combine(currentDirectory ?? throw new ArgumentNullException("Path is null"),
                                                   "Snippets",
                                                   "Templates");

            foreach (string prefix in _snippetPrefixes)
            {
                string template = Path.Combine(templatesFolder, prefix + ".bicep");

                (string description, string snippetText) = GetDescriptionAndText(File.ReadAllText(template));
                ResourceSnippet resourceSnippet = new ResourceSnippet(prefix, description, snippetText);

                resourceSnippets.Add(resourceSnippet);
            }
        }
Exemplo n.º 2
0
        private void Initialize()
        {
            string               pathPrefix            = "Snippets/Templates/";
            Assembly             assembly              = typeof(ResourceSnippetsProvider).Assembly;
            IEnumerable <string> manifestResourceNames = assembly.GetManifestResourceNames().Where(p => p.StartsWith(pathPrefix, StringComparison.Ordinal));

            foreach (var manifestResourceName in manifestResourceNames)
            {
                Stream?      stream       = assembly.GetManifestResourceStream(manifestResourceName);
                StreamReader streamReader = new StreamReader(stream ?? throw new ArgumentNullException("Stream is null"), Encoding.Default);

                (string description, string snippetText) = GetDescriptionAndText(streamReader.ReadToEnd());
                string          prefix          = Path.GetFileNameWithoutExtension(manifestResourceName);
                ResourceSnippet resourceSnippet = new ResourceSnippet(prefix, description, snippetText);

                resourceSnippets.Add(resourceSnippet);
            }
        }