From 4bf3599d79f7ac484447c99cba23b7a10c27bd83 Mon Sep 17 00:00:00 2001 From: Wvader <34067397+wvader@users.noreply.github.com> Date: Wed, 8 Dec 2021 18:20:51 +0000 Subject: [PATCH] K --- src/MapTo/Extensions/CommonSource.cs | 12 ++++- .../TestConsoleApp/Data/FinanceTransaction.cs | 48 +++++++++++++++++++ .../Data/FinanceTransactionReadDto.cs | 21 ++++++++ test/TestConsoleApp/Data/Models/User.cs | 29 ----------- test/TestConsoleApp/Data/User.cs | 43 +++++++++++++++++ test/TestConsoleApp/Data/UserList.cs | 17 +++++++ test/TestConsoleApp/Data/UserUpdateDto.cs | 21 ++++++++ .../ViewModels/UserViewModel.cs | 1 + 8 files changed, 161 insertions(+), 31 deletions(-) create mode 100644 test/TestConsoleApp/Data/FinanceTransaction.cs create mode 100644 test/TestConsoleApp/Data/FinanceTransactionReadDto.cs delete mode 100644 test/TestConsoleApp/Data/Models/User.cs create mode 100644 test/TestConsoleApp/Data/User.cs create mode 100644 test/TestConsoleApp/Data/UserList.cs create mode 100644 test/TestConsoleApp/Data/UserUpdateDto.cs diff --git a/src/MapTo/Extensions/CommonSource.cs b/src/MapTo/Extensions/CommonSource.cs index 8e07e8e..a158a20 100644 --- a/src/MapTo/Extensions/CommonSource.cs +++ b/src/MapTo/Extensions/CommonSource.cs @@ -10,7 +10,7 @@ namespace MapTo.Extensions { internal static SourceCode GenerateStructOrClass(this MappingModel model, string structOrClass) { - const bool writeDebugInfo = false; + const bool writeDebugInfo = true; using var builder = new SourceBuilder() .WriteLine(GeneratedFilesHeader) @@ -88,7 +88,15 @@ namespace MapTo.Extensions return builder.WriteClosingBracket(); } - private static bool IsMappedProperty(this System.Collections.Immutable.ImmutableArray properties, MappedProperty property) => properties.Contains(property); + private static bool IsMappedProperty(this System.Collections.Immutable.ImmutableArray properties, MappedProperty property) { + + foreach(var prop in properties) + { + if (prop.FullyQualifiedType == property.FullyQualifiedType) return true; + } + + return false; + } private static SourceBuilder TryWriteProperties(this SourceBuilder builder, System.Collections.Immutable.ImmutableArray properties, System.Collections.Immutable.ImmutableArray? otherProperties, string? sourceClassParameterName, string mappingContextParameterName, bool fromUpdate) diff --git a/test/TestConsoleApp/Data/FinanceTransaction.cs b/test/TestConsoleApp/Data/FinanceTransaction.cs new file mode 100644 index 0000000..f88072d --- /dev/null +++ b/test/TestConsoleApp/Data/FinanceTransaction.cs @@ -0,0 +1,48 @@ +using System; +using MapTo; + +namespace BlueWest.Data +{ + public enum FinanceSymbol + { + BTC_EUR, + BTC_BUSD, + BTC_USD, + BTC_USDT, + LTC_EUR, + LTC_BUSD, + LTC_USDT + } + + public enum FinanceTransactionType + { + Buy, + Sell + } + + public partial struct FinanceTransaction + { + public int Id { get; set; } + public int UserId { get; set; } + public FinanceTransactionType FinanceTransactionType { get; } + public FinanceSymbol FinanceSymbol { get; } + public double Amount { get; } // To Buy + public double Quantity { get; } // Bought + public double Fee { get; } + public DateTime DateTime { get; } + + + public FinanceTransaction(int id, int userId, FinanceTransactionType financeTransactionType, + FinanceSymbol financeSymbol, double amount, double quantity, double fee, DateTime dateTime) + { + Id = id; + UserId = userId; + FinanceTransactionType = financeTransactionType; + FinanceSymbol = financeSymbol; + Amount = amount; + Quantity = quantity; + Fee = fee; + DateTime = dateTime; + } + } +} \ No newline at end of file diff --git a/test/TestConsoleApp/Data/FinanceTransactionReadDto.cs b/test/TestConsoleApp/Data/FinanceTransactionReadDto.cs new file mode 100644 index 0000000..ca36fb4 --- /dev/null +++ b/test/TestConsoleApp/Data/FinanceTransactionReadDto.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Text; +using MapTo; + +namespace BlueWest.Data +{ + [MapFrom(typeof(FinanceTransaction))] + + public partial struct FinanceTransactionReadDto + { + public int Id { get; set; } + public int UserId { get; set; } + public FinanceTransactionType FinanceTransactionType { get; } + public FinanceSymbol FinanceSymbol { get; } + public double Amount { get; } // To Buy + public double Quantity { get; } // Bought + public double Fee { get; } + public DateTime DateTime { get; } + } +} diff --git a/test/TestConsoleApp/Data/Models/User.cs b/test/TestConsoleApp/Data/Models/User.cs deleted file mode 100644 index 5f49b57..0000000 --- a/test/TestConsoleApp/Data/Models/User.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using TestConsoleApp.ViewModels; -using MapTo; -using System.Collections.Generic; - -namespace TestConsoleApp.Data.Models -{ - [MapFrom(typeof(UserViewModel))] - public partial struct User - { - public int Id { get; set; } - - public List> ListOfListOfString {get; } - - public List StringList { get; } - public DateTimeOffset RegisteredAt { get; set; } - - public User( int id, List> listOfListOfString, List stringList, DateTimeOffset registeredAt) - { - this.StringList = stringList; - this.Id = id; - ListOfListOfString = listOfListOfString; - RegisteredAt = registeredAt; - } - - - - } -} \ No newline at end of file diff --git a/test/TestConsoleApp/Data/User.cs b/test/TestConsoleApp/Data/User.cs new file mode 100644 index 0000000..0a0179e --- /dev/null +++ b/test/TestConsoleApp/Data/User.cs @@ -0,0 +1,43 @@ + +using System.Collections.Generic; +using MapTo; + + +namespace BlueWest.Data +{ + [MapFrom(typeof(UserUpdateDto))] + public partial struct User + { + public int Id { get; } + public string Name { get; set; } + public string Address { get; set; } + + public string BTCAddress { get; set; } + public string LTCAddress { get; set; } + + public double BTCAmount { get; set; } + public double LTCAmount { get; set; } + + public List FinanceTransactions { get; set; } + + public User(int id, string name, string address, string btcAddress, string ltcAddress, double btcAmount, double ltcAmount, List financeTransactions) + { + Id = id; + Name = name; + Address = address; + BTCAddress = btcAddress; + LTCAddress = ltcAddress; + BTCAmount = btcAmount; + LTCAmount = ltcAmount; + FinanceTransactions = financeTransactions; + } + + public void AddTransaction(FinanceTransaction financeTransaction) + { + FinanceTransactions.Add(financeTransaction); + } + + } +} + + diff --git a/test/TestConsoleApp/Data/UserList.cs b/test/TestConsoleApp/Data/UserList.cs new file mode 100644 index 0000000..c7c0dc0 --- /dev/null +++ b/test/TestConsoleApp/Data/UserList.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; + +namespace BlueWest.Data +{ + public class UserList + { + public List Users; + + public UserList(List users) + { + Users = users; + } + + + public int Length => Users.Count; + } +} \ No newline at end of file diff --git a/test/TestConsoleApp/Data/UserUpdateDto.cs b/test/TestConsoleApp/Data/UserUpdateDto.cs new file mode 100644 index 0000000..48844fd --- /dev/null +++ b/test/TestConsoleApp/Data/UserUpdateDto.cs @@ -0,0 +1,21 @@ +using MapTo; + +namespace BlueWest.Data +{ + [MapFrom(typeof(User))] + + public partial struct UserUpdateDto + { + public string Name { get; set; } + public string Address { get; set; } + + public string BTCAddress { get; set; } + public string LTCAddress { get; set; } + + public double BTCAmount { get; set; } + public double LTCAmount { get; set; } + + + + } +} \ No newline at end of file diff --git a/test/TestConsoleApp/ViewModels/UserViewModel.cs b/test/TestConsoleApp/ViewModels/UserViewModel.cs index b017d3f..8ba0590 100644 --- a/test/TestConsoleApp/ViewModels/UserViewModel.cs +++ b/test/TestConsoleApp/ViewModels/UserViewModel.cs @@ -1,4 +1,5 @@ using System; +using BlueWest.Data; using MapTo; using TestConsoleApp.Data.Models;