using HStation.RevitDev.Model.AttributeClass;
|
using HStation.RevitDev.Model.ModelEnum;
|
using HStation.RevitDev.RevitDataExport.Common;
|
using HStation.RevitDev.RevitDataExport.Entity;
|
using System;
|
using System.Reflection;
|
|
namespace HStation.RevitDev.RevitDataExport.Utility
|
{
|
public static class RevitTypeExtense
|
{
|
public static bool IsRequired(this RevitType type)
|
{
|
var config = GlobalResource.ConfigModel;
|
var props = config.GetType().GetProperties();
|
|
foreach (var prop in props)
|
{
|
var attrs = prop.GetCustomAttributes(false);
|
if (attrs.Length > 0)
|
{
|
var attr = attrs[0] as RevitTypeAttribute;
|
if (attr.m_revitType == type)
|
{
|
bool? isRequired = prop.GetValue(config) as bool?;
|
if (isRequired == true)
|
{
|
return true;
|
}
|
return false;
|
}
|
}
|
}
|
|
return false;
|
}
|
|
public static Type GetElementModelType(this RevitType revitType)
|
{
|
var exportTypes = revitType.GetType().Assembly.GetExportedTypes();
|
foreach (var type in exportTypes)
|
{
|
if (!type.IsSubclassOf(typeof(ModelBase))) { continue; }
|
|
var attr = type.GetCustomAttribute<RevitTypeAttribute>();
|
if (attr == null) { continue; }
|
|
var rvtType = attr.m_revitType;
|
if (rvtType == revitType)
|
{
|
return type;
|
}
|
}
|
return null;
|
}
|
}
|
}
|