Skip to content

Commit

Permalink
Merge pull request #45 from candy-kingdom/feature/23-obsolete
Browse files Browse the repository at this point in the history
Handle `[Obsolete]`
  • Loading branch information
kostiantxn authored Dec 9, 2023
2 parents 4bf20e9 + 30356aa commit 299159f
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 106 deletions.
22 changes: 22 additions & 0 deletions docs/DocDeprecation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Summary.DocDeprecation
```cs
public record DocDeprecation
```

Contains deprecation information (e.g. the warning message).

## Properties
### Message
```cs
public string? Message { get; init; }
```

The deprecation warning message.

### Error
```cs
public bool Error { get; init; }
```

Whether the usage should be treated as an error instead of a warning.

15 changes: 15 additions & 0 deletions docs/DocMember.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ public required DocType? DeclaringType { get; init; }

The type that this member is declared in (works for nested types as well).

### Deprecated
```cs
[MemberNotNullWhen(true, nameof(Deprecation))]
public bool Deprecated { get; }
```

Whether the member is deprecated (e.g. marked with `[Obsolete]`).

### Deprecation
```cs
public DocDeprecation? Deprecation { get; init; }
```

The member deprecation information.

## Methods
### MatchesCref(string)
```cs
Expand Down
6 changes: 5 additions & 1 deletion docs/Sample{T0,T1}.Child.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Summary.Samples.Sample.Child
# ~~Summary.Samples.Sample.Child~~
> [!WARNING]
> The type is deprecated.
```cs
[Obsolete(error: true, message: "The type is deprecated.")]
public class Child
```

Expand Down
6 changes: 5 additions & 1 deletion docs/Sample{T0,T1}.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ public int Field

A field of the child class.

### Field1
### ~~Field1~~
> [!WARNING]
> The field is deprecated.
```cs
[Obsolete("The field is deprecated.")]
public int Field1
```

Expand Down
17 changes: 17 additions & 0 deletions src/Core/DocDeprecation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Summary;

/// <summary>
/// Contains deprecation information (e.g. the warning message).
/// </summary>
public record DocDeprecation
{
/// <summary>
/// The deprecation warning message.
/// </summary>
public string? Message { get; init; }

/// <summary>
/// Whether the usage should be treated as an error instead of a warning.
/// </summary>
public bool Error { get; init; }
}
15 changes: 14 additions & 1 deletion src/Core/DocMember.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Summary;
using System.Diagnostics.CodeAnalysis;

namespace Summary;

/// <summary>
/// A member of the generated document (e.g. type, field, property, method, etc.).
Expand Down Expand Up @@ -36,6 +38,17 @@ public abstract record DocMember
/// </summary>
public required DocType? DeclaringType { get; init; }

/// <summary>
/// Whether the member is deprecated (e.g. marked with <c>[Obsolete]</c>).
/// </summary>
[MemberNotNullWhen(true, nameof(Deprecation))]
public bool Deprecated => Deprecation is not null;

/// <summary>
/// The member deprecation information.
/// </summary>
public DocDeprecation? Deprecation { get; init; }

/// <summary>
/// Whether this member matches the specified `cref` reference.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions src/Core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public static string Space(this string self) =>
public static string Surround(this string self, string left, string right) =>
self.Map(x => $"{left}{x}{right}");

/// <summary>
/// Surrounds the specified string with the given prefix and suffix strings
/// if the specified condition is satisfied. If the string is empty, returns the string as is.
/// </summary>
public static string Surround(this string self, string left, string right, bool when) =>
when ? self.Surround(left, right) : self;

private static string Map(this string self, Func<string, string> map) =>
self is "" ? self : map(self);

Expand Down
2 changes: 2 additions & 0 deletions src/Core/Samples/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Sample<T0, T1>
/// <summary>
/// A child of the <see cref="Sample{T0,T1}"/> class.
/// </summary>
[Obsolete(error: true, message: "The type is deprecated.")]
public class Child
{
/// <summary>
Expand All @@ -45,6 +46,7 @@ public class Child
/// <summary>
/// A sample field.
/// </summary>
[Obsolete("The field is deprecated.")]
public int Field1;

/// <summary>
Expand Down
Loading

0 comments on commit 299159f

Please sign in to comment.