public TDestination Map<TSource, TDestination>(TSource tSource)
{
if (tSource == null)
return default(TDestination); var mapper = ObjectMapperManager.DefaultInstance.GetMapper<TSource, TDestination>();
return mapper.Map(tSource);
} public IEnumerable<TDestination> MapperGeneric<TSource, TDestination>(IEnumerable<TSource> tSources)
{
if (tSources == null)
return null; IList<TDestination> tDestinations = new List<TDestination>();
foreach (var tSource in tSources)
{
tDestinations.Add(Map<TSource, TDestination>(tSource));
}
return tDestinations;
} public IList<TDestination> MapperGeneric<TSource, TDestination>(IList<TSource> tSources)
{
if (tSources == null)
return null; IList<TDestination> tDestinations = new List<TDestination>();
foreach (var tSource in tSources)
{
tDestinations.Add(Map<TSource, TDestination>(tSource));
}
return tDestinations;
}
using EmitMapper.EmitBuilders;
using EmitMapper.Mappers;
using EmitMapper.MappingConfiguration;
using EmitObjectMapper.Mappers;
using System;
using System.Collections.Generic;
using System.Reflection.Emit; namespace EmitMapper
{
public class ObjectMapperManager
{
public static ObjectMapperManager _defaultInstance = (ObjectMapperManager) null;
private static int _instanceCount = ;
private int instanceCount = ;
private Dictionary<MapperKey, int> objectsMapperIds = new Dictionary<MapperKey, int>();
private List<ObjectsMapperDescr> objectsMappersList = new List<ObjectsMapperDescr>(); public static ObjectMapperManager DefaultInstance
{
get
{
if (ObjectMapperManager._defaultInstance == null)
{
lock (typeof (ObjectMapperManager))
{
if (ObjectMapperManager._defaultInstance == null)
ObjectMapperManager._defaultInstance = new ObjectMapperManager();
}
}
return ObjectMapperManager._defaultInstance;
}
} public ObjectMapperManager()
{
lock (typeof (ObjectMapperManager))
{
++ObjectMapperManager._instanceCount;
this.instanceCount = ObjectMapperManager._instanceCount;
}
} public ObjectsMapper<TFrom, TTo> GetMapper<TFrom, TTo>()
{
return new ObjectsMapper<TFrom, TTo>(this.GetMapperImpl(typeof (TFrom), typeof (TTo), (IMappingConfigurator) DefaultMapConfig.Instance));
} public ObjectsMapper<TFrom, TTo> GetMapper<TFrom, TTo>(IMappingConfigurator mappingConfigurator)
{
return new ObjectsMapper<TFrom, TTo>(this.GetMapperImpl(typeof (TFrom), typeof (TTo), mappingConfigurator));
} public ObjectsMapperBaseImpl GetMapperImpl(Type from, Type to, IMappingConfigurator mappingConfigurator)
{
return this.GetMapperInt(from, to, mappingConfigurator).mapper;
} internal ObjectsMapperDescr GetMapperInt(Type from, Type to, IMappingConfigurator mappingConfigurator)
{
lock (this)
{
if (to == null)
to = typeof (object);
if (from == null)
from = typeof (object);
MapperKey local_0 = new MapperKey(from, to, mappingConfigurator.GetConfigurationName());
int local_2;
if (this.objectsMapperIds.TryGetValue(local_0, out local_2))
return this.objectsMappersList[local_2];
ObjectsMapperDescr local_1 = new ObjectsMapperDescr((ObjectsMapperBaseImpl) null, local_0, );
this.AddMapper(local_1);
string local_3 = this.GetMapperTypeName(from, to);
ObjectsMapperBaseImpl local_4;
if (MapperPrimitiveImpl.IsSupportedType(to))
local_4 = (ObjectsMapperBaseImpl) new MapperPrimitiveImpl(this, from, to, mappingConfigurator);
else if (MapperForCollectionImpl.IsSupportedType(to))
{
ObjectsMapperDescr local_5 = this.GetMapperInt(MapperForCollectionImpl.GetSubMapperTypeFrom(from), MapperForCollectionImpl.GetSubMapperTypeTo(to), mappingConfigurator);
local_4 = (ObjectsMapperBaseImpl) MapperForCollectionImpl.CreateInstance(local_3 + (object) this.GetNextMapperId(), this, from, to, local_5, mappingConfigurator);
}
else
local_4 = this.BuildObjectsMapper(local_3 + (object) this.GetNextMapperId(), from, to, mappingConfigurator);
local_1.mapper = local_4;
return local_1;
}
} private ObjectsMapperBaseImpl BuildObjectsMapper(string MapperTypeName, Type from, Type to, IMappingConfigurator mappingConfigurator)
{
TypeBuilder typeBuilder = DynamicAssemblyManager.DefineMapperType(MapperTypeName);
CreateTargetInstanceBuilder.BuildCreateTargetInstanceMethod(to, typeBuilder);
MappingBuilder mappingBuilder = new MappingBuilder(this, from, to, typeBuilder, mappingConfigurator);
mappingBuilder.BuildCopyImplMethod();
ObjectsMapperBaseImpl objectsMapperBaseImpl = (ObjectsMapperBaseImpl) Activator.CreateInstance(typeBuilder.CreateType());
objectsMapperBaseImpl.Initialize(this, from, to, mappingConfigurator, mappingBuilder.storedObjects.ToArray());
return objectsMapperBaseImpl;
} private ObjectsMapperDescr GetMapperByKey(MapperKey key)
{
return this.objectsMappersList[this.objectsMapperIds[key]];
} private int AddMapper(ObjectsMapperDescr descr)
{
descr.id = this.objectsMappersList.Count;
this.objectsMappersList.Add(descr);
this.objectsMapperIds.Add(descr.key, descr.id);
return descr.id;
} private int GetNextMapperId()
{
return this.objectsMapperIds.Count;
} private bool IsMapperCreated(MapperKey key)
{
return this.objectsMapperIds.ContainsKey(key);
} private string GetMapperTypeKey(Type from, Type to, string mapperName)
{
return this.GetMapperTypeName(from, to) + (mapperName ?? "");
} private string GetMapperTypeName(Type from, Type to)
{
return "ObjectsMapper" + (object) this.instanceCount + "_" + (from == null ? "null" : from.FullName) + "_" + (to == null ? "null" : to.FullName);
}
}
}

private int _rootId;
        /// <summary>
        /// 活动来源ID
        /// </summary>
        public int RootId
        {
            get { return this._rootId; }
            set { this._rootId = value; }
        }

private List<string> _rootId;
        /// <summary>
        /// 活动来源ID
        /// </summary>
        public List<string> RootId
        {
            get { return this._rootId; }
            set
            {
                if (this._rootId == null)
                {
                    this._rootId = new List<string>();
                }
                this._rootId = value;
            }
        }

public string Tip{get;set;}

 private bool _isSelected = false;
    public bool IsSelected
    {

get
    {
_isSelected=Tip == "1" ? true : false;
return _isSelected;
    }
    set
    {
_isSelected = value;
    }
    } 

        private Dictionary<int, string> _shortUrl;
public Dictionary<int, string> ShortUrl {
get
{
_shortUrl= new Dictionary<int, string>()
{
{,"t.cn"},
{,"dwz.cn"},
{,"qq.cn.hn"},
{,"jd.cn.hn"},
{,"tb.cn.hn"},
{,"sina.lt"},
{,"tinyurl.com"},
{,"qr.net"},
{,"goo.gl"},
{,"is.gd"},
{,"j.mp"},
{,"bit.ly"}
};
return _shortUrl;
}
set { _shortUrl = value; }
}

Tuple的使用:

        public Tuple<string, string> DevileryPeriod()
{
switch (this.Cycle)
{
case :
return new Tuple<string, string>("全天", $"{this.SendTime:yyyy-MM-dd} 09:00-21:00");
case :
return new Tuple<string, string>("上午", $"{this.SendTime:yyyy-MM-dd} 09:00-12:00");
case :
return new Tuple<string, string>("下午", $"{this.SendTime:yyyy-MM-dd} 12:00-18:00");
case :
return new Tuple<string, string>("晚上", $"{this.SendTime:yyyy-MM-dd} 18:00-21:00");
default:
return new Tuple<string, string>("全天", $"{this.SendTime:yyyy-MM-dd} 09:00-21:00");
} }
//DliveryWays = t.DevileryPeriod().Item1,
class Program
{
static void Main()
{
Tuple<string, string> name = new Tuple<string, string>("Jochen", "Rindt");
Console.WriteLine(name.ToString()); var result = Divide(, );
Console.WriteLine("result of division: {0}, reminder: {1}", result.Item1, result.Item2); AnyElementNumber();
} static void AnyElementNumber()
{
var tuple = Tuple.Create<string, string, string, int, int, int, double, Tuple<int, int>>(
"Stephanie", "Alina", "Nagel", , , , 1.37, Tuple.Create<int, int>(, ));
Console.WriteLine(tuple.Item1);
} public static Tuple<int, int> Divide(int dividend, int divisor)
{
int result = dividend / divisor;
int reminder = dividend % divisor; return Tuple.Create<int, int>(result, reminder);
}
}

对象关系映射 EmitMapper 及Tuple的使用的更多相关文章

  1. [Python之路] ORM(对象关系映射)

    一.概念 ORM是Python后端Web框架Django的核心思想,"Object Relational Mapping",即对象-关系映射,简称ORM. 一句话理解就是: 创建一 ...

  2. 死去活来,而不变质:Domain Model(领域模型) 和 EntityFramework 如何正确进行对象关系映射?

    写在前面 阅读目录: 设计误区 数据库已死 枚举映射 关联映射 后记 在上一篇<一缕阳光:DDD(领域驱动设计)应对具体业务场景,如何聚焦 Domain Model(领域模型)?>博文中, ...

  3. 解析大型.NET ERP系统数据访问 对象关系映射框架LLBL Gen Pro

    LLBL Gen Pro是一个为.NET开发人员设计的的对象关系映射(ORM)框架,与NHibernate,Entity Framework等框架一样,通过实体与数据表的映射,实现关系数据库持久化. ...

  4. Hibernate(开放源代码的对象关系映射框架)

    Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的orm框架,hibernate可以自动生成SQL语句,自 ...

  5. ORM即 对象-关系映射(转自:微冷的雨)

    ORM即 对象-关系映射: 将数据库中的数据关系表,映射为实体对象. 灵动思绪EF(Entity FrameWork) 作者: 微冷的雨  来源: 博客园  发布时间: 2013-01-22 16:2 ...

  6. LLBL Gen Pro 4.2 Lite 免费的对象关系映射开发框架与工具

    LLBL Gen Pro是一款优秀的对象关系映射开发框架,自2003年发布以来,一直有广泛的客户群.LLBL Gen Pro有几个标志性的版本,2.5/2.6是一个很稳定的版本,公司的一些旧的项目仍然 ...

  7. hibernate(四)__由表逆向创建Domain对象和对象关系映射文件

    之前我们是手写Domain对象和对象关系映射文件->然后生成数据库中的Table. 现在我们反过来先在数据库中建好Table->然后用工具生成Domain对象和对象关系映射文件. 步骤: ...

  8. 对象关系映射ORM

    对象关系映射(英语:Object Relational Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换.从效 ...

  9. android对象关系映射框架ormlite之一对多(OneToMany)

    前两天,用ormlite对单张表进行了基本的操作,但是,我们知道通常情况对于单张表格进行操作在实际情况中很前两天不现实,那么ormlite能否像Hibenate那样实现多张表之间的一对多,多对多(即O ...

随机推荐

  1. POJ 1776 Task Sequences(竞赛图构造哈密顿通路)

    链接:http://poj.org/problem?id=1776 本文链接:http://www.cnblogs.com/Ash-ly/p/5458635.html 题意: 有一个机器要完成一个作业 ...

  2. kattis Curious Cupid (莫队算法)

    Curious Cupid There are K different languages in the world. Each person speaks one and only one lang ...

  3. [HDU5739]Fantasia(圆方树DP)

    题意:给一张无向点带有权无向图.定义连通图的权值为图中各点权的乘积,图的权值为其包含的各连通图的权和.设z_i为删除i点后图的权值,求$S = (\sum\limits_{i=1}^{n}i\cdot ...

  4. 【动态规划】Gym - 100507G - The Debut Album

    一般思路的dp是用f(i,j,0)表示前i位最后有j个1的方案数,用f(i,j,1)表示前j位最后有j个2的方案数,j都是大于等于1的,然后比较容易转移. 但这题卡内存,就只能用f(i,j)表示前i位 ...

  5. python3-开发面试题(python)6.23基础篇(2)

    1.请至少列举5个 PEP8 规范(越多越好). 一.代码编排 1.缩进.4个空格的缩进,不使用Tap,更不能混合使用Tap和空格 2.每行最大长度79,换行可以使用反斜杠,最好使用圆括号.换行点要在 ...

  6. [CF930E]/[CF944G]Coins Exhibition

    [CF930E]/[CF944G]Coins Exhibition 题目地址: CF930E/CF944G 博客地址: [CF930E]/[CF944G]Coins Exhibition - skyl ...

  7. 五角数 Exercise06_01

    /** * @author 冰樱梦 * 题目:五角数 * 时间:2018年下半年 * * */ public class Exercise06_01 { public static void main ...

  8. Java二进制指令代码解析

    http://www.blogjava.net/DLevin/archive/2011/09/13/358497.html http://blog.csdn.net/sum_rain/article/ ...

  9. Oracle导入本属于sys用户的表

    FlashBack Database后,将删除的数据导出时使用了system用户 exp system/oracle file=/home/oracle/test.dmp tables=sys.tes ...

  10. cs-JsonHelper

    ylbtech-Unitity: cs-JsonHelper AjaxResult.cs  FormatJsonExtension.cs 1.A,效果图返回顶部   1.B,源代码返回顶部 1.B.1 ...