Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Markup / Baml2006 / WpfMemberInvoker.cs / 1305600 / WpfMemberInvoker.cs
using System; using System.Collections.Generic; using System.Text; using System.Xaml.Schema; using System.Reflection; namespace System.Windows.Baml2006 { internal class WpfMemberInvoker : XamlMemberInvoker { WpfXamlMember _member; bool _hasShouldSerializeMethodBeenLookedup = false; MethodInfo _shouldSerializeMethod = null; public WpfMemberInvoker(WpfXamlMember member) : base(member) { _member = member; } public override void SetValue(object instance, object value) { DependencyObject dObject = instance as DependencyObject; if (dObject != null) { if (_member.DependencyProperty != null) { dObject.SetValue(_member.DependencyProperty, value); return; } else if (_member.RoutedEvent != null) { Delegate handler = value as Delegate; if (handler != null) { UIElement.AddHandler(dObject, _member.RoutedEvent, handler); return; } } } base.SetValue(instance, value); } public override object GetValue(object instance) { DependencyObject dObject = instance as DependencyObject; if (dObject != null && _member.DependencyProperty != null) { object result = dObject.GetValue(_member.DependencyProperty); if (result != null) { return result; } // Getter fallback: see comment on WpfXamlMember.AsContentProperty if (!_member.ApplyGetterFallback || _member.UnderlyingMember == null) { return result; } } return base.GetValue(instance); } public override ShouldSerializeResult ShouldSerializeValue(object instance) { // Look up the ShouldSerializeMethod if (!_hasShouldSerializeMethodBeenLookedup) { Type declaringType = _member.UnderlyingMember.DeclaringType; string methodName = "ShouldSerialize" + _member.Name; BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static; Type[] args = new Type[] { typeof(DependencyObject) }; ; if (_member.IsAttachable) { _shouldSerializeMethod = declaringType.GetMethod(methodName, flags, null, args, null); } else { flags |= BindingFlags.Instance; _shouldSerializeMethod = declaringType.GetMethod(methodName, flags, null, args, null); } _hasShouldSerializeMethodBeenLookedup = true; } // Invoke the method if we found one if (_shouldSerializeMethod != null) { bool result; var args = new object[] { instance as DependencyObject }; if (_member.IsAttachable) { result = (bool)_shouldSerializeMethod.Invoke(null, args); } else { result = (bool)_shouldSerializeMethod.Invoke(instance, args); } return result ? ShouldSerializeResult.True : ShouldSerializeResult.False; } DependencyObject dObject = instance as DependencyObject; if (dObject != null && _member.DependencyProperty != null) { // Call DO's ShouldSerializeProperty to see if the property is set. // If the property is unset, the property should not be serialized bool isPropertySet = dObject.ShouldSerializeProperty(_member.DependencyProperty); if (!isPropertySet) { return ShouldSerializeResult.False; } } return base.ShouldSerializeValue(instance); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections.Generic; using System.Text; using System.Xaml.Schema; using System.Reflection; namespace System.Windows.Baml2006 { internal class WpfMemberInvoker : XamlMemberInvoker { WpfXamlMember _member; bool _hasShouldSerializeMethodBeenLookedup = false; MethodInfo _shouldSerializeMethod = null; public WpfMemberInvoker(WpfXamlMember member) : base(member) { _member = member; } public override void SetValue(object instance, object value) { DependencyObject dObject = instance as DependencyObject; if (dObject != null) { if (_member.DependencyProperty != null) { dObject.SetValue(_member.DependencyProperty, value); return; } else if (_member.RoutedEvent != null) { Delegate handler = value as Delegate; if (handler != null) { UIElement.AddHandler(dObject, _member.RoutedEvent, handler); return; } } } base.SetValue(instance, value); } public override object GetValue(object instance) { DependencyObject dObject = instance as DependencyObject; if (dObject != null && _member.DependencyProperty != null) { object result = dObject.GetValue(_member.DependencyProperty); if (result != null) { return result; } // Getter fallback: see comment on WpfXamlMember.AsContentProperty if (!_member.ApplyGetterFallback || _member.UnderlyingMember == null) { return result; } } return base.GetValue(instance); } public override ShouldSerializeResult ShouldSerializeValue(object instance) { // Look up the ShouldSerializeMethod if (!_hasShouldSerializeMethodBeenLookedup) { Type declaringType = _member.UnderlyingMember.DeclaringType; string methodName = "ShouldSerialize" + _member.Name; BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static; Type[] args = new Type[] { typeof(DependencyObject) }; ; if (_member.IsAttachable) { _shouldSerializeMethod = declaringType.GetMethod(methodName, flags, null, args, null); } else { flags |= BindingFlags.Instance; _shouldSerializeMethod = declaringType.GetMethod(methodName, flags, null, args, null); } _hasShouldSerializeMethodBeenLookedup = true; } // Invoke the method if we found one if (_shouldSerializeMethod != null) { bool result; var args = new object[] { instance as DependencyObject }; if (_member.IsAttachable) { result = (bool)_shouldSerializeMethod.Invoke(null, args); } else { result = (bool)_shouldSerializeMethod.Invoke(instance, args); } return result ? ShouldSerializeResult.True : ShouldSerializeResult.False; } DependencyObject dObject = instance as DependencyObject; if (dObject != null && _member.DependencyProperty != null) { // Call DO's ShouldSerializeProperty to see if the property is set. // If the property is unset, the property should not be serialized bool isPropertySet = dObject.ShouldSerializeProperty(_member.DependencyProperty); if (!isPropertySet) { return ShouldSerializeResult.False; } } return base.ShouldSerializeValue(instance); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ProcessThreadDesigner.cs
- LabelLiteral.cs
- XmlAttributeCache.cs
- DrawingAttributesDefaultValueFactory.cs
- XDRSchema.cs
- MetadataException.cs
- DesignerActionPropertyItem.cs
- IntSecurity.cs
- TrackingProfileSerializer.cs
- DataGridItemCollection.cs
- ButtonFieldBase.cs
- AccessViolationException.cs
- WSHttpTransportSecurityElement.cs
- LinqDataSourceView.cs
- SerialPinChanges.cs
- AQNBuilder.cs
- SqlDataSourceFilteringEventArgs.cs
- DesignerRegion.cs
- RubberbandSelector.cs
- DbConnectionStringCommon.cs
- RewritingPass.cs
- MultipartContentParser.cs
- TimeSpanValidatorAttribute.cs
- RectAnimationClockResource.cs
- AssemblyBuilderData.cs
- BoundField.cs
- DataGridViewTextBoxEditingControl.cs
- TogglePattern.cs
- DBCommand.cs
- ParameterToken.cs
- ToolboxItemFilterAttribute.cs
- RelatedView.cs
- SoapSchemaExporter.cs
- TargetConverter.cs
- QueryCacheEntry.cs
- WebPartConnection.cs
- SqlDataReaderSmi.cs
- ColorDialog.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- CommonRemoteMemoryBlock.cs
- AuthorizationBehavior.cs
- login.cs
- ColumnMapProcessor.cs
- ObjectDisposedException.cs
- ConfigXmlWhitespace.cs
- SessionStateItemCollection.cs
- Cloud.cs
- WriteTimeStream.cs
- StorageSetMapping.cs
- DesignerActionMethodItem.cs
- BuildResultCache.cs
- WebServiceClientProxyGenerator.cs
- MailBnfHelper.cs
- Hashtable.cs
- EmptyEnumerable.cs
- Propagator.Evaluator.cs
- figurelength.cs
- VariableQuery.cs
- _BasicClient.cs
- SQLString.cs
- OrthographicCamera.cs
- TreeNodeMouseHoverEvent.cs
- xml.cs
- GridViewDeleteEventArgs.cs
- CacheRequest.cs
- ImageInfo.cs
- DbDataRecord.cs
- BamlStream.cs
- CodeSnippetTypeMember.cs
- XmlCompatibilityReader.cs
- WindowsFormsSynchronizationContext.cs
- ModelItemCollection.cs
- CatalogZoneBase.cs
- SystemUdpStatistics.cs
- WebPartZoneBase.cs
- KeyEventArgs.cs
- TypeReference.cs
- RuleRef.cs
- ParseChildrenAsPropertiesAttribute.cs
- CounterCreationDataCollection.cs
- __ConsoleStream.cs
- SrgsItemList.cs
- ColumnBinding.cs
- wgx_sdk_version.cs
- RenderingBiasValidation.cs
- MasterPageParser.cs
- PieceNameHelper.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- Int16AnimationBase.cs
- Hash.cs
- Vertex.cs
- DataViewListener.cs
- RecipientInfo.cs
- Propagator.ExtentPlaceholderCreator.cs
- RegexWriter.cs
- _DigestClient.cs
- RequestCacheValidator.cs
- SqlExpander.cs
- LogicalTreeHelper.cs
- WmpBitmapEncoder.cs