@ -16,6 +16,8 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
// DEALINGS IN THE SOFTWARE.
# nullable enable
using System ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Diagnostics.CodeAnalysis ;
using System.Diagnostics.CodeAnalysis ;
@ -43,7 +45,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <typeparam name='T'>
/// <typeparam name='T'>
/// The type of the annotation.
/// The type of the annotation.
/// </typeparam>
/// </typeparam>
T Annotation < T > ( ) where T : class ;
T ? Annotation < T > ( ) where T : class ;
/// <summary>
/// <summary>
/// Gets the first annotation of the specified type.
/// Gets the first annotation of the specified type.
@ -52,7 +54,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// <param name='type'>
/// <param name='type'>
/// The type of the annotation.
/// The type of the annotation.
/// </param>
/// </param>
object Annotation ( Type type ) ;
object? Annotation ( Type type ) ;
/// <summary>
/// <summary>
/// Adds an annotation to this instance.
/// Adds an annotation to this instance.
@ -90,7 +92,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
// or to an AnnotationList.
// or to an AnnotationList.
// Once it is pointed at an AnnotationList, it will never change (this allows thread-safety support by locking the list)
// Once it is pointed at an AnnotationList, it will never change (this allows thread-safety support by locking the list)
object annotations ;
object? annotations ;
/// <summary>
/// <summary>
/// Clones all annotations.
/// Clones all annotations.
@ -102,7 +104,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary>
/// </summary>
protected void CloneAnnotations ( )
protected void CloneAnnotations ( )
{
{
ICloneable cloneable = annotations as ICloneable ;
ICloneable ? cloneable = annotations as ICloneable ;
if ( cloneable ! = null )
if ( cloneable ! = null )
annotations = cloneable . Clone ( ) ;
annotations = cloneable . Clone ( ) ;
}
}
@ -126,8 +128,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
for ( int i = 0 ; i < this . Count ; i + + )
for ( int i = 0 ; i < this . Count ; i + + )
{
{
object obj = this [ i ] ;
object obj = this [ i ] ;
ICloneable c = obj as ICloneable ;
ICloneable ? c = obj as ICloneable ;
copy . Add ( c ! = null ? c . Clone ( ) : obj ) ;
copy . Add ( c ! = null ? c . Clone ( ) ! : obj ) ;
}
}
return copy ;
return copy ;
}
}
@ -139,12 +141,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
if ( annotation = = null )
if ( annotation = = null )
throw new ArgumentNullException ( nameof ( annotation ) ) ;
throw new ArgumentNullException ( nameof ( annotation ) ) ;
retry : // Retry until successful
retry : // Retry until successful
object oldAnnotation = Interlocked . CompareExchange ( ref this . annotations , annotation , null ) ;
object? oldAnnotation = Interlocked . CompareExchange ( ref this . annotations , annotation , null ) ;
if ( oldAnnotation = = null )
if ( oldAnnotation = = null )
{
{
return ; // we successfully added a single annotation
return ; // we successfully added a single annotation
}
}
AnnotationList list = oldAnnotation as AnnotationList ;
AnnotationList ? list = oldAnnotation as AnnotationList ;
if ( list = = null )
if ( list = = null )
{
{
// we need to transform the old annotation into a list
// we need to transform the old annotation into a list
@ -170,8 +172,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public virtual void RemoveAnnotations < T > ( ) where T : class
public virtual void RemoveAnnotations < T > ( ) where T : class
{
{
retry : // Retry until successful
retry : // Retry until successful
object oldAnnotations = this . annotations ;
object? oldAnnotations = this . annotations ;
AnnotationList list = oldAnnotations as AnnotationList ;
AnnotationList ? list = oldAnnotations as AnnotationList ;
if ( list ! = null )
if ( list ! = null )
{
{
lock ( list )
lock ( list )
@ -192,8 +194,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
if ( type = = null )
if ( type = = null )
throw new ArgumentNullException ( nameof ( type ) ) ;
throw new ArgumentNullException ( nameof ( type ) ) ;
retry : // Retry until successful
retry : // Retry until successful
object oldAnnotations = this . annotations ;
object? oldAnnotations = this . annotations ;
AnnotationList list = oldAnnotations as AnnotationList ;
AnnotationList ? list = oldAnnotations as AnnotationList ;
if ( list ! = null )
if ( list ! = null )
{
{
lock ( list )
lock ( list )
@ -209,17 +211,17 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
}
}
}
}
public T Annotation < T > ( ) where T : class
public T ? Annotation < T > ( ) where T : class
{
{
object annotations = this . annotations ;
object? annotations = this . annotations ;
AnnotationList list = annotations as AnnotationList ;
AnnotationList ? list = annotations as AnnotationList ;
if ( list ! = null )
if ( list ! = null )
{
{
lock ( list )
lock ( list )
{
{
foreach ( object obj in list )
foreach ( object obj in list )
{
{
T t = obj as T ;
T ? t = obj as T ;
if ( t ! = null )
if ( t ! = null )
return t ;
return t ;
}
}
@ -232,12 +234,12 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
}
}
}
}
public object Annotation ( Type type )
public object? Annotation ( Type type )
{
{
if ( type = = null )
if ( type = = null )
throw new ArgumentNullException ( nameof ( type ) ) ;
throw new ArgumentNullException ( nameof ( type ) ) ;
object annotations = this . annotations ;
object? annotations = this . annotations ;
AnnotationList list = annotations as AnnotationList ;
AnnotationList ? list = annotations as AnnotationList ;
if ( list ! = null )
if ( list ! = null )
{
{
lock ( list )
lock ( list )
@ -262,8 +264,8 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
/// </summary>
/// </summary>
public IEnumerable < object > Annotations {
public IEnumerable < object > Annotations {
get {
get {
object annotations = this . annotations ;
object? annotations = this . annotations ;
AnnotationList list = annotations as AnnotationList ;
AnnotationList ? list = annotations as AnnotationList ;
if ( list ! = null )
if ( list ! = null )
{
{
lock ( list )
lock ( list )