This commit is contained in:
Wvader 2021-12-06 02:06:54 +00:00
parent 302a15b30f
commit fd294925fc
3 changed files with 4 additions and 25 deletions

View File

@ -18,6 +18,8 @@
<RepositoryUrl>https://github.com/mrtaikandi/mapto</RepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<RootNamespace>MapTo</RootNamespace>
<AssemblyVersion>1.1</AssemblyVersion>
<FileVersion>1.1</FileVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
@ -44,8 +46,4 @@
<None Include="MapTo.props" Pack="true" PackagePath="build" Visible="false" />
</ItemGroup>
<ItemGroup>
<Folder Include="bin\Release\netstandard2.0" />
</ItemGroup>
</Project>

View File

@ -26,7 +26,7 @@ namespace MapTo.Sources
}
builder
.WriteLine("[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]")
.WriteLine("[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct)]")
.WriteLine($"public sealed class {AttributeName}Attribute : Attribute")
.WriteOpeningBracket();

View File

@ -147,26 +147,7 @@ namespace MapTo.Sources
.WriteLine($"/// <param name=\"{sourceClassParameterName}\">The instance of <see cref=\"{model.SourceType}\"/> to use as source.</param>");
}
private static SourceBuilder GenerateSourceTypeExtensionClass(this SourceBuilder builder, MappingModel model)
{
return builder
.WriteLine($"{model.Options.GeneratedMethodsAccessModifier.ToLowercaseString()} static partial class {model.SourceTypeIdentifierName}To{model.TypeIdentifierName}Extensions")
.WriteOpeningBracket()
.GenerateSourceTypeExtensionMethod(model)
.WriteClosingBracket();
}
private static SourceBuilder GenerateSourceTypeExtensionMethod(this SourceBuilder builder, MappingModel model)
{
var sourceClassParameterName = model.SourceTypeIdentifierName.ToCamelCase();
return builder
.GenerateConvertorMethodsXmlDocs(model, sourceClassParameterName)
.WriteLineIf(model.Options.SupportNullableStaticAnalysis, $"[return: NotNullIfNotNull(\"{sourceClassParameterName}\")]")
.WriteLine($"{model.Options.GeneratedMethodsAccessModifier.ToLowercaseString()} static {model.TypeIdentifierName}{model.Options.NullableReferenceSyntax} To{model.TypeIdentifierName}(this {model.SourceType}{model.Options.NullableReferenceSyntax} {sourceClassParameterName})")
.WriteOpeningBracket()
.WriteLine($"return {sourceClassParameterName} == null ? null : new {model.TypeIdentifierName}({sourceClassParameterName});")
.WriteClosingBracket();
}
}
}