惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
WordPress大学
WordPress大学
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
博客园 - Franky
博客园 - 司徒正美
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
Jina AI
Jina AI
Last Week in AI
Last Week in AI
雷峰网
雷峰网
IT之家
IT之家
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V
V2EX

博客园 - thh

svm资料收集 向量空间及其他相关数学结构 难题--autoconf、automake、libtool Linq 中不爽之处 关于UI设计的文章汇总 Window Live Writer LR 剖析器 MVP模式中的P和V关系 Guid、Int、BigInt编号的速度和存储空间的比较 静态构造函数线程安全的几个版本[转载] 区域性 ID 2155 (0x086B)不是受支持的区域性 解决方法 windbg给clr设置断点 python ip和int 互转函数 interface与pojo类之间的关系 关于OpenId Python SOAPpy访问asp.net web service 代码 Python SOAPpy 和 .net WebService NHibernate 代码生成工具 NHibernate使用笔记
Type.GetType 获得本Assembly以外的类型
thh · 2007-03-16 · via 博客园 - thh

   简而言之,就是相应AppDomain.的AssemblyResolve实现的。
   DynAssembly提供给动态载入的模块提供一个解析名字的机会。如下代码可以把NHibernate 的Hbm.xml 生成 数据库结构。

using System;
using System.Collections.Generic;
using System.Text;
using NHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace Hbm2Sql
{
    
class DynAssembly
    
{
        System.Reflection.Assembly _asm;

        
public DynAssembly(System.Reflection.Assembly asm)
        
{
            
this._asm = asm;
            AppDomain.CurrentDomain.AssemblyResolve 
+= new ResolveEventHandler(this.TypeResolve);
        }


        
public System.Reflection.Assembly TypeResolve(object sender, ResolveEventArgs args)
        
{
            
if (_asm.FullName.Contains(args.Name))
            
{
                
return _asm;
            }

            
return null;
        }

    }


    
class Program
    
{
        
static void Main(string[] args)
        
{
            
try
            
{
                
if (args.Length > 0)
                
{
                    System.Console.Write(
"命令行:");
                    System.Console.WriteLine(
string.Join(" ",args));

                    System.Reflection.Assembly asm 
= AppDomain.CurrentDomain.Load(System.Reflection.AssemblyName.GetAssemblyName(args[0]));
                    
new DynAssembly(asm);
                    NHibernate.Cfg.Configuration cfg 
= new Configuration().Configure()
                                                        .AddAssembly(asm);
                    SchemaExport export 
= new SchemaExport(cfg);
                    export.Create(
truefalse);
                }

            }

            
catch (System.Exception e)
            
{
                System.Console.Write(e.ToString());
            }

            
finally
            
{
                System.ConsoleKeyInfo i 
= System.Console.ReadKey();
            }

        }

    }

}

 posted on 2007-03-16 02:00  thh  阅读(1407)  评论(0)    收藏  举报

刷新页面返回顶部