/// <summary> /// Adds a child item with the given type /// (<see cref="SolutionItemType.SolutionRootItem"/> cannot be added here). /// </summary> /// <param name="displayName"></param> /// <param name="type"></param> /// <returns></returns> public static IItemModel AddStaticChild(string displayName , SolutionModelItemType type , IItemChildrenModel parent) { if (parent.FindChild(displayName) != null) { throw new ArgumentException("Item '" + displayName + "' already exists."); } IItemModel newItem = null; switch (type) { case SolutionModelItemType.File: newItem = new FileItemModel(parent, displayName); break; case SolutionModelItemType.Folder: newItem = new FolderItemModel(parent, displayName); break; case SolutionModelItemType.Project: newItem = new ProjectItemModel(parent, displayName); break; // This should be created via AddSolutionRootItem() method case SolutionModelItemType.SolutionRootItem: default: throw new ArgumentException(type.ToString()); } parent.AddChild(newItem); return(newItem); }
/// <summary> /// Reads the indicated item <paramref name="type"/> from the Xml reader's /// data stream, advances the Xml reader, and returns the new item. /// </summary> /// <param name="type"></param> /// <param name="reader"></param> /// <returns></returns> internal static IItemModel ReadItem(SolutionModelItemType type , XmlReader reader) { IItemModel newItem = null; DataContractSerializer itemSer = null; switch (type) { case SolutionModelItemType.File: itemSer = new DataContractSerializer(typeof(FileItemModel)); newItem = (FileItemModel)itemSer.ReadObject(reader); break; case SolutionModelItemType.Folder: itemSer = new DataContractSerializer(typeof(FolderItemModel)); newItem = (FolderItemModel)itemSer.ReadObject(reader); break; case SolutionModelItemType.Project: itemSer = new DataContractSerializer(typeof(ProjectItemModel)); newItem = (ProjectItemModel)itemSer.ReadObject(reader); break; case SolutionModelItemType.SolutionRootItem: itemSer = new DataContractSerializer(typeof(SolutionRootItemModel)); newItem = (SolutionRootItemModel)itemSer.ReadObject(reader); break; default: throw new ArgumentException(type.ToString()); } return(newItem); }
/// <summary> /// Gets the name of the corresponding XML for each type of model /// based on an enumerated value. /// </summary> /// <param name="type"></param> /// <returns></returns> internal static string GetXmlName(SolutionModelItemType type) { switch (type) { case SolutionModelItemType.SolutionRootItem: return("RootItem"); case SolutionModelItemType.File: return("File"); case SolutionModelItemType.Folder: return("Folder"); case SolutionModelItemType.Project: return("Project"); default: throw new System.NotImplementedException(type.ToString()); } }