1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- /*-------------------------------------------------------------------------
- * 功能描述:RelationshipBase
- * 作者:xulisong
- * 创建时间: 2019/6/17 9:24:42
- * 版本号:v1.0
- * -------------------------------------------------------------------------*/
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- namespace JBIM.Relationship
- {
- /*
- * 关系有个组织类别。一对一,或者一对多
- *
- * 比如:Connector所属关系一对一,Connector关联关系一对多
- *
- * 关系分成两类:由属性定义的关系,直接有关系表定义的关系
- * a、由属性定义的关系,可以自动解析,属性键值,反射找到对应的属性进行赋值
- * b、关系表定义的关系,直接加入document
- *
- * 通过关系名称进行反射,获取相应的值进行赋值,或者在List集合中加入相关项;
- *
- * 开放自定义关系:
- */
- /// <summary>
- /// 关系基类
- /// </summary>
- public class RelationshipBase: BimObject
- {
- public RelationshipBase()
- {
- IsProperty = true;
- this.ElementType = TypeDefinition.Relationship.ToString();
- }
- /// <summary>
- /// 标志关系是否由属性定义
- /// </summary>
- public bool IsProperty { get;protected set; }
- public void SetPropertyName(string propertyName)
- {
- PropertyName = propertyName;
- }
- public void SetElementType(TypeDefinition type)
- {
- this.ElementType = type.ToString();
- PropertyName = type.GetDescription();
- }
- public string PropertyName { get; private set; }
- public virtual void AcceptRelation(BimObject bimObject)
- {
- if (!IsProperty)
- {
- return;
- }
- AcceptRelationInner(bimObject);
- }
- protected virtual void AcceptRelationInner(BimObject bimObject)
- {
- }
- protected PropertyInfo ParseProperty(BimObject bimObject)
- {
- var type = bimObject.GetType();
- string propertyName = PropertyName;
- var key = type.FullName + "_" + propertyName;
- var propertyInfo = PropertyCache.GetProperty(key);
- if (propertyInfo == null)
- {
- //缓存解析出来的属性元数据,以便提高解析速度
- var property = type.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public);
- PropertyCache.SetProperty(key,property);
- }
- return propertyInfo;
- }
- }
- }
|