-
-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for HttpMethodAttribute as a base type so custom attributes can…
… work
- Loading branch information
1 parent
47a28be
commit 88a8573
Showing
3 changed files
with
70 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Refit.Generator | ||
{ | ||
static class ITypeSymbolExtensions | ||
{ | ||
public static IEnumerable<ITypeSymbol> GetBaseTypesAndThis(this ITypeSymbol? type) | ||
{ | ||
var current = type; | ||
while (current != null) | ||
{ | ||
yield return current; | ||
current = current.BaseType; | ||
} | ||
} | ||
|
||
// Determine if "type" inherits from "baseType", ignoring constructed types, optionally including interfaces, | ||
// dealing only with original types. | ||
public static bool InheritsFromOrEquals( | ||
this ITypeSymbol type, ITypeSymbol baseType, bool includeInterfaces) | ||
{ | ||
if (!includeInterfaces) | ||
{ | ||
return InheritsFromOrEquals(type, baseType); | ||
} | ||
|
||
return type.GetBaseTypesAndThis().Concat(type.AllInterfaces).Any(t => t.Equals(baseType, SymbolEqualityComparer.Default)); | ||
} | ||
|
||
|
||
// Determine if "type" inherits from "baseType", ignoring constructed types and interfaces, dealing | ||
// only with original types. | ||
public static bool InheritsFromOrEquals( | ||
this ITypeSymbol type, ITypeSymbol baseType) | ||
{ | ||
return type.GetBaseTypesAndThis().Any(t => t.Equals(baseType, SymbolEqualityComparer.Default)); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters