Skip to content

Commit

Permalink
Renamed ExportAttribute to DllExportAttribute
Browse files Browse the repository at this point in the history
Resolves #7
  • Loading branch information
MeikTranel committed Mar 29, 2020
1 parent 943d77b commit ee84370
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 21 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<!-- markdownlint-disable MD041 -->
<!-- markdownlint-disable MD041 -->
- [BREAKINGCHANGE] #7 Renamed `ExportAttribute` to `DllExportAttribute`
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The following code will result in an exported function named `SampleExportFunc`.

```CSharp
public static class Exports {
[Export(alias:"SampleExportFunc")]
[DllExport(alias:"SampleExportFunc")]
public static double Add(double a, double b)
{
return a + b;
Expand Down
4 changes: 2 additions & 2 deletions samples/NETFX-OldCSProj/Exports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class Exports
/// <summary>
/// The exported c function will be named "DoSomething"
/// </summary>
[Export]
[DllExport]
public static void DoSomething()
{
System.Console.WriteLine(nameof(DoSomething));
Expand All @@ -16,7 +16,7 @@ public static void DoSomething()
/// <summary>
/// The exported c function will be named "PINVOKE_Rocks"
/// </summary>
[Export("PINVOKE_Rocks")]
[DllExport("PINVOKE_Rocks")]
public static void DoSomething2ElectricBogaloo()
{
System.Console.WriteLine(nameof(DoSomething2ElectricBogaloo));
Expand Down
2 changes: 1 addition & 1 deletion samples/NETFX_SDKCSProj/Exports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void DoSomething()
/// <summary>
/// The exported c function will be named "PINVOKE_Rocks"
/// </summary>
[Export("PINVOKE_Rocks")]
[DllExport("PINVOKE_Rocks")]
public static void DoSomething2ElectricBogaloo()
{
System.Console.WriteLine(nameof(DoSomething2ElectricBogaloo));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
namespace NXPorts.Attributes
{
[AttributeUsage(System.AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public sealed class ExportAttribute : Attribute
public sealed class DllExportAttribute : Attribute
{
public string Alias { get; private set; }

public CallingConvention CallingConvention { get; private set; }

public ExportAttribute(string alias = null, CallingConvention callingConvention = CallingConvention.Cdecl)
public DllExportAttribute(string alias = null, CallingConvention callingConvention = CallingConvention.Cdecl)
{
this.Alias = alias;
this.CallingConvention = callingConvention;
Expand Down
2 changes: 1 addition & 1 deletion src/NXPorts/AssemblyExportWriterTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void RewriteAnnotatedMethod(ExportAttributedAssembly sourceAssembly, Exp
),
returnType
);
exportDefinition.MethodDefinition.CustomAttributes.RemoveAll(typeof(ExportAttribute).FullName);
exportDefinition.MethodDefinition.CustomAttributes.RemoveAll(typeof(DllExportAttribute).FullName);
}

private static void RemoveToxicDebuggableAttribute(ModuleDefMD module)
Expand Down
4 changes: 2 additions & 2 deletions src/NXPorts/ExportAttributedAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ private IEnumerable<ExportDefinition> RetrieveExportDefinitions()
{
foreach(var method in type.Methods)
{
if(method.CustomAttributes.IsDefined(new Attributes.ExportAttribute().GetType().FullName))
if(method.CustomAttributes.IsDefined(new Attributes.DllExportAttribute().GetType().FullName))
{
var attributeRef = method.CustomAttributes.Find(new Attributes.ExportAttribute().GetType().FullName);
var attributeRef = method.CustomAttributes.Find(new Attributes.DllExportAttribute().GetType().FullName);
var expDef = ExportDefinition.Create(method,attributeRef);
yield return expDef;
}
Expand Down
12 changes: 6 additions & 6 deletions tests/NXPorts.Tests/AssemblyExportWriter_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void ProducesAssemblyWithOneWorkingExport()
{
var testCode = @"namespace Test {
public class TestClassA {
[NXPorts.Attributes.Export]
[NXPorts.Attributes.DllExport]
public static string DoSomething()
{
return ""TestReturnValue"";
Expand Down Expand Up @@ -54,7 +54,7 @@ public void ProducesAssemblyWithoutExportAttributes()
{
var testCode = @"namespace Test {
public class TestClassA {
[NXPorts.Attributes.Export]
[NXPorts.Attributes.DllExport]
public static void DoSomething() { }
}
}";
Expand All @@ -73,10 +73,10 @@ public static void DoSomething() { }
var methodsWithOffendingAttribute = from t in resultModule.Types
from m in t.Methods
from ca in m.CustomAttributes
where ca.TypeFullName == typeof(Attributes.ExportAttribute).FullName
where ca.TypeFullName == typeof(Attributes.DllExportAttribute).FullName
select m;

Assert.AreEqual(0, methodsWithOffendingAttribute.Count(),$"Assembly was left with one ore more {nameof(Attributes.ExportAttribute)} occurences.");
Assert.AreEqual(0, methodsWithOffendingAttribute.Count(),$"Assembly was left with one ore more {nameof(Attributes.DllExportAttribute)} occurences.");
}
}
}
Expand All @@ -88,7 +88,7 @@ public void ProducesAssemblyWithoutAnyReferenceToNXPortAttributes()
{
var testCode = @"namespace Test {
public class TestClassA {
[NXPorts.Attributes.Export]
[NXPorts.Attributes.DllExport]
public static void DoSomething()
{
}
Expand All @@ -106,7 +106,7 @@ public static void DoSomething()

using (var resultModule = ModuleDefMD.Load("./testOut.dll"))
{
var simpleNameOfAttributeAssembly = typeof(NXPorts.Attributes.ExportAttribute).Assembly.GetName().Name;
var simpleNameOfAttributeAssembly = typeof(NXPorts.Attributes.DllExportAttribute).Assembly.GetName().Name;
Assert.AreEqual(
null,
resultModule.GetAssemblyRef(simpleNameOfAttributeAssembly),
Expand Down
6 changes: 3 additions & 3 deletions tests/NXPorts.Tests/ExportAttributedAssembly_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Reading_Export_Instructions_Returns_One_ExportDefinition()
{
var testCode = @"namespace Test {
class TestClassA {
[NXPorts.Attributes.Export]
[NXPorts.Attributes.DllExport]
public static void DoShizzle()
{
System.Console.WriteLine(""asdsad"");
Expand All @@ -61,7 +61,7 @@ public void Reading_Export_Instructions_Returns_A_Custom_Aliased_ExportDefinitio
{
var testCode = @"namespace Test {
class TestClassA {
[NXPorts.Attributes.Export(alias:""Aids"")]
[NXPorts.Attributes.DllExport(alias:""Aids"")]
public static void DoShizzle()
{
System.Console.WriteLine(""asdsad"");
Expand All @@ -87,7 +87,7 @@ public void Reading_Export_Instructions_Returns_A_ExportDefinition_With_A_Custom
var testCode = @"using System.Runtime.InteropServices;
namespace Test {
class TestClassA {
[NXPorts.Attributes.Export(callingConvention:CallingConvention.FastCall)]
[NXPorts.Attributes.DllExport(callingConvention:CallingConvention.FastCall)]
public static void DoShizzle()
{
System.Console.WriteLine(""asdsad"");
Expand Down
2 changes: 1 addition & 1 deletion tests/NXPorts.Tests/Infrastructure/TestEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public ProjectCreator SetupNXPortsProject(string projectFilePath = "./test.cspro
return ProjectCreator.Templates.SdkCsproj(projectFilePath, targetFramework: targetFramework)
.Property("NXPortsTaskAssemblyDirectory", dir + "\\")
.Property("PlatformTarget","x86")
.ItemReference(new Uri(Assembly.GetAssembly(typeof(ExportAttribute)).CodeBase).LocalPath)
.ItemReference(new Uri(Assembly.GetAssembly(typeof(DllExportAttribute)).CodeBase).LocalPath)
.Import(Path.Combine(dir, "Build", "NXPorts.targets"));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/NXPorts.Tests/TestFiles/Simple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace NXPorts.Tests.TestFiles
{
public static class Simple
{
[Export]
[DllExport]
public static void DoSomething()
{
Console.WriteLine("Test");
Expand Down

0 comments on commit ee84370

Please sign in to comment.