This commit is contained in:
Wvader 2021-12-08 18:20:51 +00:00
parent 735fd44ee1
commit 4bf3599d79
8 changed files with 161 additions and 31 deletions

View File

@ -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<MappedProperty> properties, MappedProperty property) => properties.Contains(property);
private static bool IsMappedProperty(this System.Collections.Immutable.ImmutableArray<MappedProperty> 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<MappedProperty> properties, System.Collections.Immutable.ImmutableArray<MappedProperty>? otherProperties,
string? sourceClassParameterName, string mappingContextParameterName, bool fromUpdate)

View File

@ -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;
}
}
}

View File

@ -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; }
}
}

View File

@ -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<List<string>> ListOfListOfString {get; }
public List<string> StringList { get; }
public DateTimeOffset RegisteredAt { get; set; }
public User( int id, List<List<string>> listOfListOfString, List<string> stringList, DateTimeOffset registeredAt)
{
this.StringList = stringList;
this.Id = id;
ListOfListOfString = listOfListOfString;
RegisteredAt = registeredAt;
}
}
}

View File

@ -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<FinanceTransaction> FinanceTransactions { get; set; }
public User(int id, string name, string address, string btcAddress, string ltcAddress, double btcAmount, double ltcAmount, List<FinanceTransaction> 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);
}
}
}

View File

@ -0,0 +1,17 @@
using System.Collections.Generic;
namespace BlueWest.Data
{
public class UserList
{
public List<User> Users;
public UserList(List<User> users)
{
Users = users;
}
public int Length => Users.Count;
}
}

View File

@ -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; }
}
}

View File

@ -1,4 +1,5 @@
using System;
using BlueWest.Data;
using MapTo;
using TestConsoleApp.Data.Models;