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
- BindingObserver.cs
- TrustSection.cs
- SessionStateSection.cs
- AnnotationHighlightLayer.cs
- MetafileHeaderWmf.cs
- Evidence.cs
- FormViewPageEventArgs.cs
- ObjectToIdCache.cs
- ValidationSummary.cs
- SelectionManager.cs
- UIElement.cs
- ColorTransform.cs
- PersonalizationAdministration.cs
- PerformanceCounters.cs
- KeyConverter.cs
- XslNumber.cs
- WebPartPersonalization.cs
- BufferedStream2.cs
- SimplePropertyEntry.cs
- ContextMenu.cs
- CodeAccessSecurityEngine.cs
- PageContentCollection.cs
- SQLInt16.cs
- OleStrCAMarshaler.cs
- ReadOnlyHierarchicalDataSource.cs
- WindowsTooltip.cs
- AtomParser.cs
- DataKey.cs
- WindowsProgressbar.cs
- RoleManagerSection.cs
- HierarchicalDataSourceControl.cs
- DynamicPropertyHolder.cs
- FixedSOMGroup.cs
- TypefaceMetricsCache.cs
- MethodBuilderInstantiation.cs
- StructuredType.cs
- TableLayoutStyleCollection.cs
- DataTableCollection.cs
- Rss20FeedFormatter.cs
- SubclassTypeValidatorAttribute.cs
- HelpOperationInvoker.cs
- DrawingGroupDrawingContext.cs
- ErrorTableItemStyle.cs
- FixedSchema.cs
- SpecialTypeDataContract.cs
- CircleHotSpot.cs
- SecurityPermission.cs
- TrustLevelCollection.cs
- PropertiesTab.cs
- EngineSiteSapi.cs
- TransformedBitmap.cs
- MsmqHostedTransportManager.cs
- XmlSchema.cs
- DebugInfoGenerator.cs
- HtmlInputButton.cs
- XmlArrayItemAttribute.cs
- GridEntryCollection.cs
- SHA512Managed.cs
- TraceData.cs
- EditorPart.cs
- DBCSCodePageEncoding.cs
- RecognizerInfo.cs
- QuotedStringWriteStateInfo.cs
- Soap.cs
- PerformanceCounterPermission.cs
- Mapping.cs
- NativeRecognizer.cs
- DrawingContextDrawingContextWalker.cs
- SecureEnvironment.cs
- ScrollChrome.cs
- XmlSignificantWhitespace.cs
- PrePostDescendentsWalker.cs
- CompilerScope.cs
- PackageProperties.cs
- ScriptComponentDescriptor.cs
- DataSourceHelper.cs
- InternalSafeNativeMethods.cs
- Vector.cs
- ItemsPresenter.cs
- BitmapCodecInfoInternal.cs
- BaseParser.cs
- DataControlFieldCollection.cs
- RelAssertionDirectKeyIdentifierClause.cs
- DataGridViewRowsAddedEventArgs.cs
- RegisteredArrayDeclaration.cs
- Rectangle.cs
- SmtpClient.cs
- LayoutExceptionEventArgs.cs
- Scalars.cs
- SQLConvert.cs
- PtsPage.cs
- EntityWithKeyStrategy.cs
- SqlBooleanizer.cs
- ClientSession.cs
- ObsoleteAttribute.cs
- DataObjectMethodAttribute.cs
- MouseCaptureWithinProperty.cs
- SByte.cs
- DecoderFallback.cs
- RegexCode.cs