private void ConnectSource(IDomain domain, ref bool IsConnected) { IResource Resource = SourceResource; IsConnected |= SourceProperty.ConnectToResourceOnly(domain, ref Resource); SourceResource = Resource; }
public void IndexedPathSourceResolutionTest() { string rawPath = "AvailableEmployees.Name"; BindingPath path = new BindingPath(rawPath, 1); var employee1 = new { Name = "Sam" }; var employee2 = new { Name = "Ben" }; var employee3 = new { Name = "Ali" }; var list = new[] { employee1, employee2, employee3 }; var viewModel = new { AvailableEmployees = list }; SourceProperty sourceProperty = path.ResolveAsSource(viewModel); Assert.IsNotNull(sourceProperty); Assert.IsNotNull(sourceProperty.Descriptor); Assert.IsNotNull(sourceProperty.OwningInstance); Assert.IsNotNull(sourceProperty.Value); Assert.AreEqual("Ben", sourceProperty.Value); Assert.AreEqual("Name", sourceProperty.Descriptor.Name); //empoyee at the index of 1 Assert.AreEqual(employee2, sourceProperty.OwningInstance); Assert.AreEqual(employee2.Name, sourceProperty.Value); Assert.AreEqual("Name", sourceProperty.Descriptor.Name); }
public void NestedCollectionAbsolutePathTest() { /*Arrange*/ //create a parent binding. /*Arrange*/ Binding.BindingDef parent = new Binding.BindingDef(new WebformControl(new TextBox()), "", new Options { Path = "" }, controlService); string rawPath = "ViewModelID"; BindingPath path = new BindingPath(rawPath, parent.SourceExpression, PathMode.Absolute); var viewModel = new { ViewModelID = "viewmodel1" }; /*Act*/ SourceProperty sourceProperty = path.ResolveAsSource(viewModel); /*Assert*/ Assert.IsNotNull(sourceProperty); Assert.IsNotNull(sourceProperty.Descriptor); Assert.IsNotNull(sourceProperty.OwningInstance); Assert.IsNotNull(sourceProperty.Value); Assert.AreEqual("ViewModelID", sourceProperty.Descriptor.Name); Assert.AreEqual(viewModel, sourceProperty.OwningInstance); Assert.AreEqual(viewModel.ViewModelID, sourceProperty.Value); }
private void BindTo(object obj, string propertyName) { object value = null; SourceObject = obj; Type type = SourceObject.GetType(); SourceProperty = type.GetProperty(_SourcePropertyName, BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (SourceProperty != null) { value = SourceProperty.GetValue(SourceObject, null); } object owner = obj; ControlProperty = type.GetNestedMember(ref owner, propertyName, true); if (ControlProperty == null) { throw new Exception(string.Format("Property named {0} was not found in class {1}", propertyName, owner.GetType().Name)); } Control = owner; if (value != null && Value != value) { if (Control != null) { ControlProperty.SetValue(Control, value); } } }
/// <summary> /// Gets the value using a created and data bound container /// </summary> /// <param name="item">The item.</param> /// <returns></returns> private TValue GetFromNewContainer(object item) { var treeViewItem = CreateContainer(item); var itemType = item.GetType(); if (_allowSourceProperties && !_sourceProperties.ContainsKey(itemType)) { var binding = BindingOperations.GetBinding(treeViewItem, _dependencyProperty); if (binding == null) { _sourceProperties[itemType] = new SourceProperty { MustUseDependencyProperty = false, Property = null } } ; else { // when the binding is missing or complex, use from source var useDependencyProperty = binding.Source != null || binding.RelativeSource != null || binding.ElementName != null || binding.Path.Path.Any(IsSpecial); var propertyInfo = itemType.GetProperty(binding.Path.Path); _sourceProperties[itemType] = new SourceProperty { MustUseDependencyProperty = useDependencyProperty, Property = propertyInfo }; } } return((TValue)treeViewItem.GetValue(_dependencyProperty)); }
protected override void Process(ReferenceParserPipeline pipeline) { if (!pipeline.ReferenceText.StartsWith("{") || !pipeline.ReferenceText.EndsWith("}")) { return; } // ignore formatting specifiers: {0}, {1} etc. if (pipeline.ReferenceText.Length == 3 && char.IsDigit(pipeline.ReferenceText[1])) { return; } // if the reference also contains a ", it is probably a Json string if (pipeline.ReferenceText.IndexOf('\"') >= 0 || pipeline.ReferenceText.IndexOf('\'') >= 0 || pipeline.ReferenceText.IndexOf(':') >= 0) { return; } var sourceProperty = new SourceProperty <string>(pipeline.ProjectItem, pipeline.SourceTextNode.Key, string.Empty, SourcePropertyFlags.IsSoftGuid); sourceProperty.SetValue(pipeline.SourceTextNode); pipeline.Reference = Factory.Reference(pipeline.ProjectItem, sourceProperty, pipeline.ReferenceText, pipeline.Database.DatabaseName); pipeline.Abort(); }
/// <summary> /// Maps a given class member from the source to the target object. /// </summary> /// <param name="source">Mapping sourceMember object</param> /// <param name="target">Mapping targetMember object</param> public override void Map(TSource source, TTarget target) { object src = SourceProperty.GetValue(source, null); object val = Mapper.Map(src); TargetProperty.SetValue(target, val, null); }
public override int GetHashCode() { unchecked { return(((SourceProperty != null ? SourceProperty.GetHashCode() : 0) * 397) ^ (DestinationProperty != null ? DestinationProperty.GetHashCode() : 0)); } }
public object GetValue(object dto) { if (dto == null) { return(null); } if (ParentProperties.Count == 0) { var val = SourceProperty?.GetValue(dto); if (val == null) { return(null); } if (val.IsArrayOrListOfT(out IEnumerable collection)) { return(collection.GetItems()); } return(val); } object parentVal = dto; foreach (var parentProperty in ParentProperties) { parentVal = parentProperty.GetValue(parentVal); if (parentVal == null) { break; } } if (parentVal == null) { return(null); } if (parentVal.IsArrayOrListOfT(out IEnumerable enumerable)) { return(enumerable.GetAllElementPropertyValues(SourceProperty)); } var childVal = SourceProperty?.GetValue(parentVal); if (childVal == null) { return(null); } if (childVal.IsArrayOrListOfT(out IEnumerable childEnumerable)) { return(childEnumerable.GetItems()); } return(childVal); }
public void RaiseSourcePropertyChangedEvent(SourceProperty property, object value) { SourcePropertyChangedEvent?.Invoke(this, new SourcePropertyChangedEventArgs { Property = property, Value = value }); }
static EnableImage() { SnapsToDevicePixelsProperty.OverrideMetadata(typeof(EnableImage), new FrameworkPropertyMetadata(true)); //UseLayoutRoundingProperty.OverrideMetadata(typeof(EnableImage), new FrameworkPropertyMetadata(false)); RenderOptions.EdgeModeProperty.OverrideMetadata(typeof(EnableImage), new FrameworkPropertyMetadata(EdgeMode.Aliased)); SourceProperty.OverrideMetadata(typeof(EnableImage), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnSourceChanged))); IsEnabledProperty.OverrideMetadata(typeof(EnableImage), new FrameworkPropertyMetadata(true, new PropertyChangedCallback(OnIsEnabledChanged))); }
static AppIconImage() { StretchProperty.OverrideMetadata(typeof(AppIconImage), new FrameworkPropertyMetadata(Stretch.Uniform)); SourceProperty.OverrideMetadata(typeof(AppIconImage), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(SourceChanged), new CoerceValueCallback(SourceCoerceCallback))); string exePath = GetExePath(); __appSmallIcon = IconReader.GetFileIcon(exePath, IconReader.IconSize.Small, false); //__appLargeIcon = IconReader.GetFileIcon(exePath, IconReader.IconSize.Large, false); }
public Reference([NotNull] IProjectItem owner, [NotNull] SourceProperty <string> sourceProperty, [NotNull] string referenceText, [NotNull] string databaseName) { // the reference text might be different from the source property value. // e.g. the source property value might be a list of guids while the reference text is a single Guid. Owner = owner; SourceProperty = sourceProperty; TextNode = sourceProperty.SourceTextNode; ReferenceText = referenceText; DatabaseName = databaseName; }
static CommandMenuItem() { CommandProperty.AddOwner(typeof(CommandMenuItem), new FrameworkPropertyMetadata(OnCommandChanged)); HeaderProperty.AddOwner(typeof(CommandMenuItem), new FrameworkPropertyMetadata(null, CoerceHeader)); SourceProperty.AddOwner(typeof(CommandMenuItem), new FrameworkPropertyMetadata(null, CoerceSource)); InputGestureTextProperty.AddOwner(typeof(CommandMenuItem), new FrameworkPropertyMetadata(null, CoerceInputGestureText)); }
static CommandButton() { CommandProperty.AddOwner(typeof(CommandButton), new FrameworkPropertyMetadata(OnCommandChanged)); //ContentProperty.AddOwner(typeof(CommandButton), // new FrameworkPropertyMetadata(null, CoerceContent)); SourceProperty.AddOwner(typeof(CommandButton), new FrameworkPropertyMetadata(null, CoerceSource)); ToolTipProperty.AddOwner(typeof(CommandButton), new FrameworkPropertyMetadata(null, CoerceToolTip)); }
public void RefreshFromSource() { if (SourceObject != null) { Type type = SourceObject.GetType(); SourceProperty = type.GetProperty(_SourcePropertyName, BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (SourceProperty != null) { Value = SourceProperty.GetValue(SourceObject, null); } } }
public List <SourceProperty> Init() { List <SourceProperty> result = new List <SourceProperty>(); for (int i = 0; i < 10; i++) { SourceProperty sp = new SourceProperty(); sp.DisplayPath = i.ToString() + (i + 1).ToString(); result.Add(sp); } return(result); }
protected override void Process(ReferenceParserPipeline pipeline) { if (!PathHelper.IsProbablyItemPath(pipeline.ReferenceText)) { return; } var sourceProperty = new SourceProperty <string>(pipeline.ProjectItem, pipeline.SourceTextNode.Key, string.Empty, SourcePropertyFlags.IsQualified); sourceProperty.SetValue(pipeline.SourceTextNode); pipeline.Reference = Factory.Reference(pipeline.ProjectItem, sourceProperty, pipeline.ReferenceText, pipeline.Database.DatabaseName); pipeline.Abort(); }
protected override void Process(ReferenceParserPipeline pipeline) { if (!pipeline.ReferenceText.StartsWith("~/")) { return; } var sourceProperty = new SourceProperty <string>(pipeline.ProjectItem, pipeline.SourceTextNode.Key, string.Empty, SourcePropertyFlags.IsFileName); sourceProperty.SetValue(pipeline.SourceTextNode); pipeline.Reference = Factory.FileReference(pipeline.ProjectItem, sourceProperty, pipeline.ReferenceText); pipeline.Abort(); }
/// <summary> /// Updates the target with the current value in the source object. Uses the Convert function to convert the data if available. /// </summary> public void UpdateTarget() { var value = SourceProperty.GetValue(Source, null); if (Convert != null) { value = Convert(value); } var converted = Utilities.CoerceValue( TargetProperty.PropertyType, SourceProperty.PropertyType, null, value); TargetProperty.SetValue(Target, converted, null); }
/// <summary> /// Updates the source with the current value in the target object. Uses the ConvertBack function to convert the data if available. /// </summary> public void UpdateSource() { var value = TargetProperty.GetValue(Target, null); if (ConvertBack != null) { value = ConvertBack(value); } var converted = Utilities.CoerceValue( SourceProperty.PropertyType, TargetProperty.PropertyType, null, value); SourceProperty.SetValue(Source, converted, null); }
protected override void Process(ReferenceParserPipeline pipeline) { Guid guid; if (!Guid.TryParse(pipeline.ReferenceText, out guid)) { return; } var sourceProperty = new SourceProperty <string>(pipeline.ProjectItem, pipeline.SourceTextNode.Key, string.Empty, SourcePropertyFlags.IsGuid); sourceProperty.SetValue(pipeline.SourceTextNode); pipeline.Reference = Factory.Reference(pipeline.ProjectItem, sourceProperty, pipeline.ReferenceText, pipeline.Database.DatabaseName); pipeline.Abort(); }
public void SimplePathSourceResolutionTest() { string rawPath = "SelectedEmployee.Name"; BindingPath path = new BindingPath(rawPath); object selectedEmployee = new { Name = "Sam" }; SourceProperty sourceProperty = path.ResolveAsSource(new { SelectedEmployee = selectedEmployee }); Assert.IsNotNull(sourceProperty); Assert.IsNotNull(sourceProperty.Descriptor); Assert.IsNotNull(sourceProperty.OwningInstance); Assert.IsNotNull(sourceProperty.Value); Assert.AreEqual("Sam", sourceProperty.Value); Assert.AreEqual("Name", sourceProperty.Descriptor.Name); Assert.AreEqual(selectedEmployee, sourceProperty.OwningInstance); }
protected virtual void ParseDeviceReferences([NotNull] ItemParseContext context, [NotNull, ItemNotNull] ICollection <IReference> references, [NotNull] IProjectItem projectItem, [NotNull] ITextNode deviceTextNode) { var deviceNameProperty = new SourceProperty <string>(projectItem, "Name", string.Empty, SourcePropertyFlags.IsShort); deviceNameProperty.Parse(deviceTextNode); references.Add(Factory.DeviceReference(projectItem, deviceNameProperty, string.Empty, context.ParseContext.Database.DatabaseName)); var layoutProperty = new SourceProperty <string>(projectItem, "Layout", string.Empty, SourcePropertyFlags.IsShort); layoutProperty.Parse(deviceTextNode); references.Add(Factory.LayoutReference(projectItem, layoutProperty, string.Empty, context.ParseContext.Database.DatabaseName)); foreach (var renderingTextNode in deviceTextNode.ChildNodes) { ParseRenderingReferences(context, references, projectItem, renderingTextNode); } }
private void ProxyOnOnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e) { if (SourceProperty != null && Context != null) { object value = e.NewValue; if (Expression.Converter != null) { value = Expression.Converter.ConvertBack(value, SourceProperty.PropertyType, Expression.ConverterParameter, CultureInfo.CurrentUICulture); } value = ConverterHelper.ChangeType(value, SourceProperty.PropertyType); if (SourceProperty.CanWrite) { SourceProperty.SetValue(Context, value); } } }
public void NestedAbsolutePathTest() { /*Arrange*/ //create a parent binding. Binding.BindingDef parent = new Binding.BindingDef( new WebformControl(new TextBox()) , "Text", 0 , new BindingCollection() , new Options { Path = "Companies" } , true, controlService); string rawPath = "CompanyName"; BindingPath path = new BindingPath(rawPath, parent.SourceExpression, PathMode.Absolute); var employee1 = new { Name = "Sam" }; var employee2 = new { Name = "Ben" }; var employee3 = new { Name = "Ali" }; var list = new[] { employee1, employee2, employee3 }; var company = new { AvailableEmployees = list }; var companyList = new[] { company }; var viewModel = new { CompanyName = "Tesco Ltd.", Companies = companyList }; /*Act*/ SourceProperty sourceProperty = path.ResolveAsSource(viewModel); /*Assert*/ Assert.IsNotNull(sourceProperty); Assert.IsNotNull(sourceProperty.Descriptor); Assert.IsNotNull(sourceProperty.OwningInstance); Assert.IsNotNull(sourceProperty.Value); Assert.AreEqual("CompanyName", sourceProperty.Descriptor.Name); Assert.AreEqual(viewModel, sourceProperty.OwningInstance); Assert.AreEqual(viewModel.CompanyName, sourceProperty.Value); }
public void Update() { var value = Value; #if DATABINDING var bindingExpression = BindingOperations.GetBindingExpressionsForElement(SourceObject).FirstOrDefault(); if (bindingExpression != null) { value = bindingExpression.ConvertValue(Value); #endif if (SourceProperty != null) { SourceProperty.SetValue(SourceObject, value, null); } #if DATABINDING bindingExpression.UpdateSource(); } #endif }
/// <summary> /// Updates the source with the current value in the target object. Uses the ConvertBack function to convert the data if available. /// </summary> public void UpdateSource() { if (this.BindingDirection == BindingDirection.OneWay) { return; } var value = TargetProperty.GetValue(Target, null); if (ConvertBack != null) { value = ConvertBack(value); } var converted = Utilities.CoerceValue( SourceProperty.PropertyType, TargetProperty.PropertyType, null, value); SourceProperty.SetValue(Source, converted, null); }
public void NestedRelativePathTest() { /*Arrange*/ Binding.BindingDef parent = new Binding.BindingDef( new WebformControl(new TextBox()), "Text", new Options() { Path = "Company" }, controlService); string rawPath = "AvailableEmployees.Name"; BindingPath path = new BindingPath(rawPath, 2, parent.SourceExpression, PathMode.Relative); var employee1 = new { Name = "Sam" }; var employee2 = new { Name = "Ben" }; var employee3 = new { Name = "Ali" }; var list = new[] { employee1, employee2, employee3 }; var company = new { AvailableEmployees = list }; var viewModel = new { Company = company }; /*Act*/ SourceProperty sourceProperty = path.ResolveAsSource(viewModel); /*Assert*/ Assert.IsNotNull(sourceProperty); Assert.IsNotNull(sourceProperty.Descriptor); Assert.IsNotNull(sourceProperty.OwningInstance); Assert.IsNotNull(sourceProperty.Value); Assert.AreEqual("Ali", sourceProperty.Value); Assert.AreEqual("Name", sourceProperty.Descriptor.Name); //empoyee at the index of 1 Assert.AreEqual(employee3, sourceProperty.OwningInstance); Assert.AreEqual(employee3.Name, sourceProperty.Value); Assert.AreEqual("Name", sourceProperty.Descriptor.Name); }
protected virtual void ParseDeviceReferences([NotNull] ItemParseContext context, [NotNull] [ItemNotNull] ICollection<IReference> references, [NotNull] IProjectItem projectItem, [NotNull] ITextNode deviceTextNode) { var deviceNameProperty = new SourceProperty<string>("Name", string.Empty, SourcePropertyFlags.IsShort); deviceNameProperty.Parse(deviceTextNode); references.Add(context.ParseContext.Factory.DeviceReference(projectItem, deviceNameProperty)); var layoutProperty = new SourceProperty<string>("Layout", string.Empty, SourcePropertyFlags.IsShort); layoutProperty.Parse(deviceTextNode); references.Add(context.ParseContext.Factory.LayoutReference(projectItem, layoutProperty)); var renderingsTextNode = deviceTextNode.GetSnapshotLanguageSpecificChildNode("Renderings"); if (renderingsTextNode == null) { return; } foreach (var renderingTextNode in renderingsTextNode.ChildNodes) { ParseRenderingReferences(context, references, projectItem, renderingTextNode); } }
public virtual object GetSourceValue() { object value = null; if (SourceProperty != null) { value = SourceProperty.GetValue(Binding.Source); } if (value == null && _ViewProperty != null) { value = _ViewProperty.GetValue(Binding.ViewSource); } if (value != null) { return(value); } return(Binding.FallbackValue); }
public virtual IReference Reference(IProjectItem projectItem, SourceProperty<string> sourceSourceProperty, string referenceText) { return new Reference(projectItem, sourceSourceProperty, referenceText); }
public virtual LayoutRenderingReference LayoutRenderingReference(IProjectItem projectItem, SourceProperty<string> renderingTextNode) { return new LayoutRenderingReference(projectItem, renderingTextNode); }
public virtual LayoutReference LayoutReference(IProjectItem projectItem, SourceProperty<string> layoutSourceProperty) { return new LayoutReference(projectItem, layoutSourceProperty); }
internal static extern void alSourcei(uint sourceId, SourceProperty property, float val1);
internal static extern void alGetSource3f(uint sourceId, SourceProperty property, out float val1, out float val2, out float val3);
internal static extern void alSourcefv(uint sourceId, SourceProperty property, float[] value);
internal static extern void alSource3f(uint sourceId, SourceProperty property, float val1, float val2, float val3);
protected virtual void ParseRenderingReferences([NotNull] ItemParseContext context, [NotNull] [ItemNotNull] ICollection<IReference> references, [NotNull] IProjectItem projectItem, [NotNull] ITextNode renderingTextNode) { if (!string.IsNullOrEmpty(renderingTextNode.Key)) { var sourceProperty = new SourceProperty<string>(renderingTextNode.Key, string.Empty, SourcePropertyFlags.IsShort); sourceProperty.SetValue(new AttributeNameTextNode(renderingTextNode)); references.Add(context.ParseContext.Factory.LayoutRenderingReference(projectItem, sourceProperty)); } // parse references for rendering properties foreach (var attributeTextNode in renderingTextNode.Attributes) { foreach (var reference in context.ParseContext.ReferenceParser.ParseReferences(projectItem, attributeTextNode)) { references.Add(reference); } } foreach (var childTextNode in renderingTextNode.ChildNodes) { ParseRenderingReferences(context, references, projectItem, childTextNode); } }
internal static extern void alGetSourcei(uint sourceId, SourceProperty property, out int value);
internal static extern void alListener3f(SourceProperty param, float val1, float val2, float val3);
internal static extern void alGetListener3f(SourceProperty param, out float val1, out float val2, out float val3);
public virtual DeviceReference DeviceReference(IProjectItem projectItem, SourceProperty<string> deviceNameSourceProperty) { return new DeviceReference(projectItem, deviceNameSourceProperty); }
public virtual FileReference FileReference(IProjectItem owner, SourceProperty<string> sourceSourceProperty) { return new FileReference(owner, sourceSourceProperty); }
internal static extern void alListenerfv(SourceProperty param, float[] val);