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

Resolve conflicts when two csdl names have similar suffixes #407

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 9 additions & 2 deletions src/Microsoft.OData.CodeGen/Templates/ODataT4CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5121,7 +5121,10 @@ internal override void WriteGeneratedEdmModel(string escapedEdmxString)
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
WanjohiSammy marked this conversation as resolved.
Show resolved Hide resolved
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down Expand Up @@ -7297,7 +7300,11 @@ End Function
Private Shared Function CreateXmlReader() As Global.System.Xml.XmlReader
Try
Dim assembly As Global.System.Reflection.Assembly = Global.System.Reflection.Assembly.GetExecutingAssembly()
Dim resourcePath As Global.System.String = Global.System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), Function(str) str.EndsWith(filePath))
' If multiple resource names end with the file name, select the shortest one.
Dim resourcePath As Global.System.String =
Global.System.Linq.Enumerable.First(
Global.System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), Function(n) n.Length),
Function(str) str.EndsWith(filePath))
Dim stream As Global.System.IO.Stream = assembly.GetManifestResourceStream(resourcePath)
Return Global.System.Xml.XmlReader.Create(New Global.System.IO.StreamReader(stream))
Catch e As Global.System.Xml.XmlException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4683,7 +4683,10 @@ namespace <#= fullNamespace #>
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we should apply the filter first (i.e., .EndsWith(string)), then order by length, then pick the first item
I feel like that's more efficient. We'll calculate length for fewer candidates (most times 1):

global::System.Linq.Enumerable.First(
    global::System.Linq.Enumerable.OrderBy(
        global::System.Linq.Enumerable.Where(
            assembly.GetManifestResourceNames(),
            str1 => str1.EndsWith(filePath)),
        str2 => str2.Length))

There's also the question whether it'd be safer to use FirstOrDefault()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made the change.

global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down Expand Up @@ -5870,7 +5873,11 @@ Namespace <#= fullNamespace #>
Private Shared Function CreateXmlReader() As Global.System.Xml.XmlReader
Try
Dim assembly As Global.System.Reflection.Assembly = Global.System.Reflection.Assembly.GetExecutingAssembly()
Dim resourcePath As Global.System.String = Global.System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), Function(str) str.EndsWith(filePath))
' If multiple resource names end with the file name, select the shortest one.
Dim resourcePath As Global.System.String =
Global.System.Linq.Enumerable.First(
Global.System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), Function(n) n.Length),
Function(str) str.EndsWith(filePath))
Dim stream As Global.System.IO.Stream = assembly.GetManifestResourceStream(resourcePath)
Return Global.System.Xml.XmlReader.Create(New Global.System.IO.StreamReader(stream))
Catch e As Global.System.Xml.XmlException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,10 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
WanjohiSammy marked this conversation as resolved.
Show resolved Hide resolved
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,10 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
habbes marked this conversation as resolved.
Show resolved Hide resolved
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,10 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,10 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,10 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,10 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,10 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,10 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,10 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,10 @@ private abstract class GeneratedEdmModel
try
{
var assembly = global::System.Reflection.Assembly.GetExecutingAssembly();
var resourcePath = global::System.Linq.Enumerable.Single(assembly.GetManifestResourceNames(), str => str.EndsWith(filePath));
// If multiple resource names end with the file name, select the shortest one.
var resourcePath = global::System.Linq.Enumerable.First(
global::System.Linq.Enumerable.OrderBy(assembly.GetManifestResourceNames(), n => n.Length),
str => str.EndsWith(filePath));
global::System.IO.Stream stream = assembly.GetManifestResourceStream(resourcePath);
return global::System.Xml.XmlReader.Create(new global::System.IO.StreamReader(stream));
}
Expand Down