-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
126 additions
and
25 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
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,63 @@ | ||
using ExtendedXmlSerializer.Core.Sources; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace ExtendedXmlSerializer.ReflectionModel | ||
{ | ||
/// <summary> | ||
/// Attribution: https://stackoverflow.com/a/6131116/10340424 | ||
/// </summary> | ||
sealed class AssemblyPath : IParameterizedSource<string, string> | ||
{ | ||
public static AssemblyPath Default { get; } = new AssemblyPath(); | ||
|
||
AssemblyPath() {} | ||
|
||
public string Get(string parameter) | ||
{ | ||
if (parameter == null) | ||
{ | ||
throw new ArgumentNullException(nameof(parameter)); | ||
} | ||
|
||
var finalName = parameter; | ||
var aInfo = new AssemblyInfo {cchBuf = 1024}; // should be fine... | ||
aInfo.currentAssemblyPath = new string('\0', aInfo.cchBuf); | ||
|
||
var hr = CreateAssemblyCache(out var ac, 0); | ||
if (hr >= 0) | ||
{ | ||
hr = ac.QueryAssemblyInfo(0, finalName, ref aInfo); | ||
if (hr < 0) | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
return aInfo.currentAssemblyPath; | ||
} | ||
|
||
[DllImport("fusion.dll")] | ||
static extern int CreateAssemblyCache(out IAssemblyCache ppAsmCache, int reserved); | ||
|
||
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("e707dcde-d1cd-11d2-bab9-00c04f8eceae")] | ||
interface IAssemblyCache | ||
{ | ||
void Reserved0(); | ||
|
||
[PreserveSig] | ||
int QueryAssemblyInfo(int flags, [MarshalAs(UnmanagedType.LPWStr)] string assemblyName, | ||
ref AssemblyInfo assemblyInfo); | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
struct AssemblyInfo | ||
{ | ||
readonly int cbAssemblyInfo; | ||
readonly int assemblyFlags; | ||
readonly long assemblySizeInKB; | ||
[MarshalAs(UnmanagedType.LPWStr)] public string currentAssemblyPath; | ||
public int cchBuf; // size of path buf. | ||
} | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
test/ExtendedXmlSerializer.Tests.ReportedIssues/Issue366Tests.cs
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,37 @@ | ||
using ExtendedXmlSerializer.Configuration; | ||
using ExtendedXmlSerializer.Tests.ReportedIssues.Support; | ||
using FluentAssertions; | ||
using System.Drawing; | ||
using Xunit; | ||
|
||
namespace ExtendedXmlSerializer.Tests.ReportedIssues | ||
{ | ||
public sealed class Issue366Tests | ||
{ | ||
[Fact] | ||
void Verify() | ||
{ | ||
var instance = new Model(); | ||
new ConfigurationContainer().Create() | ||
.ForTesting() | ||
.Cycle(instance) | ||
.Should() | ||
.BeEquivalentTo(instance); | ||
} | ||
|
||
public class Model | ||
{ | ||
public Model() | ||
{ | ||
NestedModel = new NestedModel(); | ||
} | ||
|
||
public NestedModel NestedModel { get; set; } | ||
} | ||
|
||
public class NestedModel | ||
{ | ||
public Size Size { get; set; } | ||
} | ||
} | ||
} |