Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
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
2 changes: 1 addition & 1 deletion libraries/AdaptiveExpressions/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ public class FunctionTable : IDictionary<string, ExpressionEvaluator>
#pragma warning restore CA1710 // Identifiers should have correct suffix
#pragma warning restore CA1034 // Nested types should not be visible
{
private readonly ConcurrentDictionary<string, ExpressionEvaluator> _customFunctions = new ConcurrentDictionary<string, ExpressionEvaluator>(StringComparer.InvariantCultureIgnoreCase);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringComparer.InvariantCultureIgnoreCase [](start = 152, length = 41)

Did you want to drop the cases insensitivity?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Personally think the custom functions should align with Builtin functions. (Case sensitivity).

private readonly ConcurrentDictionary<string, ExpressionEvaluator> _customFunctions = new ConcurrentDictionary<string, ExpressionEvaluator>();

/// <summary>
/// Gets a collection of string values that represent the keys of the StandardFunctions.
Expand Down
18 changes: 4 additions & 14 deletions libraries/Microsoft.Bot.Builder.LanguageGeneration/Templates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ private Templates InjectToExpressionFunction()
{
if (curTemplates.Any(u => u.Name == templateName))
{
var newGlobalName = $"{curTemplates.Namespace}.{templateName}";
var prefix = string.IsNullOrWhiteSpace(curTemplates.Namespace) ? string.Empty : curTemplates.Namespace + ".";
var newGlobalName = prefix + templateName;
Expression.Functions.Add(newGlobalName, new ExpressionEvaluator(
newGlobalName,
(expression, state, options) =>
Expand Down Expand Up @@ -648,19 +649,8 @@ private string ExtractNameSpace(IList<string> options)
{
var result = ExtractOptionsByKey(_namespaceKey, options);

if (result == null)
{
if (Path.IsPathRooted(Source))
{
result = Path.GetFileNameWithoutExtension(Source);
}
else
{
throw new Exception("namespace is required or the id should be an absoulte path!");
}
}

return result;
// If there is no namespace, use the file name parsed from Id.
return result ?? Path.GetFileNameWithoutExtension(Id ?? string.Empty);
}

private IList<string> GetGlobalFunctionTable(IList<string> options)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
> !# @Exports = greeting

# greeting
- hi ${name}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<None Remove="Examples\import2.lg" />
<None Remove="Examples\InjectionTest\common.lg" />
<None Remove="Examples\InjectionTest\inject.lg" />
<None Remove="Examples\InjectionTest\injectWithoutNamespace.lg" />
<None Remove="Examples\IsTemplate.lg" />
<None Remove="Examples\LGOptionTest.lg" />
<None Remove="Examples\MultilineTextForAdaptiveCard.lg" />
Expand Down Expand Up @@ -188,6 +189,9 @@
<Content Include="Examples\InjectionTest\inject.lg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Examples\InjectionTest\injectWithoutNamespace.lg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Examples\StringInterpolation.lg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,35 @@ public void TestInjectLG()
Assert.Equal("10", evaled.ToString());
}

[Fact]
public void TestInjectLGWithoutNamespace()
{
// using Id as the namespace
var lgPath = GetExampleFilePath("./InjectionTest/injectWithoutNamespace.lg");
var resource = new LGResource("myId", lgPath, File.ReadAllText(lgPath));
Templates.ParseResource(resource);

var (evaled, error) = Expression.Parse("myId.greeting()").TryEvaluate(new { name = "Alice" });
Assert.Null(error);
Assert.Equal("hi Alice", evaled.ToString());

// using the fuileName parsed from Id as the namespace
resource = new LGResource("./path/myNewId.lg", lgPath, File.ReadAllText(lgPath));
Templates.ParseResource(resource);

(evaled, error) = Expression.Parse("myNewId.greeting()").TryEvaluate(new { name = "Alice" });
Assert.Null(error);
Assert.Equal("hi Alice", evaled.ToString());

// With empty id
resource = new LGResource(string.Empty, lgPath, File.ReadAllText(lgPath));
Templates.ParseResource(resource);

(evaled, error) = Expression.Parse("greeting()").TryEvaluate(new { name = "Alice" });
Assert.Null(error);
Assert.Equal("hi Alice", evaled.ToString());
}

public class LoopClass
{
public string Name { get; set; }
Expand Down