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. Python3 数字

    layout: post title: Python3 数字 author: "luowentaoaa" catalog: true tags: mathjax: true Pyt ...

  2. 差分+树状数组 线段树【P2357】 守墓人

    题目描述-->p2357 守墓人 敲了一遍线段树,水过. 树状数组分析 主要思路: 差分 简单介绍一下差分(详细概念太麻烦,看下面. 给定一个数组 7 8 6 5 1 8 18 20 35 // ...

  3. Compare, sort, and delete duplicate lines in Notepad ++

    Compare, sort, and delete duplicate lines in Notepad ++ Organize Lines: Since version 6.5.2 the app ...

  4. 小型Web应用扫描工具Grabber

    小型Web应用扫描工具Grabber   Grabber是Kali Linux集成的一款Web应用扫描工具.该工具适合中小Web应用,如个人博客.论坛等.该工具使用Python语言编写,支持常见的漏洞 ...

  5. luogu P1056 排座椅

    题目描述 上课的时候总会有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情.不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的D对同学上课时会交头接耳.同学 ...

  6. 【平面图】【最小割】【最短路】【Heap-Dijkstra】bzoj1001 [BeiJing2006]狼抓兔子

    http://wenku.baidu.com/view/8f1fde586edb6f1aff001f7d.html #include<cstdio> #include<queue&g ...

  7. 【记忆化搜索】bzoj3208 花神的秒题计划Ⅰ

    暴力 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #de ...

  8. 焦点改变事件OnFocusChangeListener

    效果图 1.MainActivity.java package com.example.app2; import android.support.v7.app.AppCompatActivity; i ...

  9. Mac SublimeREPL 插件安装使用及解决各种坑

    虽然网上教程一大堆,然而都不全面,遇到的各种坑的情况都没写. 一.安装 前提是你安装了Package Control,见Mac Sublime Text 3 配置Python环境及安装插件 Prefe ...

  10. JNI之数组

    Array Operations -- 数组操作 1.GetArrayLength jsize GetArrayLength(JNIEnv *env, jarray array); Returns t ...