Esempio n. 1
0
        void LoadPropertyTemplateFile(string xmlFilename, DynamicPropertyCollectionType target)
        {
            xmlFilename = EditorManager.Project.MakeAbsolute(xmlFilename);
              IShapeFactory factory = EditorManager.ShapeFactory;
              try
              {
            XmlDocument doc = new XmlDocument();
            XmlTextReader xmlReader = new XmlTextReader(xmlFilename);
            xmlReader.WhitespaceHandling = WhitespaceHandling.None;
            doc.Load(xmlReader);
            xmlReader.Close();

            IEnumerator nodes = doc.DocumentElement.GetEnumerator();
            while (nodes.MoveNext())
            {
              XmlElement node = nodes.Current as XmlElement;
              if (node == null)
            continue;
              if (node.Name != "property")
            continue;
              string propName = node.GetAttribute("name");
              string typeName = node.GetAttribute("type");
              string defaultStr = node.GetAttribute("default");
              string description = node.GetAttribute("description");
              if (string.IsNullOrEmpty(propName) || string.IsNullOrEmpty(typeName))
            continue;
              Type t;
              // some convenience type conversions
              if (string.Compare(typeName, "float", true) == 0) t = typeof(float);
              else if (string.Compare(typeName, "int", true) == 0) t = typeof(int);
              else if (string.Compare(typeName, "string", true) == 0) t = typeof(string);
              else t = SerializationHelper.GetType(typeName);
              if (t==null)
            continue;
              object defaultVal = SerializationHelper.GetObjectFromStringData(t, defaultStr);
              DynamicPropertyType newType = new DynamicPropertyType(propName, t, defaultVal, description, null);
              target.Add(newType);
            }
              }
              catch (Exception ex)
              {
            EditorManager.DumpException(ex);

              }
        }