/// <summary> /// Sets the value of the specified custom property. /// </summary> private void SetCustomProperty(string propertyName, string value) { if (!CustomProperties.ContainsKey(propertyName)) { CustomProperties.Add(propertyName, value); } else { CustomProperties[propertyName] = value; } }
public void Process( ) { CustomProperties customProperties = _treeItem.ItemProperties.CustomProperties; var form = new AddCustomPropertyForm(e => !customProperties.ContainsKey(e)); DialogResult result = form.ShowDialog( ); if (result == DialogResult.OK) { IoC.Model.AddCustomProperty(_treeItem, form.NewCustomProperty); } }
private bool UpdateCustomProperty(CustomProperties customProperties, object hashKeyValue, string customItemKey) { if (_control.IgnoreMSDesignerInformation && customItemKey.IndexOf("MS_", StringComparison.OrdinalIgnoreCase) != -1) { if (string.Compare(customItemKey, "MS_Description", true) != 0) { return(false); } } if (customProperties.ContainsKey(customItemKey)) { if (customProperties[customItemKey] == hashKeyValue) { return(false); } customProperties[customItemKey] = hashKeyValue; } else { customProperties.Add(customItemKey, hashKeyValue); } return(true); }
public override void Initialize() { colBodySize = Size; CollisionBox = context.lvl.CollisionWorld.CreateRectangle((float)ConvertUnits.ToSimUnits(Size.X), (float)ConvertUnits.ToSimUnits(Size.Y), 1, ConvertUnits.ToSimUnits(Transform.Position), 0, BodyType.Kinematic); CollisionBox.SetCollisionCategories(collidesWith); CollisionBox.Tag = this; cntlr = new PlatformController(CollisionBox, Category.Cat2) { speed = 0.2f, easeAmount = 1.7f, waitTime = 0.5f, globalWaypoints = WayPoints.ToArray() }; if (CustomProperties.ContainsKey("tex")) { var texture = CustomProperties["tex"].value.ToString(); movingObj = context.lvl.getItemByName(texture); movingObj.Transform.Position = Transform.Position; } base.Initialize(); }
public bool ContainsProperty(string name) { return(CustomProperties.ContainsKey(name)); }
void buttonOkClick(object sender, EventArgs e) { //todo: move to an action if (uiFirstItemCustomPropertyNameTextBox.Text == "") { MessageBox.Show( @"Please specify a name for the Custom Property that is to be added to the first Item!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (uiLinkSecondItemToFirstCheckbox.Checked && uiSecondItemCustomPropertyNameTextBox.Text == string.Empty) { MessageBox.Show( @"Please specify a name for the Custom Property that is to be added to the second Item!", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var model = ObjectFactory.GetInstance <IModel>(); IEnumerable <ITreeItem> selectedEditors = model.Level.SelectedEditors.ToList( ); ITreeItem firstSelectedItem = selectedEditors.First(); CustomProperties customPropertiesForFirstItem = firstSelectedItem.ItemProperties.CustomProperties; if (customPropertiesForFirstItem.ContainsKey(uiFirstItemCustomPropertyNameTextBox.Text)) { MessageBox.Show( "The first Item ({0}) already has a Custom Property named \"{1}\". Please use another name.".FormatWith(firstSelectedItem.ItemProperties.Name, uiFirstItemCustomPropertyNameTextBox.Text), @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var customProperty = new CustomProperty { Name = uiFirstItemCustomPropertyNameTextBox.Text, Type = typeof(ItemEditor) }; ITreeItem secondSelectItem = selectedEditors.ElementAt(1); customProperty.Value = secondSelectItem; customPropertiesForFirstItem.Add(customProperty.Name, customProperty); if (uiLinkSecondItemToFirstCheckbox.Checked) { CustomProperties customPropertiesForSecondItem = secondSelectItem.ItemProperties.CustomProperties; if (customPropertiesForSecondItem.ContainsKey(uiSecondItemCustomPropertyNameTextBox.Text)) { MessageBox.Show( "The second Item ({0}) already has a Custom Property named \"{1}\". Please use another name!".FormatWith(secondSelectItem.ItemProperties.Name, uiSecondItemCustomPropertyNameTextBox.Text), "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); customPropertiesForFirstItem.Remove(customProperty.Name); return; } customProperty = new CustomProperty { Name = uiSecondItemCustomPropertyNameTextBox.Text, Type = typeof(ItemEditor), Value = firstSelectedItem }; customPropertiesForSecondItem.Add(customProperty.Name, customProperty); } Hide(); }
private void ReadXmlInternal(XmlReader reader) { // открываем чтение, если еще не сделали if (reader.ReadState == ReadState.Initial) { reader.Read(); } // читаем root var rootName = reader.Name; if (!reader.Read()) { return; } var instanceCount = 1; var properties = TypeDescriptor.GetProperties(GetType()).Cast <DynamicPropertyDescriptor>().ToArray(); while (!reader.EOF) { var name = reader.Name; if (name == rootName) { // дочитали до конца - выходим if (reader.NodeType == XmlNodeType.EndElement) { instanceCount--; if (instanceCount == 0) { break; } } instanceCount++; } // нас интересуют только заполненные элементы if (reader.NodeType != XmlNodeType.Element || reader.IsEmptyElement) { reader.Read(); continue; } // ищем соответствующее свойство (в XML и в метаданных должны быть большие буквы) var propertyDesc = properties.FirstOrDefault(i => name.Equals(i.SourceName)); CustomProperty property; if (propertyDesc != null && CustomProperties.ContainsKey(propertyDesc.Name)) { property = CustomProperties[propertyDesc.Name]; } else // свойсва нет - пытаемся присвоить по прочитанному имени (а там в зависимости от настроек) { var innerXml = reader.ReadInnerXml(); SetProperty(name, innerXml); //reader.Read(); лишнее чтение continue; } // если объект сам умеет десериализоваться, пусть этим и займется if (typeof(IXmlSerializable).IsAssignableFrom(property.PropertyType)) { // создаем новый экземпляз класса property.SetNewInstance(); var obj = ((IXmlSerializable)property.Value); obj.ReadXml(reader); } else { var strValue = reader.ReadElementContentAsString(); //HACK: заменяем escape символы на соответсвующие foreach (var esc in EscapeChars) { strValue = strValue.Replace(esc.Key, esc.Value); } // оставшиеся заносим как есть property.Value = strValue; } // сообщаем об изменении св-ва // ЭТО ОЧЕНЬ ВАЖНО!!! Запускаются механизмы контроля изменений и валидации! // TODO: Подумать как убрать эту фигню!!! OnPropertyChanged(property.Name); } }