-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
Dev/src gen cell value mapper #69
Dev/src gen cell value mapper #69
Conversation
This is how I think to implement source gen with
|
Thanks for the PR! I made a quick suggestion how to support this in #67, but after some more thought I'd like to make some changes to my initial suggestion:
Here is how that would look in code: public class MyObject
{
[CellValueConverter(typeof(NullToDashConverter))]
public int? Number { get; set; }
}
public class NullToDashConverter : CellValueConverter<int?>
{
public DataCell ConvertToCell(int? value)
{
return value is null ? new DataCell("-") : new DataCell(value.Value);
}
}
public abstract class CellValueConverter<T>
{
public abstract DataCell ConvertToCell(T value);
} Support for selecting a style based on the cell value probably doesn't belong in this PR, but to handle that I am considering a similar approach. That feature would depend on getting a style by its name. In code it could look like this: public class MyObject
{
// TODO: Better name for the attribute?
[CellStyleProvider(typeof(NullableIntStyleProvider))]
public int? Number { get; set; }
}
public class NullableIntStyleProvider : CellStyleProvider<int?>
{
public string? GetStyleName(int? value)
{
return value is null ? null : "My style";
}
}
public abstract class CellStyleProvider<T>
{
public abstract string? GetStyleName(T value);
} Now, to answer your questions:
|
…value converter type
…or CellValueConverter
…_value_mapper # Conflicts: # SpreadCheetah.SourceGenerator/WorksheetRowGenerator.cs
I decided not to add support for the class level attribute for this time, because it requires another attribute with a different name and the ability to add it multiple times for different types. The current |
Thanks! 👍 I'll have a look. |
SpreadCheetah.SourceGenerator/Extensions/AttributeDataExtensions.cs
Outdated
Show resolved
Hide resolved
...adCheetah.SourceGenerator.SnapshotTest/Tests/WorksheetRowGeneratorCellValueConverterTests.cs
Show resolved
Hide resolved
…g for the base type op CellValueConverter, update test
This looks very good, thank you! I will make some minor adjustments and once that is ready I will release a new version on NuGet. I hope to have it ready during the weekend. |
0c29c21
into
sveinungf:dev/src-gen-cellvalueconverter
okay |
Preview version of source gen with
CellValueMapper