Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / CompMod / System / ComponentModel / Design / Serialization / EventMemberCodeDomSerializer.cs / 1 / EventMemberCodeDomSerializer.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.ComponentModel.Design.Serialization { using System; using System.CodeDom; using System.ComponentModel.Design; using System.Design; using System.Diagnostics; using System.Reflection; ////// A MemberCodeDomSerializer for events. /// internal sealed class EventMemberCodeDomSerializer : MemberCodeDomSerializer { private static CodeThisReferenceExpression _thisRef = new CodeThisReferenceExpression(); private static EventMemberCodeDomSerializer _default; internal static EventMemberCodeDomSerializer Default { get { if (_default == null) _default = new EventMemberCodeDomSerializer(); return _default; } } ////// This method actually performs the serialization. When the member is serialized /// the necessary statements will be added to the statements collection. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2102:CatchNonClsCompliantExceptionsInGeneralHandlers")] public override void Serialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor, CodeStatementCollection statements) { EventDescriptor eventToSerialize = descriptor as EventDescriptor; if (manager == null) throw new ArgumentNullException("manager"); if (value == null) throw new ArgumentNullException("value"); if (eventToSerialize == null) throw new ArgumentNullException("descriptor"); if (statements == null) throw new ArgumentNullException("statements"); try { IEventBindingService eventBindings = (IEventBindingService)manager.GetService(typeof(IEventBindingService)); // VSWhidbey 204574: If the IEventBindingService is not available, we don't throw - we just don't do // anything. if (eventBindings != null) { PropertyDescriptor prop = eventBindings.GetEventProperty(eventToSerialize); string methodName = (string)prop.GetValue(value); if (methodName != null) { CodeDomSerializer.Trace("Event {0} bound to {1}", eventToSerialize.Name, methodName); CodeExpression eventTarget = SerializeToExpression(manager, value); CodeDomSerializer.TraceWarningIf(eventTarget == null, "Object has no name and no propery ref in context so we cannot serialize events: {0}", value); if (eventTarget != null) { CodeTypeReference delegateTypeRef = new CodeTypeReference(eventToSerialize.EventType); CodeDelegateCreateExpression delegateCreate = new CodeDelegateCreateExpression(delegateTypeRef, _thisRef, methodName); CodeEventReferenceExpression eventRef = new CodeEventReferenceExpression(eventTarget, eventToSerialize.Name); CodeAttachEventStatement attach = new CodeAttachEventStatement(eventRef, delegateCreate); attach.UserData[typeof(Delegate)] = eventToSerialize.EventType; statements.Add(attach); } } } } catch (Exception e) { // Since we usually go through reflection, don't // show what our engine does, show what caused // the problem. // if (e is TargetInvocationException) { e = e.InnerException; } manager.ReportError(SR.GetString(SR.SerializerPropertyGenFailed, eventToSerialize.Name, e.Message)); } } ////// This method returns true if the given member descriptor should be serialized, /// or false if there is no need to serialize the member. /// public override bool ShouldSerialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor) { return true; } } } // 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
- ApplicationTrust.cs
- XamlWriterExtensions.cs
- RegexCaptureCollection.cs
- UnsupportedPolicyOptionsException.cs
- EncoderFallback.cs
- Point3DCollectionConverter.cs
- Permission.cs
- RsaSecurityKey.cs
- CustomWebEventKey.cs
- DeviceContext.cs
- HeaderCollection.cs
- ImageClickEventArgs.cs
- WriteTimeStream.cs
- TraceRecord.cs
- Line.cs
- XmlTypeMapping.cs
- Accessible.cs
- SiteMapSection.cs
- SplineQuaternionKeyFrame.cs
- DefaultClaimSet.cs
- DateTimeParse.cs
- iisPickupDirectory.cs
- WmlPageAdapter.cs
- WebPartDisplayModeCancelEventArgs.cs
- PropertyNames.cs
- ListChangedEventArgs.cs
- WebServiceData.cs
- LinkLabelLinkClickedEvent.cs
- ConnectionConsumerAttribute.cs
- ImmutableObjectAttribute.cs
- Version.cs
- DragSelectionMessageFilter.cs
- XhtmlBasicTextBoxAdapter.cs
- CommandField.cs
- AttachedPropertiesService.cs
- ExponentialEase.cs
- FlowDocumentPage.cs
- AdornerLayer.cs
- ReaderWriterLockWrapper.cs
- XmlCodeExporter.cs
- WebPartConnection.cs
- EntityClientCacheEntry.cs
- CrossSiteScriptingValidation.cs
- KnownTypeDataContractResolver.cs
- ServiceBehaviorElementCollection.cs
- ColorConvertedBitmap.cs
- FrameworkElementAutomationPeer.cs
- SystemColorTracker.cs
- InputBindingCollection.cs
- ShapingEngine.cs
- HttpServerProtocol.cs
- ComplexPropertyEntry.cs
- HierarchicalDataTemplate.cs
- TableLayoutRowStyleCollection.cs
- COM2FontConverter.cs
- ApplicationServiceManager.cs
- FixedSOMTableCell.cs
- XPathAncestorQuery.cs
- SelfIssuedAuthRSAPKCS1SignatureFormatter.cs
- Compiler.cs
- IsolationInterop.cs
- AlphabetConverter.cs
- TextRange.cs
- SystemColors.cs
- QuadraticBezierSegment.cs
- DictionaryBase.cs
- ComAdminWrapper.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- OdbcConnectionStringbuilder.cs
- BulletedList.cs
- BindingMemberInfo.cs
- ListItem.cs
- GenericTypeParameterBuilder.cs
- Vector3DIndependentAnimationStorage.cs
- PointUtil.cs
- SymbolMethod.cs
- StorageMappingItemCollection.cs
- Hash.cs
- TextEncodedRawTextWriter.cs
- MruCache.cs
- CodeTypeDeclaration.cs
- TextRangeEditTables.cs
- QuaternionAnimation.cs
- RIPEMD160Managed.cs
- SelectionPattern.cs
- ClientTargetSection.cs
- HelpProvider.cs
- COM2IManagedPerPropertyBrowsingHandler.cs
- XPathNavigatorException.cs
- SvcMapFileLoader.cs
- PartialToken.cs
- DataObjectPastingEventArgs.cs
- PropertyPathWorker.cs
- ContextProperty.cs
- PlatformNotSupportedException.cs
- HelloMessageCD1.cs
- AmbientProperties.cs
- TableItemProviderWrapper.cs
- ResourceManager.cs
- GridItemPatternIdentifiers.cs