Even more revit fixes (#12)
* get parameter should null check * get element can be null * add more to proxy map
This commit is contained in:
@@ -31,10 +31,15 @@ public partial interface IRevitElementProxy : IRevitElement;
|
||||
|
||||
public partial class ElementProxy
|
||||
{
|
||||
public IRevitParameter GetParameter(RevitBuiltInParameter builtInParameter) =>
|
||||
new ParameterProxy(
|
||||
_Instance.get_Parameter(EnumUtility<RevitBuiltInParameter, BuiltInParameter>.Convert(builtInParameter))
|
||||
);
|
||||
public IRevitParameter? GetParameter(RevitBuiltInParameter builtInParameter)
|
||||
{
|
||||
var param = _Instance.get_Parameter(EnumUtility<RevitBuiltInParameter, BuiltInParameter>.Convert(builtInParameter));
|
||||
if (param is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ParameterProxy(param);
|
||||
}
|
||||
|
||||
public IRevitBoundingBoxXYZ GetBoundingBox() => new BoundingBoxXYZProxy(_Instance.get_BoundingBox(null));
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public partial interface IRevitParameterProxy : IRevitParameter;
|
||||
public partial class ParameterProxy
|
||||
{
|
||||
public bool IsReadOnly => _Instance.IsReadOnly;
|
||||
public IRevitStorageType StorageType => EnumUtility<StorageType, IRevitStorageType>.Convert(_Instance.StorageType);
|
||||
public RevitStorageType StorageType => EnumUtility<StorageType, RevitStorageType>.Convert(_Instance.StorageType);
|
||||
}
|
||||
|
||||
[Proxy(typeof(Definition), ImplementationOptions.UseExtendedInterfaces | ImplementationOptions.ProxyForBaseInterface)]
|
||||
|
||||
@@ -101,7 +101,7 @@ public partial class FilteredElementCollectorProxy
|
||||
public IEnumerable<T> OfClass<T>(IProxyMap proxyMap) =>
|
||||
_Instance
|
||||
.OfClass(
|
||||
proxyMap.UnmapType(typeof(T))
|
||||
proxyMap.GetHostTypeFromMappedType(typeof(T))
|
||||
?? throw new InvalidOperationException($"Could not unmap type: {typeof(T).FullName}")
|
||||
)
|
||||
.Select(x => proxyMap.CreateProxy(typeof(T), x))
|
||||
|
||||
@@ -8,5 +8,5 @@ public interface IRevitDocument : IRevitObject
|
||||
bool IsFamilyDocument { get; }
|
||||
IRevitUnits GetUnits();
|
||||
|
||||
IRevitElement GetElement(IRevitElementId elementId);
|
||||
IRevitElement? GetElement(IRevitElementId elementId);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public interface IRevitParameter
|
||||
int AsInteger();
|
||||
double AsDouble();
|
||||
IRevitElementId? AsElementId();
|
||||
IRevitStorageType StorageType { get; }
|
||||
RevitStorageType StorageType { get; }
|
||||
IRevitForgeTypeId GetUnitTypeId();
|
||||
IRevitDefinition Definition { get; }
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public interface IRevitInternalDefinition : IRevitDefinition
|
||||
RevitBuiltInParameter BuiltInParameter { get; }
|
||||
}
|
||||
|
||||
public enum IRevitStorageType
|
||||
public enum RevitStorageType
|
||||
{
|
||||
None,
|
||||
Integer,
|
||||
|
||||
@@ -22,8 +22,9 @@ public interface IRevitFilterFactory
|
||||
|
||||
public interface IProxyMap
|
||||
{
|
||||
Type? GetMappedType(Type type);
|
||||
Type? UnmapType(Type type);
|
||||
Type? GetMappedTypeFromHostType(Type type);
|
||||
Type? GetMappedTypeFromProxyType(Type type);
|
||||
Type? GetHostTypeFromMappedType(Type type);
|
||||
|
||||
object CreateProxy(Type type, object toWrap);
|
||||
}
|
||||
@@ -33,10 +34,15 @@ public static class ProxyMapExtensions
|
||||
{
|
||||
public static (Type, object)? WrapIfExists(this IProxyMap proxyMap, Type target, object toWrap)
|
||||
{
|
||||
var proxyType = proxyMap.GetMappedType(target);
|
||||
if (proxyType is not null)
|
||||
var mappedType = proxyMap.GetMappedTypeFromHostType(target);
|
||||
if (mappedType is not null)
|
||||
{
|
||||
return (proxyType, proxyMap.CreateProxy(proxyType, toWrap));
|
||||
return (mappedType, proxyMap.CreateProxy(mappedType, toWrap));
|
||||
}
|
||||
mappedType = proxyMap.GetMappedTypeFromProxyType(target);
|
||||
if (mappedType is not null)
|
||||
{
|
||||
return (mappedType, toWrap);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user