Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / System / Windows / Markup / ArrayExtension.cs / 1 / ArrayExtension.cs
/****************************************************************************\ * * File: ArrayExtension.cs * * Class for Xaml markup extension for Arrays * * Copyright (C) 2004 by Microsoft Corporation. All rights reserved. * \***************************************************************************/ using System; using System.Windows; using System.Collections; using System.ComponentModel; namespace System.Windows.Markup { ////// Class for Xaml markup extension for Arrays. /// [ContentProperty("Items")] [MarkupExtensionReturnType(typeof(Array))] public class ArrayExtension : MarkupExtension, IAddChild { ////// Constructor that takes no parameters. This creates an empty array. /// public ArrayExtension() { } ////// Constructor that takes one parameter. This initializes the type of the array. /// public ArrayExtension( Type arrayType) { if (arrayType == null) { throw new ArgumentNullException("arrayType"); } _arrayType = arrayType; } ////// Constructor for writing /// /// The array to write public ArrayExtension(Array elements) { _arrayList.AddRange(elements); _arrayType = elements.GetType().GetElementType(); } ////// Called to Add an object as a new array item. This will append the object to the end /// of the array. /// /// /// Object to add to the end of the array. /// public void AddChild(Object value) { _arrayList.Add(value); } ////// Called to Add a text as a new array item. This will append the object to the end /// of the array. /// /// /// Text to Add to the end of the array /// public void AddText(string text) { AddChild(text); } ////// Get and set the type of array to be created when calling ProvideValue /// [ConstructorArgument("type")] public Type Type { get { return _arrayType; } set { _arrayType = value; } } ////// An IList accessor to the contents of the array /// [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public IList Items { get { return _arrayList; } } ////// Return an array that is sized to the number of objects added to the ArrayExtension. /// /// Object that can provide services for the markup extension. ////// The Array containing all the objects added to this extension. /// public override object ProvideValue(IServiceProvider serviceProvider) { if (_arrayType == null) { throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionArrayType)); } object retArray = null; try { retArray = _arrayList.ToArray(_arrayType); } catch (System.InvalidCastException) { // If an element was added to the ArrayExtension that does not agree with the // ArrayType, then an InvalidCastException will occur. Generate a more // meaningful error for this case. throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionArrayBadType, _arrayType.Name)); } return retArray; } private ArrayList _arrayList = new ArrayList(); private Type _arrayType; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /****************************************************************************\ * * File: ArrayExtension.cs * * Class for Xaml markup extension for Arrays * * Copyright (C) 2004 by Microsoft Corporation. All rights reserved. * \***************************************************************************/ using System; using System.Windows; using System.Collections; using System.ComponentModel; namespace System.Windows.Markup { ////// Class for Xaml markup extension for Arrays. /// [ContentProperty("Items")] [MarkupExtensionReturnType(typeof(Array))] public class ArrayExtension : MarkupExtension, IAddChild { ////// Constructor that takes no parameters. This creates an empty array. /// public ArrayExtension() { } ////// Constructor that takes one parameter. This initializes the type of the array. /// public ArrayExtension( Type arrayType) { if (arrayType == null) { throw new ArgumentNullException("arrayType"); } _arrayType = arrayType; } ////// Constructor for writing /// /// The array to write public ArrayExtension(Array elements) { _arrayList.AddRange(elements); _arrayType = elements.GetType().GetElementType(); } ////// Called to Add an object as a new array item. This will append the object to the end /// of the array. /// /// /// Object to add to the end of the array. /// public void AddChild(Object value) { _arrayList.Add(value); } ////// Called to Add a text as a new array item. This will append the object to the end /// of the array. /// /// /// Text to Add to the end of the array /// public void AddText(string text) { AddChild(text); } ////// Get and set the type of array to be created when calling ProvideValue /// [ConstructorArgument("type")] public Type Type { get { return _arrayType; } set { _arrayType = value; } } ////// An IList accessor to the contents of the array /// [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public IList Items { get { return _arrayList; } } ////// Return an array that is sized to the number of objects added to the ArrayExtension. /// /// Object that can provide services for the markup extension. ////// The Array containing all the objects added to this extension. /// public override object ProvideValue(IServiceProvider serviceProvider) { if (_arrayType == null) { throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionArrayType)); } object retArray = null; try { retArray = _arrayList.ToArray(_arrayType); } catch (System.InvalidCastException) { // If an element was added to the ArrayExtension that does not agree with the // ArrayType, then an InvalidCastException will occur. Generate a more // meaningful error for this case. throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionArrayBadType, _arrayType.Name)); } return retArray; } private ArrayList _arrayList = new ArrayList(); private Type _arrayType; } } // 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
- PrintDialog.cs
- StoryFragments.cs
- DocComment.cs
- SQLDouble.cs
- SignerInfo.cs
- Line.cs
- EndGetFileNameFromUserRequest.cs
- DataGridViewLayoutData.cs
- ISFTagAndGuidCache.cs
- Attributes.cs
- QilInvokeLateBound.cs
- WebPartRestoreVerb.cs
- SqlRemoveConstantOrderBy.cs
- WindowsAuthenticationModule.cs
- WrappedDispatcherException.cs
- ISAPIWorkerRequest.cs
- serverconfig.cs
- CodeGroup.cs
- ObjectHelper.cs
- BitmapPalette.cs
- SqlBooleanMismatchVisitor.cs
- HttpContext.cs
- EventItfInfo.cs
- CustomErrorsSection.cs
- XmlDataDocument.cs
- DoubleCollection.cs
- PnrpPeerResolverElement.cs
- MimePart.cs
- ActivityFunc.cs
- InfiniteTimeSpanConverter.cs
- ItemCheckEvent.cs
- SQLGuid.cs
- XamlSerializerUtil.cs
- OdbcReferenceCollection.cs
- DateTime.cs
- AlignmentYValidation.cs
- ComboBoxDesigner.cs
- ServicesExceptionNotHandledEventArgs.cs
- DtdParser.cs
- ExpressionTextBoxAutomationPeer.cs
- QueryGeneratorBase.cs
- XmlSchemaComplexContent.cs
- StateDesigner.Helpers.cs
- TriggerAction.cs
- CodeGotoStatement.cs
- MultiSelectRootGridEntry.cs
- OperatingSystem.cs
- XmlDigitalSignatureProcessor.cs
- ConfigXmlElement.cs
- FileNotFoundException.cs
- SafeSecurityHandles.cs
- ComponentConverter.cs
- HtmlElement.cs
- NameScopePropertyAttribute.cs
- XmlFormatExtensionPointAttribute.cs
- RegexWorker.cs
- RequestCachePolicy.cs
- BrowserCapabilitiesCodeGenerator.cs
- Model3D.cs
- XamlTypeWithExplicitNamespace.cs
- PreloadedPackages.cs
- SplashScreenNativeMethods.cs
- ClientOptions.cs
- CompilerError.cs
- WebPageTraceListener.cs
- RelatedCurrencyManager.cs
- SystemThemeKey.cs
- AppDomainProtocolHandler.cs
- TargetPerspective.cs
- FontStretches.cs
- JsonUriDataContract.cs
- DbMetaDataColumnNames.cs
- ReverseInheritProperty.cs
- SizeKeyFrameCollection.cs
- IRCollection.cs
- MenuStrip.cs
- XNameConverter.cs
- AspNetCompatibilityRequirementsMode.cs
- Util.cs
- Point3DCollection.cs
- EventsTab.cs
- DescendantOverDescendantQuery.cs
- MarshalDirectiveException.cs
- PassportPrincipal.cs
- HierarchicalDataBoundControlAdapter.cs
- SafeViewOfFileHandle.cs
- Queue.cs
- WS2007HttpBinding.cs
- TransformerTypeCollection.cs
- AddInProcess.cs
- Reference.cs
- RegionIterator.cs
- ImportCatalogPart.cs
- FileSecurity.cs
- OutOfMemoryException.cs
- QueryConverter.cs
- NativeCompoundFileAPIs.cs
- RangeValidator.cs
- RichTextBoxConstants.cs
- DataTemplate.cs