Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / System / Windows / Markup / ArrayExtension.cs / 2 / 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
- EntityWithChangeTrackerStrategy.cs
- Types.cs
- HttpValueCollection.cs
- PathTooLongException.cs
- Schedule.cs
- InfiniteTimeSpanConverter.cs
- RoutedEventArgs.cs
- ScriptManager.cs
- PathParser.cs
- isolationinterop.cs
- ImportDesigner.xaml.cs
- MimeTextImporter.cs
- SerializerDescriptor.cs
- xmlglyphRunInfo.cs
- Polyline.cs
- RetrieveVirtualItemEventArgs.cs
- WorkflowMessageEventArgs.cs
- SmiEventStream.cs
- Matrix.cs
- TypeDescriptionProviderAttribute.cs
- TemplateBindingExtension.cs
- Menu.cs
- EdmMember.cs
- AlignmentYValidation.cs
- ReaderWriterLockWrapper.cs
- FontStyles.cs
- CategoryGridEntry.cs
- mediaeventshelper.cs
- FontStretches.cs
- Rect3D.cs
- PreProcessInputEventArgs.cs
- DiscoveryInnerClientManaged11.cs
- BaseValidatorDesigner.cs
- SmiEventSink_Default.cs
- SqlProfileProvider.cs
- Timer.cs
- ColumnTypeConverter.cs
- TransformPattern.cs
- AsymmetricKeyExchangeDeformatter.cs
- DocumentXPathNavigator.cs
- CommandTreeTypeHelper.cs
- DataObjectPastingEventArgs.cs
- MarshalDirectiveException.cs
- UInt32.cs
- DistinctQueryOperator.cs
- InternalRelationshipCollection.cs
- ApplicationException.cs
- TaiwanCalendar.cs
- UniqueConstraint.cs
- ScriptingScriptResourceHandlerSection.cs
- MobileCapabilities.cs
- PropertyChangedEventArgs.cs
- TrustLevel.cs
- SmiTypedGetterSetter.cs
- HorizontalAlignConverter.cs
- OleDbConnection.cs
- EmptyReadOnlyDictionaryInternal.cs
- XmlMapping.cs
- WindowsListViewItemCheckBox.cs
- AsymmetricAlgorithm.cs
- XNodeNavigator.cs
- Schema.cs
- GridViewUpdateEventArgs.cs
- EntityConnectionStringBuilder.cs
- sqlnorm.cs
- HashCryptoHandle.cs
- EntityDesignerBuildProvider.cs
- ModuleElement.cs
- TemplateControlParser.cs
- AnonymousIdentificationSection.cs
- RoleService.cs
- ProtocolElementCollection.cs
- ListViewTableCell.cs
- AnyAllSearchOperator.cs
- MembershipValidatePasswordEventArgs.cs
- EntityContainerEmitter.cs
- CacheEntry.cs
- DefaultObjectMappingItemCollection.cs
- SafeNativeMethods.cs
- AsyncWaitHandle.cs
- NumberFormatter.cs
- Storyboard.cs
- MgmtResManager.cs
- RelAssertionDirectKeyIdentifierClause.cs
- WebPartConnectionsDisconnectVerb.cs
- HatchBrush.cs
- NamespaceEmitter.cs
- XmlUTF8TextReader.cs
- IteratorAsyncResult.cs
- wmiprovider.cs
- SqlDependency.cs
- ActiveDocumentEvent.cs
- TextAdaptor.cs
- LeafCellTreeNode.cs
- SizeConverter.cs
- PersonalizationDictionary.cs
- ConnectionPoolRegistry.cs
- ColorDialog.cs
- MediaSystem.cs
- TimeSpanValidatorAttribute.cs