Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle [Obsolete] #45

Merged
merged 6 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading