develop main BundledAgentNotesContent.cs csharp fb8e0499
1 #nullable enable 2 using System .Diagnostics .CodeAnalysis ;3 using System .Reflection ;4 using System .Text ;5 6 namespace AgentNotes .Core ;7 8 /// <summary> 9 /// Встроенные JSON из <c>Resources/</c> (см. <c>EmbeddedResource</c> в AgentNotes.Core.csproj). Имя в манифесте: 10 /// <c>AgentNotes.Core.Resources.</c> + относительный путь, <c>/</c> → <c>.</c> — тот же приём, что <c>BundledAppContent</c> в CascadeIDE (<c>CascadeIDE.</c> + путь). 11 /// </summary> 12 internal static class BundledAgentNotesContent 13 { 14 private static readonly Assembly s_assembly = typeof (BundledAgentNotesContent ).Assembly ; 15 private const string ResourcePrefix = "AgentNotes.Core.Resources." ; 16 17 /// <param name= "relativePath" >Под <c>Resources /</c>, слеши <c>/</c>, напр. <c>hot-context-defaults.json</c>.</param> 18 public static bool TryReadEmbeddedText (string relativePath, [NotNullWhen (true )] out string ? text) 19 { 20 text = null ; 21 var normalized = relativePath.Replace ('\\' , '/' ).TrimStart ('/' ); 22 if (normalized.Length == 0 || normalized.Contains (".." , StringComparison .Ordinal )) 23 return false ; 24 var name = ResourcePrefix + normalized.Replace ('/' , '.' ); 25 using var stream = s_assembly.GetManifestResourceStream (name); 26 if (stream is null ) 27 return false ; 28 using var reader = new StreamReader (stream, Encoding .UTF8 ); 29 text = reader.ReadToEnd (); 30 return !string .IsNullOrWhiteSpace (text); 31 } 32 } 33