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. 奶牛与农夫John与oj

    当蒟蒻的我悲惨的发现oj出现大量的奶牛与农夫时,觉得早晚usaco要占领oj,于是绝望的开始记录农夫与奶牛的题目……. 一道usaco月赛的题…在oj用作练习二维数组,虽然数据的大量字符确实很让人不爽 ...

  2. 完全背包【p1832】A+B Problem(再升级)

    Description 给定一个正整数n,求将其分解成若干个素数之和的方案总数. Input 一行:一个正整数n Output 一行:一个整数表示方案总数 素数之和 ? 背包啊. 没一遍切的题都不是水 ...

  3. 洛谷——P1604 B进制星球

    P1604 B进制星球 题目背景 进制题目,而且还是个计算器~~ 题目描述 话说有一天,小Z乘坐宇宙飞船,飞到一个美丽的星球.因为历史的原因,科技在这个美丽的星球上并不很发达,星球上人们普遍采用B(2 ...

  4. 23、Flask实战第23天:Flask-Restful

    Restful API规范 restful api是用于前端和后台进行通信的一套规范.使用这个规范可以让前后端开发变得更加轻松. 协议 采用http或者https 数据传输格式 数据之间传输的格式应该 ...

  5. [BZOJ 3152] 组合子逻辑

    Link: BZOJ 3152 传送门 Solution: 喜闻乐见,gyz出的语文题,题意要看半小时 题意:使用最少的括号将序列分割,对于每个括号中的序列,设最左边的数为$num$,序列中元素个数为 ...

  6. 洛谷 P2066 机器分配

     题目背景 Background 无  题目描述 Description 总公司拥有高效设备M台,准备分给下属的N个分公司.各分公司若获得这些设备,可以为国家提供一定的盈利.问:如何分配这M台设备才能 ...

  7. 【读书笔记】Elasticsearch集成Hadoop最佳实践

    前言 本文记录[Elasticsearch集成Hadoop最佳实战]读书笔记 本书总计209页,共7章节,计划时间:20180712-20180717 (每天至少40页) 本文代码地址: https: ...

  8. 调用上一个页面的js方法

    点击商品分类,弹出下框 点击确定,将选中的类别的name和唯一的code返回到上个页面 function save(){ var ids = getIdSelections(); jp.get(&qu ...

  9. Mybatis通过ID查询 && 通过name模糊查询

    接上篇:Mybatis环境搭建 在搭建环境时已经有了mapper和sqlMapConfig 1,数据库建表 prompt PL/SQL Developer import file prompt Cre ...

  10. 线程协作-CountDownLatch

    CountDownLatch允许一个或多个线程等待其他线程完成操作.