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

推荐订阅源

Martin Fowler
Martin Fowler
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
N
Netflix TechBlog - Medium
G
Google Developers Blog
L
LangChain Blog
腾讯CDC
大猫的无限游戏
大猫的无限游戏
U
Unit 42
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
小众软件
小众软件
The GitHub Blog
The GitHub Blog
博客园_首页
GbyAI
GbyAI

博客园 - 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)    收藏  举报

刷新页面返回顶部