Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / FaultReason.cs / 1 / FaultReason.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel { using System.Collections.Generic; using System.Globalization; public class FaultReason { SynchronizedReadOnlyCollectiontranslations; public FaultReason(FaultReasonText translation) { if (translation == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("translation"); Init(translation); } public FaultReason(string text) { // Let FaultReasonText constructor throw Init(new FaultReasonText(text)); } internal FaultReason(string text, string xmlLang) { // Let FaultReasonText constructor throw Init(new FaultReasonText(text, xmlLang)); } internal FaultReason(string text, CultureInfo cultureInfo) { // Let FaultReasonText constructor throw Init(new FaultReasonText(text, cultureInfo)); } public FaultReason(IEnumerable translations) { if (translations == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("translations")); int count = 0; foreach (FaultReasonText faultReasonText in translations) count++; if (count == 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.AtLeastOneFaultReasonMustBeSpecified), "translations")); FaultReasonText[] array = new FaultReasonText[count]; int index = 0; foreach (FaultReasonText faultReasonText in translations) { if (faultReasonText == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("translations", SR.GetString(SR.NoNullTranslations)); array[index++] = faultReasonText; } Init(array); } void Init(FaultReasonText translation) { Init(new FaultReasonText[] { translation }); } void Init(FaultReasonText[] translations) { this.translations = new SynchronizedReadOnlyCollection (new object(), Array.AsReadOnly (translations)); } public FaultReasonText GetMatchingTranslation() { return GetMatchingTranslation(CultureInfo.CurrentCulture); } // [....], This function should always return a translation so that a fault can be surfaced. public FaultReasonText GetMatchingTranslation(CultureInfo cultureInfo) { if (cultureInfo == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("cultureInfo")); // If there's only one translation, use it if (translations.Count == 1) return translations[0]; // Search for an exact match for (int i = 0; i < translations.Count; i++) if (translations[i].Matches(cultureInfo)) return translations[i]; // If no exact match is found, proceed by looking for the a translation with a language that is a parent of the current culture if (translations.Count == 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.NoMatchingTranslationFoundForFaultText))); // Search for a more general language #pragma warning suppress 56506 string localLang = cultureInfo.Name; while (true) { int idx = localLang.LastIndexOf('-'); // We don't want to accept xml:lang="" if (idx == -1) break; // Clip off the last subtag and look for a match localLang = localLang.Substring(0, idx); for (int i = 0; i < translations.Count; i++) if (translations[i].XmlLang == localLang) return translations[i]; } // Return the first translation if no match is found return translations[0]; } public SynchronizedReadOnlyCollection Translations { get { return translations; } } public override string ToString() { if (translations.Count == 0) return string.Empty; return GetMatchingTranslation().Text; } } } // 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
- ContourSegment.cs
- DataGridViewDesigner.cs
- ServiceModelConfigurationSectionCollection.cs
- WebBrowser.cs
- FieldToken.cs
- PathData.cs
- OneOfConst.cs
- SchemeSettingElementCollection.cs
- SystemDiagnosticsSection.cs
- Shape.cs
- ViewSimplifier.cs
- UrlMapping.cs
- GeneralTransform3DTo2D.cs
- TextUtf8RawTextWriter.cs
- CategoryState.cs
- InlineCollection.cs
- ReferenceCountedObject.cs
- PageRequestManager.cs
- UdpTransportBindingElement.cs
- OleDbPropertySetGuid.cs
- TreeNode.cs
- XDeferredAxisSource.cs
- sqlser.cs
- RequestBringIntoViewEventArgs.cs
- filewebresponse.cs
- AxHost.cs
- SpellerHighlightLayer.cs
- RegisteredScript.cs
- CssStyleCollection.cs
- WizardForm.cs
- InternalConfigEventArgs.cs
- XmlCharType.cs
- ServiceContractViewControl.Designer.cs
- MetadataArtifactLoaderComposite.cs
- SelectionRange.cs
- Win32SafeHandles.cs
- AncestorChangedEventArgs.cs
- ItemChangedEventArgs.cs
- EncoderParameters.cs
- DataContractSerializerElement.cs
- UncommonField.cs
- SmtpNetworkElement.cs
- MenuEventArgs.cs
- DecoderExceptionFallback.cs
- ellipse.cs
- SecurityElementBase.cs
- InkSerializer.cs
- SqlUnionizer.cs
- TextWriterTraceListener.cs
- DocumentSchemaValidator.cs
- CollaborationHelperFunctions.cs
- FixedDSBuilder.cs
- XmlQuerySequence.cs
- CleanUpVirtualizedItemEventArgs.cs
- SynthesizerStateChangedEventArgs.cs
- DataGridViewAccessibleObject.cs
- StdValidatorsAndConverters.cs
- CultureMapper.cs
- FigureParaClient.cs
- SettingsBase.cs
- CrossAppDomainChannel.cs
- IIS7UserPrincipal.cs
- ReferencedCollectionType.cs
- WebBrowserDocumentCompletedEventHandler.cs
- TextElementCollectionHelper.cs
- CompoundFileReference.cs
- ActivationServices.cs
- ServiceDescriptions.cs
- CheckBoxAutomationPeer.cs
- GeneralTransformGroup.cs
- DataSpaceManager.cs
- TableLayoutPanelCellPosition.cs
- WebPartTransformerAttribute.cs
- EventTrigger.cs
- InputBinder.cs
- BitmapFrameDecode.cs
- IntSecurity.cs
- DateTimeFormat.cs
- Wildcard.cs
- ListSortDescription.cs
- UIElementHelper.cs
- MediaContext.cs
- CapabilitiesPattern.cs
- NameScope.cs
- WebPartDisplayMode.cs
- CssClassPropertyAttribute.cs
- Validator.cs
- DrawingVisual.cs
- SystemFonts.cs
- CodeGen.cs
- SchemaSetCompiler.cs
- SecurityKeyIdentifier.cs
- COM2ExtendedBrowsingHandler.cs
- XmlSchemaCompilationSettings.cs
- StylusButtonEventArgs.cs
- HitTestWithGeometryDrawingContextWalker.cs
- GridViewRowCollection.cs
- KeyBinding.cs
- BlockExpression.cs
- EmptyQuery.cs