I found the second resource while trying to find out how to handle ParameterType.Text in Revit 2022. The first link I somehow overlooked. It does contain a lot of useful information that will likely come in handy in the future to correctly implement the new ForgeTypeId everywhere.
I am working on this wrapper class that hopefully will be able to handle the ParameterType changes in a transparent manner so that I do not have to put #if statements all throughout the code, but instead move everything regarding the parameter type to this class.
public class ParType
{
#if R2022
private readonly ForgeTypeId _ftype;
public bool IsValid
{
get
{
if (null == _ftype) return false;
if (SpecTypeId.String.Text == _ftype) return true;
PropertyInfo[] props = typeof(SpecTypeId).GetProperties();
foreach (PropertyInfo pi in props)
{
if (!(pi.GetValue(null) is ForgeTypeId val)) continue;
if (val.NameEquals(_ftype)) return true;
}
return false;
}
}
public static readonly ParType Angle = new ParType(SpecTypeId.Angle);
public static readonly ParType Area = new ParType(SpecTypeId.Area);
//public static readonly ParType FixtureUnit = new ParType(SpecTypeId.FixtureUnit);
public static readonly ParType Integer = new ParType(SpecTypeId.Int.Integer);
//public static readonly ParType Invalid = new ParType(SpecTypeId.Invalid);
public static readonly ParType Length = new ParType(SpecTypeId.Length);
public static readonly ParType Number = new ParType(SpecTypeId.Number);
public static readonly ParType Text = new ParType(SpecTypeId.String.Text);
public static readonly ParType Volume = new ParType(SpecTypeId.Volume);
public static readonly ParType YesNo = new ParType(SpecTypeId.Boolean.YesNo);
public static explicit operator ForgeTypeId(ParType pt)
{
return pt._ftype;
}
public ParType(ForgeTypeId fti)
{
_ftype = fti;
}
public ParType(Definition def)
{
if (null == def) return;
_ftype = def.GetDataType();
}
#else
The part after the #else is the implementation using ParameterType for older versions of Revit.
The static values are the types that are explicitly tested in the legacy code. Thankfully I do not have to implement every possibly SpecTypeId (as that would rather defeat the point of having a wrapper and move to using ForgeTypeId).
I still need to add an IComparable<> and IEquatable<> implementation but those are trivial.