-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chaowlert
committed
May 26, 2017
1 parent
c436564
commit cb2b752
Showing
19 changed files
with
266 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace Mapster.Adapters | ||
{ | ||
internal class ObjectAdapter : BaseAdapter | ||
{ | ||
protected override int Score => -111; | ||
|
||
protected override bool CanMap(PreCompileArgument arg) | ||
{ | ||
return arg.SourceType == typeof(object) || arg.DestinationType == typeof(object); | ||
} | ||
|
||
protected override Expression CreateBlockExpression(Expression source, Expression destination, CompileArgument arg) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected override Expression CreateInlineExpression(Expression source, CompileArgument arg) | ||
{ | ||
// object, T | ||
|
||
//if (src.GetType() == typeof(object)) | ||
// return (T)src | ||
|
||
//return src.Adapt<T>(); | ||
|
||
// poco, object | ||
|
||
//return (object)src.Adapt<T, T>(); | ||
|
||
// object, object | ||
|
||
//if (src.GetType() == typeof(object)) | ||
// return src; | ||
// return src.Adapt(src.GetType(), src.GetType()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Mapster.Utils; | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
|
||
namespace Mapster.Adapters | ||
{ | ||
internal class StringAdapter : PrimitiveAdapter | ||
{ | ||
protected override int Score => -110; | ||
protected override bool CheckExplicitMapping => false; | ||
|
||
protected override bool CanMap(PreCompileArgument arg) | ||
{ | ||
return arg.SourceType == typeof(string) || arg.DestinationType == typeof(string); | ||
} | ||
|
||
protected override Expression CreateExpressionBody(Expression source, Expression destination, CompileArgument arg) | ||
{ | ||
var sourceType = arg.SourceType; | ||
var destinationType = arg.DestinationType; | ||
|
||
if (sourceType == destinationType) | ||
return source; | ||
|
||
if (destinationType == typeof(string)) | ||
{ | ||
if (sourceType.GetTypeInfo().IsEnum) | ||
{ | ||
var method = typeof(Enum<>).MakeGenericType(sourceType).GetMethod("ToString", new[] { sourceType }); | ||
return Expression.Call(method, source); | ||
} | ||
else | ||
{ | ||
var method = sourceType.GetMethod("ToString", Type.EmptyTypes); | ||
return Expression.Call(source, method); | ||
} | ||
} | ||
else //if (sourceType == typeof(string)) | ||
{ | ||
if (destinationType.GetTypeInfo().IsEnum) | ||
{ | ||
var method = typeof(Enum<>).MakeGenericType(destinationType).GetMethod("Parse", new[] { typeof(string) }); | ||
return Expression.Call(method, source); | ||
} | ||
else | ||
{ | ||
var method = destinationType.GetMethod("Parse", new[] { typeof(string) }); | ||
if (method != null) | ||
return Expression.Call(method, source); | ||
} | ||
} | ||
|
||
return base.ConvertType(source, arg); | ||
} | ||
|
||
protected override Expression CreateBlockExpression(Expression source, Expression destination, CompileArgument arg) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
protected override Expression CreateInlineExpression(Expression source, CompileArgument arg) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace Mapster | ||
{ | ||
public class PreCompileArgument | ||
{ | ||
public Type SourceType; | ||
public Type DestinationType; | ||
public MapType MapType; | ||
public bool ExplicitMapping; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ public enum AccessModifier | |
Private = 1, | ||
Protected = 2, | ||
Internal = 4, | ||
ProtectedInternal = 6, | ||
Public = 8, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.