Skip to content

Commit

Permalink
fix: prevent failure loading ops when XML is missing (#229)
Browse files Browse the repository at this point in the history
Valid for Operator, Function, Predicate
Also speed up the process to Locate()
Use Describe() when reading XML comments is needed
  • Loading branch information
Seddryck authored Dec 28, 2023
1 parent e0df8c4 commit 1f27e32
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FunctionIntrospectorTest

[SetUp]
public void Setup()
=> Infos ??= new FunctionIntrospector().Locate();
=> Infos ??= new FunctionIntrospector().Describe();

[Test]
public void Locate_ExpressifAssembly_ElementsReturned()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PredicateIntrospectorTest

[SetUp]
public void Setup()
=> Infos ??= new PredicateIntrospector().Locate();
=> Infos ??= new PredicateIntrospector().Describe();

[Test]
public void Locate_ExpressifAssembly_ElementsReturned()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class OperatorIntrospectorTest

[SetUp]
public void Setup()
=> Infos ??= new OperatorIntrospector().Locate().ToArray();
=> Infos ??= new OperatorIntrospector().Describe().ToArray();

[Test]
public void Locate_ExpressifAssembly_ElementsReturned()
Expand Down
11 changes: 7 additions & 4 deletions Expressif/Functions/Introspection/FunctionIntrospector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ public FunctionIntrospector(ITypesProbe probe)
: base(probe) { }

public IEnumerable<FunctionInfo> Locate()
=> Locate<FunctionAttribute>();
=> Locate<FunctionAttribute>(true);

protected IEnumerable<FunctionInfo> Locate<T>() where T : FunctionAttribute
public IEnumerable<FunctionInfo> Describe()
=> Locate<FunctionAttribute>(false);

protected IEnumerable<FunctionInfo> Locate<T>(bool fast) where T : FunctionAttribute
{
var functions = LocateAttribute<FunctionAttribute>();

Expand All @@ -37,8 +40,8 @@ protected IEnumerable<FunctionInfo> Locate<T>() where T : FunctionAttribute
).Where(x => !string.IsNullOrEmpty(x)).ToArray()
, function.Type.Namespace!.ToToken('.').Last()
, function.Type
, function.Type.GetSummary()
, BuildParameters(function.Type.GetInfoConstructors()).ToArray()
, fast ? "" : function.Type.GetSummary()
, fast ? [] : BuildParameters(function.Type.GetInfoConstructors()).ToArray()
);
}
}
Expand Down
11 changes: 7 additions & 4 deletions Expressif/Predicates/Introspection/PredicateIntrospector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ public PredicateIntrospector(ITypesProbe probe)
: base(probe) { }

public IEnumerable<PredicateInfo> Locate()
=> Locate<PredicateAttribute>();
=> Locate<PredicateAttribute>(true);

protected IEnumerable<PredicateInfo> Locate<T>() where T : PredicateAttribute
public IEnumerable<PredicateInfo> Describe()
=> Locate<PredicateAttribute>(false);

protected IEnumerable<PredicateInfo> Locate<T>(bool fast = true) where T : PredicateAttribute
{
var predicates = LocateAttribute<PredicateAttribute>();

Expand All @@ -42,8 +45,8 @@ protected IEnumerable<PredicateInfo> Locate<T>() where T : PredicateAttribute
, predicate.Attribute.Aliases.AsQueryable().Prepend(string.Join('-', array)).ToArray()
, predicate.Type.Namespace!.ToToken('.').Last()
, predicate.Type
, predicate.Type.GetSummary()
, BuildParameters(predicate.Type.GetInfoConstructors()).ToArray()
, fast ? "" : predicate.Type.GetSummary()
, fast ? [] : BuildParameters(predicate.Type.GetInfoConstructors()).ToArray()
);
}
}
Expand Down
8 changes: 7 additions & 1 deletion Expressif/Predicates/Operators/OperatorIntrospector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public OperatorIntrospector(ITypesProbe probe)
: base(probe) { }

public IEnumerable<OperatorInfo> Locate()
=> Locate(true);

public IEnumerable<OperatorInfo> Describe()
=> Locate(false);

protected IEnumerable<OperatorInfo> Locate(bool fast = true)
{
var operators = LocateAttribute<OperatorAttribute>();

Expand All @@ -27,7 +33,7 @@ public IEnumerable<OperatorInfo> Locate()
, @operator.Type.IsPublic
, @operator.Attribute.Aliases
, @operator.Type
, @operator.Type.GetSummary()
, fast ? "" : @operator.Type.GetSummary()
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion generate-info.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $job = Start-Job -ScriptBlock { param($fullDllPath, $class, $destination)
$elapsed = Measure-Command -Expression {
$TextInfo = (Get-Culture).TextInfo
$locator = New-Object -TypeName "Expressif.$($TextInfo.ToTitleCase($class))s.Introspection.$($TextInfo.ToTitleCase($class))Introspector"
$functions = $locator.Locate() | Sort-Object ListingPriority | Select-Object -Property Name, IsPublic, Aliases, Scope, Summary, Parameters
$functions = $locator.Describe() | Sort-Object ListingPriority | Select-Object -Property Name, IsPublic, Aliases, Scope, Summary, Parameters
Write-Host "`t$($functions.Count) $($class.ToLower()) identified"
$functions | ForEach-Object {
if ($_.IsPublic) {
Expand Down

0 comments on commit 1f27e32

Please sign in to comment.