Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / Host / Serialization / ResourcePropertyMemberCodeDomSerializer.cs / 2 / ResourcePropertyMemberCodeDomSerializer.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.ComponentModel.Design.Serialization { using System; using System.CodeDom; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design; using System.Diagnostics; using System.Globalization; using System.Resources; using System.Windows.Forms; using System.Windows.Forms.Design; ////// This serializer replaces the property serializer for properties when we're /// in localization mode. /// internal class ResourcePropertyMemberCodeDomSerializer : MemberCodeDomSerializer { private CodeDomLocalizationModel _model; private MemberCodeDomSerializer _serializer; private CodeDomLocalizationProvider.LanguageExtenders _extender; private CultureInfo localizationLanguage = null; internal ResourcePropertyMemberCodeDomSerializer(MemberCodeDomSerializer serializer, CodeDomLocalizationProvider.LanguageExtenders extender, CodeDomLocalizationModel model) { Debug.Assert(extender != null, "Extender should have been created by now."); _serializer = serializer; _extender = extender; _model = model; } ////// This method actually performs the serialization. When the member is serialized /// the necessary statements will be added to the statements collection. /// public override void Serialize(IDesignerSerializationManager manager, object value, MemberDescriptor descriptor, CodeStatementCollection statements) { // We push the localization model to indicate that our serializer is in control. Our // serialization provider looks for this and decides what type of resource serializer // to give us. manager.Context.Push(_model); try { _serializer.Serialize(manager, value, descriptor, statements); } finally { manager.Context.Pop(); } } private CultureInfo GetLocalizationLanguage(IDesignerSerializationManager manager) { if (localizationLanguage == null) { // Check to see if our base component's localizable prop is true RootContext rootCxt = manager.Context[typeof(RootContext)] as RootContext; if (rootCxt != null) { object comp = rootCxt.Value; PropertyDescriptor prop = TypeDescriptor.GetProperties(comp)["LoadLanguage"]; if (prop != null && prop.PropertyType == typeof(CultureInfo)) { localizationLanguage = (CultureInfo)prop.GetValue(comp); } } } return localizationLanguage; } private void OnSerializationComplete(object sender, EventArgs e) { // we do the cleanup here and clear out the cache of the localizedlanguage localizationLanguage = null; //unhook the event IDesignerSerializationManager manager = sender as IDesignerSerializationManager; Debug.Assert(manager != null, "manager should not be null!"); if(manager != null) { manager.SerializationComplete -= new EventHandler(OnSerializationComplete); } } ////// 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) { bool shouldSerialize = _serializer.ShouldSerialize(manager, value, descriptor); if (!shouldSerialize && !descriptor.Attributes.Contains(DesignOnlyAttribute.Yes)) { switch (_model) { case CodeDomLocalizationModel.PropertyReflection : if(!shouldSerialize) { // hook up the event the first time to clear out our cache at the end of the serialization if(localizationLanguage == null) { manager.SerializationComplete += new EventHandler(OnSerializationComplete); } if(GetLocalizationLanguage(manager) != CultureInfo.InvariantCulture) { shouldSerialize = true; } } break; case CodeDomLocalizationModel.PropertyAssignment : // If this property contains its default value, we still want to serialize it if we are in // localization mode if we are writing to the default culture, but only if the object // is not inherited. InheritanceAttribute inheritance = (InheritanceAttribute)manager.Context[typeof(InheritanceAttribute)]; if (inheritance == null) { inheritance = (InheritanceAttribute)TypeDescriptor.GetAttributes(value)[typeof(InheritanceAttribute)]; if (inheritance == null) { inheritance = InheritanceAttribute.NotInherited; } } if (inheritance.InheritanceLevel != InheritanceLevel.InheritedReadOnly) { shouldSerialize = true; } break; default : break; } } return shouldSerialize; } } } // 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
- XmlBindingWorker.cs
- XamlPoint3DCollectionSerializer.cs
- RequiredFieldValidator.cs
- StubHelpers.cs
- PathTooLongException.cs
- ReachPrintTicketSerializer.cs
- XhtmlBasicTextViewAdapter.cs
- WebBaseEventKeyComparer.cs
- WriteTimeStream.cs
- QuaternionAnimationBase.cs
- HtmlInputSubmit.cs
- VirtualPath.cs
- CodeAttributeDeclaration.cs
- IsolatedStorageFile.cs
- HMACSHA512.cs
- FormatterConverter.cs
- SamlAttributeStatement.cs
- NextPreviousPagerField.cs
- ReadWriteSpinLock.cs
- StructuralObject.cs
- BindingMAnagerBase.cs
- HandlerFactoryWrapper.cs
- RedirectionProxy.cs
- DataGridViewRow.cs
- EditorPartChrome.cs
- ContainerUIElement3D.cs
- AnnouncementSendsAsyncResult.cs
- TextTabProperties.cs
- ConfigXmlText.cs
- cache.cs
- HttpHandlerActionCollection.cs
- Brush.cs
- GeometryConverter.cs
- Proxy.cs
- IDispatchConstantAttribute.cs
- CodeMemberField.cs
- XmlSchemaValidator.cs
- DateBoldEvent.cs
- CounterSampleCalculator.cs
- Viewport3DAutomationPeer.cs
- WindowsFormsHelpers.cs
- XmlILAnnotation.cs
- AddInEnvironment.cs
- FocusWithinProperty.cs
- RequestCache.cs
- SchemaInfo.cs
- Privilege.cs
- XamlClipboardData.cs
- FrameDimension.cs
- DateTimePicker.cs
- SocketPermission.cs
- ManualWorkflowSchedulerService.cs
- SystemThemeKey.cs
- ConsoleKeyInfo.cs
- ReceiveContext.cs
- GridViewCommandEventArgs.cs
- FileUtil.cs
- BitmapEffectDrawingContextState.cs
- Int64Storage.cs
- ProfileService.cs
- DataBindingList.cs
- WebPartZoneBase.cs
- TransformedBitmap.cs
- PointUtil.cs
- ManagementClass.cs
- CrossContextChannel.cs
- RawStylusInput.cs
- XsltConvert.cs
- Selector.cs
- TemplateControl.cs
- DrawingDrawingContext.cs
- WorkflowOperationBehavior.cs
- PropertyGridDesigner.cs
- List.cs
- TypeConverterAttribute.cs
- NativeMethods.cs
- LambdaCompiler.Lambda.cs
- SmtpNtlmAuthenticationModule.cs
- mediapermission.cs
- KeyedCollection.cs
- DiscoveryRequestHandler.cs
- AlphabeticalEnumConverter.cs
- ConnectionStringsExpressionEditor.cs
- ZipIOExtraField.cs
- ProcessModuleCollection.cs
- SrgsItemList.cs
- ComMethodElement.cs
- PrintDialogDesigner.cs
- HttpHandlersSection.cs
- BitmapDecoder.cs
- ConnectionStringsExpressionBuilder.cs
- ScriptControl.cs
- EventWaitHandleSecurity.cs
- UInt16Storage.cs
- DefaultAssemblyResolver.cs
- Convert.cs
- UseAttributeSetsAction.cs
- DesignerWidgets.cs
- CompletedAsyncResult.cs
- input.cs