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

Add additional generator options #9

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: added ability to change the name of the generated method
amyskippy committed Oct 6, 2024
commit 8f9421de2980915746e1c3cd679a4870cf0c45fa
5 changes: 5 additions & 0 deletions MapDataReader/GenerateDataReaderMapperAttribute.cs
Original file line number Diff line number Diff line change
@@ -11,6 +11,11 @@ public class GenerateDataReaderMapperAttribute : Attribute
/// Gets or sets the namespace to be used in the generated methods.
/// </summary>
public string NamespaceName { get; set; }

/// <summary>
/// Gets or sets the method name to be used in the generated methods.
/// </summary>
public string MethodName { get; set; }

public GenerateDataReaderMapperAttribute()
{
6 changes: 4 additions & 2 deletions MapDataReader/MapperGenerator.cs
Original file line number Diff line number Diff line change
@@ -27,6 +27,7 @@ public void Execute(GeneratorExecutionContext context)

var accessModifier = allAttributes["AccessModifier"];
var namespaceName = allAttributes["NamespaceName"];
var methodName = allAttributes["MethodName"] ?? $"To{typeNode.Identifier}";

var src = $@"
// <auto-generated/>
@@ -79,7 +80,7 @@ private static void SetPropertyByUpperName(this {typeNodeSymbol.FullName()} targ
{
src += $@"

{accessModifier} static List<{typeNodeSymbol.FullName()}> To{typeNode.Identifier}(this IDataReader dr)
{accessModifier} static List<{typeNodeSymbol.FullName()}> {methodName}(this IDataReader dr)
{{
var list = new List<{typeNodeSymbol.FullName()}>();

@@ -125,7 +126,8 @@ private static Dictionary<string,string> GetGeneratedMapperAttributes(ClassDecla
var defaults = new Dictionary<string, string>
{
{ "AccessModifier", "public" },
{ "NamespaceName", "MapDataReader" }
{ "NamespaceName", "MapDataReader" },
{ "MethodName", null }
};

// Retrieve the attribute list