public TDestination Map(
TSource realObject,
TDestination dtoObject = default (TDestination),
Dictionary alreadyInitializedObjects = null,
bool shouldMapInnerEntities = true)
where TSource : class, new()
where TDestination : class, new()
{
if (realObject == null)
{
returnnull;
}
if (alreadyInitializedObjects == null)
{
alreadyInitializedObjects = new Dictionary();
}
if (dtoObject == null)
{
dtoObject = new TDestination();
}
var realObjectType = realObject.GetType();
PropertyInfo[] properties = realObjectType.GetProperties();
foreach (PropertyInfo currentRealProperty in properties)
{
PropertyInfo currentDtoProperty = dtoObject.GetType().GetProperty(currentRealProperty.Name);
if (currentDtoProperty == null)
{
////Debug.WriteLine("The property {0} was not found
////in the DTO object in order to be mapped.
/// Because of that we skip to map it.", currentRealProperty.Name);
}
else
{
if (this.MappingTypes.ContainsKey
(currentRealProperty.PropertyType) && shouldMapInnerEntities)
{
object mapToObject = this.mappingTypes[currentRealProperty.PropertyType];
var types = new Type[] { currentRealProperty.PropertyType, (Type)mapToObject };
MethodInfo method = GetType().GetMethod("Map").MakeGenericMethod(types);
var realObjectPropertyValue = currentRealProperty.GetValue(realObject, null);
var objects = new object[]
{
realObjectPropertyValue,
null,
alreadyInitializedObjects,
shouldMapInnerEntities
};
if (objects != null && realObjectPropertyValue != null)
{
if (alreadyInitializedObjects.ContainsKey
(realObjectPropertyValue) && currentDtoProperty.CanWrite)
{
// Set the cached version of the same object (optimization)
currentDtoProperty.SetValue(dtoObject, alreadyInitializedObjects
[realObjectPropertyValue]);
}
else
{
// Add the object to cached objects collection.
alreadyInitializedObjects.Add(realObjectPropertyValue, null);
// Recursively call Map method again to get the new proxy object.var newProxyProperty = method.Invoke(this, objects);
if (currentDtoProperty.CanWrite)
{
currentDtoProperty.SetValue(dtoObject, newProxyProperty);
}
if (alreadyInitializedObjects.ContainsKey(realObjectPropertyValue)
&& alreadyInitializedObjects[realObjectPropertyValue] == null)
{
alreadyInitializedObjects[realObjectPropertyValue] = newProxyProperty;
}
}
}
elseif (realObjectPropertyValue == null && currentDtoProperty.CanWrite)
{
// If the original value of the object was null set null to the destination property.
currentDtoProperty.SetValue(dtoObject, null);
}
}
elseif (!this.MappingTypes.ContainsKey(currentRealProperty.PropertyType))
{
// If the property is not custom type just set normally the value.if (currentDtoProperty.CanWrite)
{
currentDtoProperty.SetValue
(dtoObject, currentRealProperty.GetValue(realObject, null));
}
}
}
}
return dtoObject;
}
首先,它获取源对象的属性。
隐藏复制代码
var realObjectType = realObject.GetType();
PropertyInfo[] properties = realObjectType.GetProperties();
elseif (!this.MappingTypes.ContainsKey(currentRealProperty.PropertyType))
{
// If the property is not custom type just set normally the value.if (currentDtoProperty.CanWrite)
{
currentDtoProperty.SetValue(dtoObject, currentRealProperty.GetValue(realObject, null));
}
}
public class Power {
/**
*Q71-数值的整数次方
*实现函数double Power(double base, int exponent),求base的exponent次方。不需要考虑溢出。
*/
private static boolean InvalidInput=false;
public static void main(
实现两个WEB之间通过session 共享数据
查看tomcat 关于 HTTP Connector 中有个emptySessionPath 其解释如下:
If set to true, all paths for session cookies will be set to /. This can be useful for portlet specification impleme
Parses a raw HTTP request using yii\helpers\Json::decode()
To enable parsing for JSON requests you can configure yii\web\Request::$parsers using this class:
'request' =&g
Sort a linked list in O(n log n) time using constant space complexity.
====analysis=======
mergeSort for singly-linked list
====code======= /**
* Definition for sin
我使用的是ubuntu13.04系统,在安装nginx的时候遇到如下几个问题,然后找思路解决的,nginx 的下载与安装
wget http://nginx.org/download/nginx-1.0.11.tar.gz
tar zxvf nginx-1.0.11.tar.gz
./configure
make
make install
安装的时候出现
在系统开发过程中,总少不免要自己处理一些异常信息,然后将异常信息变成友好的提示返回到客户端的这样一个过程,之前都是new一个自定义的异常,当然这个所谓的自定义异常也是继承RuntimeException的,但这样往往会造成异常信息说明不一致的情况,所以就想到了用枚举来解决的办法。
1,先创建一个接口,里面有两个方法,一个是getCode, 一个是getMessage
public