/// <summary> /// Create a new FieldData object /// </summary> /// <param name="name">The name of the field</param> /// <param name="typeIn">The AssemblyQualifiedName of the Field's data type</param> /// <param name="unit">The unit type of the Field (set to UT_Undefined for non-floating point types</param> /// <param name="subSchema">The SchemaWrapper of the field's subSchema, if the field is of type "Entity"</param> public FieldData(string name, string typeIn, UnitType unit, SchemaWrapper subSchema) { m_Name = name; m_Type = typeIn; m_Unit = unit; m_SubSchema = subSchema; }
/// <summary> /// Creates a new SchemaWrapper from an XML file on disk /// </summary> /// <param name="xmlDataPath">The path to the XML file containing a schema definition</param> /// <returns>A new SchemaWrapper</returns> public static SchemaWrapper FromXml(string xmlDataPath) { XmlSerializer sampleSchemaInXml = new XmlSerializer(typeof(SchemaWrapper)); Stream streamXmlIn = new FileStream(xmlDataPath, FileMode.Open, FileAccess.Read, FileShare.Read); SchemaWrapper wrapperIn = null; try { wrapperIn = sampleSchemaInXml.Deserialize(streamXmlIn) as SchemaWrapper; } catch (Exception ex) { Debug.WriteLine("Could not deserialize schema file." + ex.ToString()); return(null); } wrapperIn.SetRevitAssembly(); streamXmlIn.Close(); try { wrapperIn.FinishSchema(); } catch (Exception ex) { Debug.WriteLine("Could not create schema." + ex.ToString()); return(null); } return(wrapperIn); }
/// <summary> /// Create a new FieldData object /// </summary> /// <param name="name">The name of the field</param> /// <param name="typeIn">The AssemblyQualifiedName of the Field's data type</param> /// <param name="spec">The unit type of the Field (set to UT_Undefined for non-floating point types</param> /// <param name="subSchema">The SchemaWrapper of the field's subSchema, if the field is of type "Entity"</param> public FieldData(string name, string typeIn, string spec, SchemaWrapper subSchema) { m_Name = name; m_Type = typeIn; m_Spec = spec; m_SubSchema = subSchema; }
/// <summary> /// Creates a new SchemaWrapper from an existing schema. /// </summary> /// <param name="schema">A schema to create a wrapper from</param> /// <returns>A new SchemaWrapper containing all data in the schema</returns> public static SchemaWrapper FromSchema(Schema schema) { SchemaWrapper swReturn = new SchemaWrapper(schema); foreach (Field currentField in schema.ListFields()) { //We need to add call AddField on the SchemaWrapper we are creating for each field in the source schema. //Since we do not know the data type of the field yet, we need to get the generic method first and //then query the field data types from the field and instantiate a new generic method with those types as parameters. //Get the "AddField" method. MethodInfo addFieldmethod = typeof(SchemaWrapper).GetMethod("AddField", new Type[] { typeof(string), typeof(ForgeTypeId), typeof(SchemaWrapper) }); Type[] methodGenericParameters = null; //Get the generic type parameters. The type will either be a single type, an IList<> of a single type, or an IDictionary<> of a key type and a value type. if (currentField.ContainerType == ContainerType.Simple) { methodGenericParameters = new Type[] { currentField.ValueType } } ; else if (currentField.ContainerType == ContainerType.Array) { methodGenericParameters = new Type[] { typeof(IList <int>).GetGenericTypeDefinition().MakeGenericType(new Type[] { currentField.ValueType }) } } ; else { methodGenericParameters = new Type[] { typeof(Dictionary <int, int>).GetGenericTypeDefinition().MakeGenericType(new Type[] { currentField.KeyType, currentField.ValueType }) } }; //Instantiate a new generic method from the "AddField" method we got before with the generic parameters we got //from the current field we are querying. MethodInfo genericAddFieldMethodInstantiated = addFieldmethod.MakeGenericMethod(methodGenericParameters); SchemaWrapper swSub = null; //Our subSchema is null by default unless the field is of type "Entity," in which case //we will call "FromSchema" again on the field's subSchema. if (currentField.ValueType == typeof(Entity)) { Schema subSchema = Schema.Lookup(currentField.SubSchemaGUID); swSub = SchemaWrapper.FromSchema(subSchema); } //Invoke the "AddField" method with the generic parameters from the current field. genericAddFieldMethodInstantiated.Invoke(swReturn, new object[] { currentField.FieldName, currentField.GetSpecTypeId(), swSub }); } //Note that we don't call SchemaWrapper.FinishSchema here. //The Autodesk.Revit.DB.ExtensibleStorage.Schema object already exists and is registered -- we're just populating the outer wrapper. return(swReturn); }
/// <summary> /// Adds a new field to the wrapper's list of fields. /// </summary> /// <param name="name">the name of the field</param> /// <param name="typeIn">the data type of the field</param> /// <param name="unit">The unit type of the Field (set to UT_Undefined for non-floating point types</param> /// <param name="subSchema">The SchemaWrapper of the field's subSchema, if the field is of type "Entity"</param> public void AddData(string name, System.Type typeIn, UnitType unit, SchemaWrapper subSchema) { m_DataList.Add(new FieldData(name, typeIn.FullName, unit, subSchema)); }
/// <summary> /// Adds a new field to the SchemaWrapper /// </summary> /// <typeparam name="TypeName">Currently supported types: int, short, float, double, bool, string, ElementId, XYZ, UV, Guid, Entity, IDictionary<>, IList<>. IDictionary<> does not support floating point types, XYZ, UV, or Entity as Key parameters.</typeparam> /// <param name="name">The name of the field</param> /// <param name="spec">The unit type of the field. Defintion required for floating point, XYZ, and UV types</param> /// <param name="subSchema">A subSchemaWrapper, if the field is of type Entity</param> public void AddField <TypeName>(string name, ForgeTypeId spec, SchemaWrapper subSchema) { m_SchemaDataWrapper.AddData(name, typeof(TypeName), spec, subSchema); }
/// <summary> /// Adds a new field to the SchemaWrapper /// </summary> /// <typeparam name="TypeName">Currently supported types: int, short, float, double, bool, string, ElementId, XYZ, UV, Guid, Entity, IDictionary<>, IList<>. IDictionary<> does not support floating point types, XYZ, UV, or Entity as Key parameters.</typeparam> /// <param name="name">The name of the field</param> /// <param name="unit">The unit type of the field. Defintion required for floating point, XYZ, and UV types</param> /// <param name="subSchema">A subSchemaWrapper, if the field is of type Entity</param> public void AddField <TypeName>(string name, UnitType unit, SchemaWrapper subSchema) { m_SchemaDataWrapper.AddData(name, typeof(TypeName), unit, subSchema); }
/// <summary> /// Adds a new field to the wrapper's list of fields. /// </summary> /// <param name="name">the name of the field</param> /// <param name="typeIn">the data type of the field</param> /// <param name="spec">The unit type of the Field (set to UT_Undefined for non-floating point types</param> /// <param name="subSchema">The SchemaWrapper of the field's subSchema, if the field is of type "Entity"</param> public void AddData(string name, System.Type typeIn, ForgeTypeId spec, SchemaWrapper subSchema) { m_DataList.Add(new FieldData(name, typeIn.FullName, spec.TypeId, subSchema)); }