Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Markup / Baml2006 / WpfKnownMemberInvoker.cs / 1305600 / WpfKnownMemberInvoker.cs
using System; using System.Collections.Generic; using System.Text; using System.Xaml.Schema; using System.Reflection; namespace System.Windows.Baml2006 { class WpfKnownMemberInvoker : XamlMemberInvoker { WpfKnownMember _member; bool _hasShouldSerializeMethodBeenLookedup = false; MethodInfo _shouldSerializeMethod = null; public WpfKnownMemberInvoker(WpfKnownMember member) : base(member) { _member = member; } public override object GetValue(object instance) { if (_member.DependencyProperty != null) { return ((DependencyObject)instance).GetValue(_member.DependencyProperty); } else { return _member.GetDelegate(instance); } } public override void SetValue(object instance, object value) { if (_member.DependencyProperty != null) { ((DependencyObject)instance).SetValue(_member.DependencyProperty, value); } else { _member.SetDelegate(instance, value); } } 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
- FrameSecurityDescriptor.cs
- EventLogPermissionEntryCollection.cs
- SR.Designer.cs
- WaitHandle.cs
- QueryableFilterUserControl.cs
- XmlReaderSettings.cs
- TextLine.cs
- SessionIDManager.cs
- RenameRuleObjectDialog.cs
- XmlSchemaCompilationSettings.cs
- ServiceDebugElement.cs
- XmlNodeList.cs
- WindowsToolbarItemAsMenuItem.cs
- RectangleGeometry.cs
- StorageComplexPropertyMapping.cs
- DesignerValidatorAdapter.cs
- IntegerValidatorAttribute.cs
- ObjectNavigationPropertyMapping.cs
- StrokeCollection2.cs
- SharedPersonalizationStateInfo.cs
- MergablePropertyAttribute.cs
- XamlInt32CollectionSerializer.cs
- SelectorAutomationPeer.cs
- DataServiceStreamProviderWrapper.cs
- DummyDataSource.cs
- XmlDataCollection.cs
- KeyTimeConverter.cs
- SignatureDescription.cs
- Int32EqualityComparer.cs
- SafeMarshalContext.cs
- PageAsyncTaskManager.cs
- WmlMobileTextWriter.cs
- ColumnClickEvent.cs
- StateWorkerRequest.cs
- PackageFilter.cs
- StyleSelector.cs
- RouteValueExpressionBuilder.cs
- RadialGradientBrush.cs
- DirectoryNotFoundException.cs
- DataFormats.cs
- PeerCollaborationPermission.cs
- CursorInteropHelper.cs
- ProfileProvider.cs
- List.cs
- ButtonBase.cs
- DateTimeValueSerializerContext.cs
- XmlWrappingReader.cs
- ProcessInfo.cs
- LoginView.cs
- SoapSchemaImporter.cs
- Configuration.cs
- CodeDelegateCreateExpression.cs
- RoutedEventConverter.cs
- ContextDataSourceContextData.cs
- ApplicationActivator.cs
- RuntimeWrappedException.cs
- WorkflowMarkupSerializationException.cs
- _LazyAsyncResult.cs
- DataListComponentEditor.cs
- RectAnimation.cs
- PropertyInfoSet.cs
- MethodCallTranslator.cs
- SqlIdentifier.cs
- TracePayload.cs
- DataTableMapping.cs
- SoapSchemaImporter.cs
- BooleanExpr.cs
- LineSegment.cs
- GregorianCalendar.cs
- ObsoleteAttribute.cs
- cache.cs
- GlyphShapingProperties.cs
- GridViewDeleteEventArgs.cs
- WindowsUpDown.cs
- Constants.cs
- CollectionCodeDomSerializer.cs
- SequentialWorkflowHeaderFooter.cs
- ConstructorBuilder.cs
- InvokeHandlers.cs
- CqlWriter.cs
- MediaSystem.cs
- BamlResourceDeserializer.cs
- LineInfo.cs
- Msec.cs
- DataGridCell.cs
- TextDecorationUnitValidation.cs
- XmlRawWriterWrapper.cs
- FormViewModeEventArgs.cs
- FigureHelper.cs
- XmlSchemaDocumentation.cs
- RecordsAffectedEventArgs.cs
- NamedPipeActivation.cs
- SecurityDescriptor.cs
- MappingSource.cs
- FixedSOMFixedBlock.cs
- RemoteX509Token.cs
- BaseTransportHeaders.cs
- TcpAppDomainProtocolHandler.cs
- MasterPageBuildProvider.cs
- BufferedWebEventProvider.cs