XAF-DevExpress.ExpressApp.DC.Xpo.XpoTypeInfoSource 生成实体的过程-学习笔记
//目的,想自己生成实体类,不走dc的生成机制,所以研究一下此方法。
public void GenerateEntities(string generatedAssemblyFile) { lock (this.lockObjectForDC) {
//此数组为要生成代码的接口类型 Type[] entityInterfaces = this.entitiesToGenerateInfo.GetEntityInterfaces(); if (!this.IsAlreadyBuild && (entityInterfaces.Length > 0)) {
//生成过了,且有实体接口,有文件的情况下,直接加载 if (File.Exists(generatedAssemblyFile)) { this.generatedAssembly = Assembly.LoadFrom(generatedAssemblyFile); } else {
//没有文件,马上生成一个。 DCBuilder builder = new DCBuilder(this.typesInfo); builder.Setup(this.entitiesToGenerateInfo, this.customLogics, this.existingImplementorsInfo); this.generatedAssembly = builder.GetAssembly(generatedAssemblyFile); } this.ProcessGeneratedAssembly(this.generatedAssembly);
//遍历所有的实体类,即接口定义 Dictionary<Type, object> dictionary = new Dictionary<Type, object>(); foreach (Type type in entityInterfaces) {
//没处理过的 if (!dictionary.ContainsKey(type)) { dictionary.Add(type, null);
//标记为处理过。
//处理“基”接口 foreach (Type type2 in type.GetInterfaces()) {
//已经注册过的实体类中包含这个接,且,没处理过此接口时,把基接口也加进来 if (this.registeredEntityTypes.Contains(type2) && !dictionary.ContainsKey(type2)) { dictionary.Add(type2, null); } } } }
foreach (Type type3 in dictionary.Keys) {
//上面收集到了所有需要用到的接口,刷新类型信息。使用实际类型查找接口 this.typesInfo.RefreshInfo(type3); Type entityTypeByInterface = this.GetEntityTypeByInterface(type3); if (entityTypeByInterface != null) { this.typesInfo.RefreshInfo(entityTypeByInterface); foreach (TypeInfo info in this.typesInfo.FindTypeInfo(entityTypeByInterface).RequiredTypes) { info.Refresh(true); } } Type dataTypeByInterface = this.GetDataTypeByInterface(type3); if (dataTypeByInterface != null) { this.typesInfo.RefreshInfo(dataTypeByInterface); } }
foreach (Type type6 in this.generatedAssembly.GetExportedTypes()) { if (this.TypeIsKnown(type6)) { TypeInfo info2 = this.typesInfo.FindTypeInfo(type6); if ((info2 != null) && (info2.Source != this)) { info2.Source = this; this.typesInfo.RefreshInfo(type6);
//类typeinfo附source的值,即TypeInfoSource } } } } } }
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端