This repository was archived by the owner on Jan 22, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ namespace BitzArt.XDoc;
2323/// Disposing of an <see cref="XDoc"/> object will lead to a loss of all said data.
2424/// </para>
2525/// </summary>
26- public class XDoc
26+ public class XDoc : IDisposable
2727{
2828 private readonly ConcurrentDictionary < Assembly , AssemblyDocumentation > _fetchedAssemblies ;
2929
@@ -123,4 +123,53 @@ private AssemblyDocumentation Fetch(Assembly assembly)
123123 Type type => Get ( type ) ,
124124 _ => Get ( memberInfo . DeclaringType ! ) ? . GetDocumentation ( memberInfo )
125125 } ;
126+
127+ /// <summary>
128+ /// <inheritdoc cref="IDisposable"/>
129+ /// </summary>
130+ public void Dispose ( )
131+ {
132+ _fetchedAssemblies . Clear ( ) ;
133+ }
134+
135+ private static readonly ConcurrentDictionary < string , XDoc > Instances = new ( ) ;
136+
137+ /// <summary>
138+ /// Creates a new instance of <see cref="XDoc"/> or returns an existing one
139+ /// </summary>
140+ /// <param name="name"></param>
141+ /// <returns></returns>
142+ public static XDoc GetOrCreate ( string name = "" )
143+ {
144+ if ( Instances . TryGetValue ( name , out var doc ) )
145+ {
146+ return doc ;
147+ }
148+
149+ var xdoc = new XDoc ( ) ;
150+
151+ if ( Instances . TryAdd ( name , xdoc ) )
152+ {
153+ return xdoc ;
154+ }
155+
156+ return Instances [ name ] ;
157+ }
158+
159+ /// <summary>
160+ /// Removes the <see cref="XDoc"/> instance with the specified name
161+ /// </summary>
162+ /// <param name="name"></param>
163+ /// <returns></returns>
164+ public static bool Remove ( string name )
165+ {
166+ if ( Instances . TryRemove ( name , out var xdoc ) )
167+ {
168+ xdoc . Dispose ( ) ;
169+
170+ return true ;
171+ }
172+
173+ return false ;
174+ }
126175}
You can’t perform that action at this time.
0 commit comments