diff --git a/test/TestConsoleApp/Data/Models/Profile.cs b/test/TestConsoleApp/Data/Models/Profile.cs
new file mode 100644
index 0000000..898c13a
--- /dev/null
+++ b/test/TestConsoleApp/Data/Models/Profile.cs
@@ -0,0 +1,11 @@
+namespace TestConsoleApp.Data.Models
+{
+ public class Profile
+ {
+ public string FirstName { get; set; }
+
+ public string LastName { get; set; }
+
+ public string FullName => $"{FirstName} {LastName}";
+ }
+}
\ No newline at end of file
diff --git a/test/TestConsoleApp/Data/Models/User.cs b/test/TestConsoleApp/Data/Models/User.cs
index 541c315..550b840 100644
--- a/test/TestConsoleApp/Data/Models/User.cs
+++ b/test/TestConsoleApp/Data/Models/User.cs
@@ -1,15 +1,13 @@
-namespace TestConsoleApp.Data.Models
+using System;
+
+namespace TestConsoleApp.Data.Models
{
public class User
{
public int Id { get; set; }
- public string FirstName { get; set; }
+ public DateTimeOffset RegisteredAt { get; set; }
- public string LastName { get; set; }
-
- public string FullName => $"{FirstName} {LastName}";
-
- public long Key { get; }
+ public Profile Profile { get; set; }
}
}
\ No newline at end of file
diff --git a/test/TestConsoleApp/Program.cs b/test/TestConsoleApp/Program.cs
index ddffa3b..e5ac5f9 100644
--- a/test/TestConsoleApp/Program.cs
+++ b/test/TestConsoleApp/Program.cs
@@ -1,4 +1,6 @@
-using TestConsoleApp.ViewModels;
+using System;
+using TestConsoleApp.Data.Models;
+using TestConsoleApp.ViewModels;
namespace TestConsoleApp
{
@@ -6,8 +8,23 @@ namespace TestConsoleApp
{
private static void Main(string[] args)
{
- var userViewModel = User.From(new Data.Models.User());
- var userViewModel2 = new Data.Models.User().ToUserViewModel();
+ var user = new User
+ {
+ Id = 1234,
+ RegisteredAt = DateTimeOffset.Now,
+ Profile = new Profile
+ {
+ FirstName = "John",
+ LastName = "Doe"
+ }
+ };
+
+ var vm = user.ToUserViewModel();
+
+ Console.WriteLine("Key: {0}", vm.Key);
+ Console.WriteLine("RegisteredAt: {0}", vm.RegisteredAt);
+ Console.WriteLine("FirstName: {0}", vm.Profile.FirstName);
+ Console.WriteLine("LastName: {0}", vm.Profile.LastName);
}
}
}
\ No newline at end of file
diff --git a/test/TestConsoleApp/TestConsoleApp.csproj b/test/TestConsoleApp/TestConsoleApp.csproj
index 274cf0d..047bb19 100644
--- a/test/TestConsoleApp/TestConsoleApp.csproj
+++ b/test/TestConsoleApp/TestConsoleApp.csproj
@@ -3,8 +3,8 @@
Exe
netcoreapp3.1
- 8
- annotations
+ 7.3
+ disable
diff --git a/test/TestConsoleApp/ViewModels/User.cs b/test/TestConsoleApp/ViewModels/ProfileViewModel.cs
similarity index 51%
rename from test/TestConsoleApp/ViewModels/User.cs
rename to test/TestConsoleApp/ViewModels/ProfileViewModel.cs
index bf5410c..67d4b84 100644
--- a/test/TestConsoleApp/ViewModels/User.cs
+++ b/test/TestConsoleApp/ViewModels/ProfileViewModel.cs
@@ -1,14 +1,13 @@
-// using MapTo;
-
-using MapTo;
+using MapTo;
+using TestConsoleApp.Data.Models;
namespace TestConsoleApp.ViewModels
{
- [MapFrom(typeof(Data.Models.User))]
- public partial class User
+ [MapFrom(typeof(Profile))]
+ public partial class ProfileViewModel
{
public string FirstName { get; }
-
+
public string LastName { get; }
}
}
\ No newline at end of file
diff --git a/test/TestConsoleApp/ViewModels/UserViewModel.cs b/test/TestConsoleApp/ViewModels/UserViewModel.cs
index e32b172..50f3f3e 100644
--- a/test/TestConsoleApp/ViewModels/UserViewModel.cs
+++ b/test/TestConsoleApp/ViewModels/UserViewModel.cs
@@ -1,22 +1,24 @@
-using MapTo;
+using System;
+using MapTo;
+using TestConsoleApp.Data.Models;
namespace TestConsoleApp.ViewModels
{
- [MapFrom(typeof(Data.Models.User))]
+ [MapFrom(typeof(User))]
public partial class UserViewModel
{
- public string FirstName { get; }
-
- [IgnoreProperty]
- public string LastName { get; }
-
- [MapTypeConverter(typeof(LastNameConverter))]
+ [MapProperty(SourcePropertyName = nameof(User.Id))]
+ [MapTypeConverter(typeof(IdConverter))]
public string Key { get; }
- private class LastNameConverter : ITypeConverter
+ public DateTimeOffset RegisteredAt { get; set; }
+
+ // [IgnoreProperty]
+ public ProfileViewModel Profile { get; set; }
+
+ private class IdConverter : ITypeConverter
{
- ///
- public string Convert(long source, object[]? converterParameters) => $"{source} :: With Type Converter";
+ public string Convert(int source, object[] converterParameters) => $"{source:X}";
}
}
}
\ No newline at end of file