Skip to content
Closed
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
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.1.101",
"rollForward": "latestFeature"
"rollForward": "latestMajor"
}
}
}
5 changes: 4 additions & 1 deletion src/Weikio.TypeGenerator/CodeToAssemblyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public Assembly GenerateAssembly(string code)
null, null, null, OptimizationLevel.Debug, false,
false, null, null, new ImmutableArray<byte>(), new bool?()));

var fullPath = Path.Combine(_workingFolder, assemblyName);
var fullPath = Path.Combine(_workingFolder, GetWithDllExtension(assemblyName));
var assemblies = _assemblies.Where(x => !string.IsNullOrWhiteSpace(x.Location)).Select(x => x).ToList();

if (_assemblyLoadContext is CustomAssemblyLoadContext customAssemblyLoadContext)
Expand Down Expand Up @@ -202,6 +202,9 @@ public Assembly GenerateAssembly(string code)
}
}

private static string GetWithDllExtension(string input) =>
input.EndsWith(".dll") ? input : $"{input}.dll";

private static void ThrowError(string code, EmitResult emitResult)
{
var errors = emitResult.Diagnostics
Expand Down
9 changes: 5 additions & 4 deletions src/Weikio.TypeGenerator/Weikio.TypeGenerator.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
Expand All @@ -18,9 +18,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="4.7.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" />
<PackageReference Include="System.Reflection.MetadataLoadContext" Version="7.0.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Update="MinVer" Version="4.3.0" />
</ItemGroup>
</Project>
98 changes: 49 additions & 49 deletions tests/unit/Weikio.TypeGenerator.Tests/TypeWrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,55 +422,55 @@ public void CanInheritAndImplement()
}

#if DEBUG
[Fact]
public void CanAddAttributesToType()
{
throw new NotImplementedException();

var wrapper = new TypeToTypeWrapper();

var result = wrapper.CreateType(typeof(TestClass), new TypeToTypeWrapperOptions()
{
TypeAttributesGenerator = (options, type) =>
{
var typeAttributes = new List<Attribute> { new DisplayNameAttribute("Hello There") };

return typeAttributes;
}
});

Assert.Single(result.GetCustomAttributes(typeof(DisplayNameAttribute), true));
}

[Fact]
public void CanAddAttributesToMethod()
{
throw new NotImplementedException();

var wrapper = new TypeToTypeWrapper();

var result = wrapper.CreateType(typeof(TestClass),
new TypeToTypeWrapperOptions()
{
AdditionalReferences = new List<Assembly>() { typeof(JsonConverter).Assembly },
OnConstructorCustomCodeGenerator = (options, type) => "var arr = new Newtonsoft.Json.Linq.JArray();"
});
}

[Fact]
public void CanAddAttributesToConstructor()
{
throw new NotImplementedException();

var wrapper = new TypeToTypeWrapper();

var result = wrapper.CreateType(typeof(TestClass),
new TypeToTypeWrapperOptions()
{
AdditionalReferences = new List<Assembly>() { typeof(JsonConverter).Assembly },
OnConstructorCustomCodeGenerator = (options, type) => "var arr = new Newtonsoft.Json.Linq.JArray();"
});
}
// [Fact]
// public void CanAddAttributesToType()
// {
// throw new NotImplementedException();
//
// var wrapper = new TypeToTypeWrapper();
//
// var result = wrapper.CreateType(typeof(TestClass), new TypeToTypeWrapperOptions()
// {
// TypeAttributesGenerator = (options, type) =>
// {
// var typeAttributes = new List<Attribute> { new DisplayNameAttribute("Hello There") };
//
// return typeAttributes;
// }
// });
//
// Assert.Single(result.GetCustomAttributes(typeof(DisplayNameAttribute), true));
// }
//
// [Fact]
// public void CanAddAttributesToMethod()
// {
// throw new NotImplementedException();
//
// var wrapper = new TypeToTypeWrapper();
//
// var result = wrapper.CreateType(typeof(TestClass),
// new TypeToTypeWrapperOptions()
// {
// AdditionalReferences = new List<Assembly>() { typeof(JsonConverter).Assembly },
// OnConstructorCustomCodeGenerator = (options, type) => "var arr = new Newtonsoft.Json.Linq.JArray();"
// });
// }
//
// [Fact]
// public void CanAddAttributesToConstructor()
// {
// throw new NotImplementedException();
//
// var wrapper = new TypeToTypeWrapper();
//
// var result = wrapper.CreateType(typeof(TestClass),
// new TypeToTypeWrapperOptions()
// {
// AdditionalReferences = new List<Assembly>() { typeof(JsonConverter).Assembly },
// OnConstructorCustomCodeGenerator = (options, type) => "var arr = new Newtonsoft.Json.Linq.JArray();"
// });
// }

#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFrameworks>netcoreapp3.1;net7.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.*" />
<PackageReference Include="xunit" Version="2.4.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.*" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Update="MinVer" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down