Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- ControlBuilderAttribute.cs
- CounterSample.cs
- ProfilePropertyNameValidator.cs
- LiteralControl.cs
- VisualProxy.cs
- LineSegment.cs
- MatchingStyle.cs
- HttpGetProtocolImporter.cs
- ComponentRenameEvent.cs
- DataSourceControl.cs
- DataGridViewComboBoxEditingControl.cs
- XmlAttributes.cs
- ObjectRef.cs
- CompoundFileReference.cs
- PathStreamGeometryContext.cs
- QuaternionConverter.cs
- AffineTransform3D.cs
- OleDbPropertySetGuid.cs
- EDesignUtil.cs
- SpecialNameAttribute.cs
- RulePatternOps.cs
- SubMenuStyle.cs
- MemberDescriptor.cs
- ScriptResourceAttribute.cs
- CompilerInfo.cs
- RegexRunnerFactory.cs
- ToolStripStatusLabel.cs
- DataRecordInfo.cs
- SQlBooleanStorage.cs
- DataSourceCollectionBase.cs
- ExplicitDiscriminatorMap.cs
- WebSysDisplayNameAttribute.cs
- Icon.cs
- PathSegmentCollection.cs
- FamilyTypeface.cs
- Cursors.cs
- AxHost.cs
- HTMLTextWriter.cs
- DefaultTraceListener.cs
- BasePattern.cs
- IsolatedStoragePermission.cs
- RelationshipType.cs
- Vars.cs
- DependencySource.cs
- BufferBuilder.cs
- ButtonAutomationPeer.cs
- CancellationHandler.cs
- BuilderElements.cs
- SyndicationItemFormatter.cs
- SqlClientWrapperSmiStream.cs
- GridLength.cs
- CssClassPropertyAttribute.cs
- CustomWebEventKey.cs
- BulletedListEventArgs.cs
- RadioButtonPopupAdapter.cs
- _ShellExpression.cs
- HMAC.cs
- StorageBasedPackageProperties.cs
- Crypto.cs
- ControlCachePolicy.cs
- ColumnTypeConverter.cs
- MarkupCompilePass2.cs
- RecordManager.cs
- DataTransferEventArgs.cs
- StyleCollection.cs
- EntityWrapper.cs
- ArgumentValue.cs
- PersonalizableAttribute.cs
- XmlMapping.cs
- ClientSideQueueItem.cs
- TablePatternIdentifiers.cs
- DeferredSelectedIndexReference.cs
- InfoCardMasterKey.cs
- BoundingRectTracker.cs
- safemediahandle.cs
- FrameworkRichTextComposition.cs
- ItemAutomationPeer.cs
- ScrollChrome.cs
- EndPoint.cs
- SQLBoolean.cs
- DataBoundControlHelper.cs
- CompiledQueryCacheKey.cs
- TextWriterEngine.cs
- TreeNodeBinding.cs
- SQLDouble.cs
- Constants.cs
- RuntimeConfig.cs
- GenericEnumConverter.cs
- SortKey.cs
- RemoteWebConfigurationHostStream.cs
- Suspend.cs
- LinearKeyFrames.cs
- Task.cs
- DataBoundControlAdapter.cs
- EventLogTraceListener.cs
- BooleanStorage.cs
- ComNativeDescriptor.cs
- HttpListener.cs
- Accessible.cs
- CultureInfo.cs