/// <summary> /// Refresh key and property values. Call after Save to capture database updated keys and values. /// </summary> public AuditLog Refresh() { // update current values because the entites can change after submit foreach (var auditEntity in Entities) { // don't need to update deletes if (auditEntity.Action == AuditAction.Deleted) { continue; } // if current is stored, it will be updated on submit object current = auditEntity.Current; if (current == null) { continue; } // update the key value foreach (var key in auditEntity.Keys) { key.Value = LateBinder.GetProperty(current, key.Name); } // update the property current values foreach (var property in auditEntity.Properties.Where(p => !p.IsRelationship)) { property.Current = LateBinder.GetProperty(current, property.Name); } } return(this); }
public static Orientation GetItemsPanelOrientation(this ItemsControl itemsControl) { var itemsPresenter = itemsControl.GetVisualDescendant <ItemsPresenter>(); if (itemsPresenter == null) { return(Orientation.Vertical); } var itemsPanel = VisualTreeHelper.GetChild(itemsPresenter, 0); if (itemsPanel == null) { return(Orientation.Vertical); } var orientationProperty = LateBinder.FindProperty(itemsPanel.GetType(), "Orientation"); if (orientationProperty == null) { return(Orientation.Vertical); } return((Orientation)orientationProperty.GetValue(itemsPanel)); }
public void GetFieldValue() { Tester tester = new Tester(); string name = LateBinder.GetField(tester, "_name").ToString(); Assert.AreEqual("test", name); }
public static UndoState FromObject(object recordFrom) { UndoState toReturn = new UndoState(); toReturn.Owner = recordFrom; var lateBinder = LateBinder.GetInstance(recordFrom.GetType()); object result; if (lateBinder.TryGetValue(recordFrom, "X", out result)) { toReturn.X = (float)result; } if (lateBinder.TryGetValue(recordFrom, "Y", out result)) { toReturn.Y = (float)result; } if (lateBinder.TryGetValue(recordFrom, "Z", out result)) { toReturn.Z = (float)result; } if (lateBinder.TryGetValue(recordFrom, "ScaleX", out result)) { toReturn.ScaleX = (float)result; } if (lateBinder.TryGetValue(recordFrom, "ScaleY", out result)) { toReturn.ScaleY = (float)result; } return(toReturn); }
public void ApplyUndo() { var lateBinder = LateBinder.GetInstance(Owner.GetType()); if (X.HasValue) { lateBinder.SetValue(Owner, "X", X.Value); } if (Y.HasValue) { lateBinder.SetValue(Owner, "Y", Y.Value); } if (Z.HasValue) { lateBinder.SetValue(Owner, "Z", Z.Value); } if (ScaleX.HasValue) { lateBinder.SetValue(Owner, "ScaleX", ScaleX.Value); } if (ScaleY.HasValue) { lateBinder.SetValue(Owner, "ScaleY", ScaleY.Value); } }
private void HandleInstanceMemberSetByUi(object sender, EventArgs e) { if (PropertyChange != null) { PropertyChangedArgs args = new PropertyChangedArgs(); args.Owner = this.Instance; args.NewValue = LateBinder.GetValueStatic(this.Instance, ((InstanceMember)sender).Name); args.PropertyName = ((InstanceMember)sender).Name; PropertyChange(((InstanceMember)sender).Name, args); } foreach (var item in InternalControl.Items) { MemberCategory memberCategory = item as MemberCategory; foreach (var instanceMember in memberCategory.Members) { if (instanceMember.Name != ((InstanceMember)sender).Name) { instanceMember.SimulateValueChanged(); } } } RefreshDelegateBasedElementVisibility(); }
public void GetFieldValueBoxed() { Tester tester = new Tester(); var id = LateBinder.GetField(tester, "_id"); Assert.AreEqual(888, id); }
public void GetPropertyValue() { Tester tester = new Tester(); string name = LateBinder.GetProperty(tester, "Name").ToString(); Assert.AreEqual("test", name); }
public Tweener Tween(string member, float value, float time, InterpolationType interpolation, Easing easing) { MemberToSet = member; object currentValueAsObject = LateBinder.GetValueStatic(Caller, member); if (currentValueAsObject is float) { float currentValue = (float)currentValueAsObject; Tweener tweener = new Tweener(currentValue, value, time, interpolation, easing); tweener.PositionChanged = HandlePositionSet; tweener.Owner = Caller; TweenerManager.Self.Add(tweener); tweener.Start(); return(tweener); } else { throw new NotImplementedException(); } }
private void MakeAllInvisible() { foreach (object visibleObject in mVisibleRepresentations.Values) { LateBinder.GetInstance(visibleObject.GetType()).SetValue(visibleObject, "Visible", false); } }
public void GetPropertyValueBoxed() { Tester tester = new Tester(); var id = LateBinder.GetProperty(tester, "Id"); Assert.AreEqual(888, id); }
public object InstanceForElementRuntime(ElementRuntime elementRuntime) { if (elementRuntime == null) { return(null); } if (elementRuntime.AssociatedNamedObjectSave == null) { throw new Exception("The ElementRuntime does not have an associated NamedObject and it should"); } string nameToFind = elementRuntime.AssociatedNamedObjectSave.InstanceName; IElement containerIElement = ObjectFinder.Self.GetElementContaining(elementRuntime.AssociatedNamedObjectSave); string containerNameStripped = null; if (containerIElement is EntitySave) { containerNameStripped = containerIElement.Name.Substring("Entities/".Length); } else //Implied: if (containerIElement is ScreenSave) { containerNameStripped = containerIElement.Name.Substring("Screens/".Length); } ArrowElementSave container = ArrowState.Self.CurrentArrowProject.Elements.FirstOrDefault( item => item.Name == containerNameStripped); return(container.AllInstances.FirstOrDefault(item => LateBinder.GetInstance(item.GetType()).GetValue(item, "Name") as string == nameToFind)); }
public void SetPropertyValueBoxed() { Tester tester = new Tester(); LateBinder.SetProperty(tester, "Id", 999); Assert.AreEqual(999, tester.Id); }
public void SetPropertyValueNestedNull() { Tester tester = new Tester(); LateBinder.SetProperty(tester, "Order.OrderAddress.City", "New Description"); Assert.AreEqual("New Description", tester.Order.OrderAddress.City); }
private static MemberInfo FindMember(Type entityType, string fullName) { var name = fullName.Split('.').LastOrDefault(); var member = LateBinder.Find(entityType, name); var info = member.MemberInfo; return(info); }
public void SetPropertyValue() { Tester tester = new Tester(); LateBinder.SetProperty(tester, "Name", "New Name"); Assert.AreEqual("New Name", tester.Name); }
public void SetFieldValueBoxed() { Tester tester = new Tester(); LateBinder.SetField(tester, "_id", 999); Assert.AreEqual(999, tester.Id); }
public void SetFieldValue() { Tester tester = new Tester(); LateBinder.SetField(tester, "_name", "New Name"); Assert.AreEqual("New Name", tester.Name); }
public void GetPropertyValueNested() { Tester tester = new Tester(); tester.Order = new Order(); string name = LateBinder.GetProperty(tester, "Order.Id").ToString(); Assert.AreEqual("123", name); }
private static void SetSavePositionsFromRelativeValues(PositionedObject whatToPullFromAsPo, object saveObject) { if (whatToPullFromAsPo.Parent != null) { var lateBinderInstance = LateBinder.GetInstance(saveObject.GetType()); lateBinderInstance.SetValue(saveObject, "X", whatToPullFromAsPo.RelativeX); lateBinderInstance.SetValue(saveObject, "Y", whatToPullFromAsPo.RelativeY); lateBinderInstance.SetValue(saveObject, "Z", whatToPullFromAsPo.RelativeZ); } }
public void SetPropertyValueNested() { Tester tester = new Tester(); tester.Order = new Order(); LateBinder.SetProperty(tester, "Order.Description", "New Description"); Assert.AreEqual("New Description", tester.Order.Description); }
public ElementRuntime ElementRuntimeForArrowInstance(object instance, ElementRuntime container) { // todo: Add verification because we assume the current IElement contains a NOS for the instance string name = (string)LateBinder.GetInstance(instance.GetType()).GetValue(instance, "Name"); ElementRuntime contained = container.GetContainedElementRuntime(name); return(contained); }
public void SetPropertyValueNestedObject() { Tester tester = new Tester(); tester.Order = new Order(); LateBinder.SetProperty(tester, "Order.OrderAddress", new OrderAddress { Zip = "55346" }); Assert.AreEqual("55346", tester.Order.OrderAddress.Zip); }
public override void SetValue(object component, object value) { if (MemberChangeEvent != null) { MemberChangeEvent(null, new MemberChangeArgs { Owner = Instance, Member = this.Name, Value = value }); } else if (Instance != null) { LateBinder.GetInstance(Instance.GetType()).SetValue(Instance, this.Name, value); } }
public void ReactToMemberChange(object sender, MemberChangeArgs args) { if (MemberChange != null) { MemberChange(sender, args); } else { LateBinder.GetInstance(args.Owner.GetType()).SetValue(args.Owner, args.Member, args.Value); } if (AfterMemberChange != null) { AfterMemberChange(sender, args); } }
public static bool CanSelectMultipleItems(this ItemsControl itemsControl) { if (itemsControl is MultiSelector) { return((bool)LateBinder.GetProperty(itemsControl, "CanSelectMultipleItems", BindingFlags.Instance | BindingFlags.NonPublic)); } if (itemsControl is ListBox) { return(((ListBox)itemsControl).SelectionMode != SelectionMode.Single); } return(false); }
public static bool IsValueEmptyCollection(this JsonProperty property, object target) { var value = property.ValueProvider.GetValue(target); if (value == null) { return(true); } var collection = value as ICollection; if (collection != null && collection.Count == 0) { return(true); } if (!_countAccessors.ContainsKey(property.PropertyType)) { if (typeof(IEnumerable).IsAssignableFrom(property.PropertyType)) { var countProperty = property.PropertyType.GetProperty("Count"); if (countProperty != null) { _countAccessors.AddOrUpdate(property.PropertyType, LateBinder.GetPropertyAccessor(countProperty)); } else { _countAccessors.AddOrUpdate(property.PropertyType, null); } } else { _countAccessors.AddOrUpdate(property.PropertyType, null); } } var countAccessor = _countAccessors[property.PropertyType]; if (countAccessor == null) { return(false); } var count = (int)countAccessor.GetValue(value); return(count == 0); }
public DataObjectConverter(IEnumerable <KeyValuePair <string, Type> > knownDataTypes = null) { if (knownDataTypes != null) { _dataTypeRegistry.AddRange(knownDataTypes); } if (_propertyAccessors.Count != 0) { return; } foreach (var prop in typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public).Where(p => p.CanWrite)) { _propertyAccessors.Add(prop.Name, LateBinder.GetPropertyAccessor(prop)); } }
public void MakeNewObjectUnique(DataTypes.ArrowElementSave container, object newObject) { string name = LateBinder.GetValueStatic(newObject, "Name") as string; List <string> allNames = new List <string>(); foreach (var item in container.AllInstances) { if (item != newObject) { allNames.Add(LateBinder.GetValueStatic(item, "Name") as string); } } name = StringFunctions.MakeStringUnique(name, allNames); LateBinder.SetValueStatic(newObject, "Name", name); }
public UndoState GetDiff(object compareTo) { UndoState toReturn = new UndoState(); var lateBinder = LateBinder.GetInstance(compareTo.GetType()); object result = null; bool foundSomething = false; if (X.HasValue && lateBinder.TryGetValue(compareTo, "X", out result) && (float)result != X.Value) { toReturn.X = this.X; foundSomething = true; } if (Y.HasValue && lateBinder.TryGetValue(compareTo, "Y", out result) && (float)result != Y.Value) { toReturn.Y = this.Y; foundSomething = true; } if (Z.HasValue && lateBinder.TryGetValue(compareTo, "Z", out result) && (float)result != Z) { toReturn.Z = this.Z; foundSomething = true; } if (ScaleX.HasValue && lateBinder.TryGetValue(compareTo, "ScaleX", out result) && (float)result != ScaleX) { toReturn.ScaleX = this.ScaleX; foundSomething = true; } if (ScaleY.HasValue && lateBinder.TryGetValue(compareTo, "ScaleY", out result) && (float)result != ScaleY) { toReturn.ScaleY = this.ScaleY; foundSomething = true; } if (foundSomething) { toReturn.Owner = compareTo; return(toReturn); } else { return(null); } }