Code:
/ 4.0 / 4.0 / 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. 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
- MenuItemStyleCollectionEditor.cs
- SocketPermission.cs
- SettingsPropertyValue.cs
- ConfigurationErrorsException.cs
- Hyperlink.cs
- AbstractSvcMapFileLoader.cs
- TCEAdapterGenerator.cs
- SelectorAutomationPeer.cs
- Random.cs
- TypedTableBaseExtensions.cs
- EmbeddedObject.cs
- CodeMemberEvent.cs
- ConstraintManager.cs
- ImageButton.cs
- CallTemplateAction.cs
- AppDomainResourcePerfCounters.cs
- MessageBox.cs
- AvtEvent.cs
- FamilyMap.cs
- FilterElement.cs
- Compensation.cs
- StringConcat.cs
- LingerOption.cs
- XXXOnTypeBuilderInstantiation.cs
- ScalarConstant.cs
- DeploymentSectionCache.cs
- AspNetHostingPermission.cs
- WinEventHandler.cs
- ToolStripScrollButton.cs
- DbParameterCollectionHelper.cs
- WaitHandleCannotBeOpenedException.cs
- DataRowCollection.cs
- FunctionQuery.cs
- ClientSettingsSection.cs
- SQLDateTime.cs
- ArrangedElement.cs
- AssociationSetMetadata.cs
- NetworkCredential.cs
- LinkAreaEditor.cs
- CachedPathData.cs
- DuplicateWaitObjectException.cs
- WebBrowserContainer.cs
- CodeMemberEvent.cs
- TableStyle.cs
- CloudCollection.cs
- FormatVersion.cs
- XmlSchemaParticle.cs
- AutomationProperties.cs
- SQLInt16.cs
- OracleMonthSpan.cs
- DbTransaction.cs
- Command.cs
- DataBinding.cs
- XmlTypeMapping.cs
- QilCloneVisitor.cs
- SymbolUsageManager.cs
- ColumnWidthChangingEvent.cs
- CompositeClientFormatter.cs
- Wildcard.cs
- ContentValidator.cs
- LeaseManager.cs
- EventPrivateKey.cs
- DictionaryBase.cs
- XmlTextEncoder.cs
- TextBoxAutomationPeer.cs
- ParserContext.cs
- MimeFormReflector.cs
- SelectingProviderEventArgs.cs
- AtomServiceDocumentSerializer.cs
- ComPlusServiceHost.cs
- WCFServiceClientProxyGenerator.cs
- PeerTransportBindingElement.cs
- GridViewCancelEditEventArgs.cs
- RadioButton.cs
- _NetRes.cs
- ErrorRuntimeConfig.cs
- ComboBoxAutomationPeer.cs
- XPathQueryGenerator.cs
- DigitalSignatureProvider.cs
- BuildProvider.cs
- MarkedHighlightComponent.cs
- CredentialCache.cs
- ConcurrentDictionary.cs
- DateTimePicker.cs
- XslCompiledTransform.cs
- NumericUpDown.cs
- EmptyControlCollection.cs
- EntityEntry.cs
- Action.cs
- ClockGroup.cs
- Property.cs
- SerialStream.cs
- SqlMultiplexer.cs
- MissingSatelliteAssemblyException.cs
- MetabaseSettingsIis7.cs
- Transaction.cs
- Misc.cs
- BaseCAMarshaler.cs
- QueryExecutionOption.cs
- AnnotationStore.cs