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. MySQL逻辑架构简介

    1.Connectors指的是不同语言中与SQL的交互2 Management Serveices & Utilities: 系统管理和控制工具3 Connection Pool: 连接池管理 ...

  2. 训练指南 UVALive - 4287 (强连通分量+缩点)

    layout: post title: 训练指南 UVALive - 4287 (强连通分量+缩点) author: "luowentaoaa" catalog: true mat ...

  3. Codeforces #447 Div2 E

    #447 Div2 E 题意 给出一个由有向边构成的图,每条边上有蘑菇,假设有 \(n\) 个蘑菇,那么第一次走过这条边可以获得 \(n\) 个蘑菇,第二次 \(n-1\),第三次 \(n-1-2\) ...

  4. 26、Django实战第26天:配置全局导航

    1.编辑index.html,继承base.html 2.编辑base.html,根据是否登录不同显示 问题:当我们选中一个导航,选中样式并没有成为选中的状态 因此我们编辑base.html对导航中进 ...

  5. 【分类讨论】bzoj3856 Monster

    #include<cstdio> using namespace std; int T=0; long long h,a,b,k; int main() { freopen("b ...

  6. 【DFS序】【莫队算法】【权值分块】bzoj2809 [Apio2012]dispatching

    题意:在树中找到一个点i,并且找到这个点子树中的一些点组成一个集合,使得集合中的所有点的c之和不超过M,且Li*集合中元素个数和最大 首先,我们将树处理出dfs序,将子树询问转化成区间询问. 然后我们 ...

  7. [CF930E]/[CF944G]Coins Exhibition

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

  8. STL之search

    描述 使用STL中的search函数,判断一个序列是否是另一个序列的子序列. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. int main() { vector<int> ...

  9. golang的reflect

    引用自 http://www.jb51.net/article/115002.htm 和 C 数据结构一样,Go 对象头部并没有类型指针,通过其自身是无法在运行期获知任何类型相关信息的.反射操作所需要 ...

  10. ubuntu下python3及idle3的安装

    一.使用以下命令检查自己的系统下是否有python3 python3 --version 如果出现类似“command not found",则说明你需要安装python3.如果能够出现py ...