using HStation.RevitDev.Model.AttributeClass; using HStation.RevitDev.Model.ModelEnum; using HStation.RevitDev.RevitDataExport.Parser; using System.Reflection; namespace HStation.RevitDev.RevitDataExport.Utility { public static class ParserUtils { public static RevitType GetRevitType(this BaseParser parser) { if (parser == null) { return RevitType.RFT_Others; } var type = parser.GetType(); var attr = type.GetCustomAttributes(false)?[0]; if (attr == null) { return RevitType.RFT_Others; } if (attr is RevitTypeAttribute rtAttr) { return rtAttr.m_revitType; } return RevitType.RFT_Others; } public static BaseParser GetParser(this RevitType type) { var parsers = ParserManager.Instance.Parsers; foreach (var parser in parsers) { var parserType = parser.GetType(); var attr = parserType.GetCustomAttribute(); if (attr == null) { continue; } if (type == attr.m_revitType) { return parser; } } return null; } } }