Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / MultidimensionalArrayItemReference.cs / 1305376 / MultidimensionalArrayItemReference.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Expressions { using System.Collections.ObjectModel; using System.ComponentModel; using System.Runtime; using System.Runtime.Collections; using System.Runtime.Serialization; using System.Windows.Markup; [ContentProperty("Indices")] public sealed class MultidimensionalArrayItemReference: CodeActivity > { Collection > indices; [RequiredArgument] [DefaultValue(null)] public InArgument Array { get; set; } [DefaultValue(null)] public Collection > Indices { get { if (this.indices == null) { this.indices = new ValidatingCollection > { // disallow null values OnAddValidationCallback = item => { if (item == null) { throw FxTrace.Exception.ArgumentNull("item"); } }, }; } return this.indices; } } protected override void CacheMetadata(CodeActivityMetadata metadata) { if (this.Indices.Count == 0) { metadata.AddValidationError(SR.IndicesAreNeeded(this.GetType().Name, this.DisplayName)); } RuntimeArgument arrayArgument = new RuntimeArgument("Array", typeof(Array), ArgumentDirection.In, true); metadata.Bind(this.Array, arrayArgument); metadata.AddArgument(arrayArgument); for (int i = 0; i < this.Indices.Count; i++) { RuntimeArgument indexArgument = new RuntimeArgument("Index_" + i, typeof(int), ArgumentDirection.In, true); metadata.Bind(this.Indices[i], indexArgument); metadata.AddArgument(indexArgument); } RuntimeArgument resultArgument = new RuntimeArgument("Result", typeof(Location ), ArgumentDirection.Out); metadata.Bind(this.Result, resultArgument); metadata.AddArgument(resultArgument); } protected override Location Execute(CodeActivityContext context) { Array items = this.Array.Get(context); if (items == null) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.MemberCannotBeNull("Array", this.GetType().Name, this.DisplayName))); } Type realItemType = items.GetType().GetElementType(); if (!TypeHelper.AreTypesCompatible(typeof(TItem), realItemType)) { throw FxTrace.Exception.AsError(new InvalidCastException(SR.IncompatibleTypeForMultidimensionalArrayItemReference(typeof(TItem).Name, realItemType.Name))); } int[] itemIndex = new int[this.Indices.Count]; for (int i = 0; i < this.Indices.Count; i++) { itemIndex[i] = this.Indices[i].Get(context); } return new MultidimensionArrayLocation(items, itemIndex); } [DataContract] class MultidimensionArrayLocation : Location { [DataMember] Array array; [DataMember(EmitDefaultValue = false)] int[] indices; public MultidimensionArrayLocation(Array array, int[] indices) : base() { this.array = array; this.indices = indices; } public override TItem Value { get { return (TItem)this.array.GetValue(indices); } set { this.array.SetValue(value, indices); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ObjectStateEntry.cs
- WsatServiceCertificate.cs
- XPathSelectionIterator.cs
- XmlSchemaCompilationSettings.cs
- ConfigXmlComment.cs
- CodePageUtils.cs
- ELinqQueryState.cs
- QueryConverter.cs
- Vector3dCollection.cs
- SelectiveScrollingGrid.cs
- Oci.cs
- FlowDocument.cs
- MessageDesigner.cs
- HttpCookie.cs
- GenericParameterDataContract.cs
- Menu.cs
- RemoteWebConfigurationHost.cs
- InputProcessorProfiles.cs
- GridViewCancelEditEventArgs.cs
- WorkflowPersistenceContext.cs
- ImageSourceValueSerializer.cs
- UnderstoodHeaders.cs
- SessionPageStatePersister.cs
- XmlArrayAttribute.cs
- RectangleHotSpot.cs
- EventBuilder.cs
- ColumnBinding.cs
- FixedHighlight.cs
- DrawingCollection.cs
- HybridDictionary.cs
- BaseParagraph.cs
- LinkedList.cs
- Ops.cs
- SqlConnectionFactory.cs
- CodeBinaryOperatorExpression.cs
- WebBrowserBase.cs
- ScrollChrome.cs
- ServiceDeploymentInfo.cs
- WebChannelFactory.cs
- InvocationExpression.cs
- VectorValueSerializer.cs
- WebConfigurationHostFileChange.cs
- ShaderEffect.cs
- ConnectionStringSettingsCollection.cs
- ProgramNode.cs
- Context.cs
- List.cs
- FormViewInsertedEventArgs.cs
- InputBuffer.cs
- AbstractExpressions.cs
- SqlMetaData.cs
- DataGridColumnHeaderAutomationPeer.cs
- WinEventHandler.cs
- HtmlTableRow.cs
- ManagementObjectSearcher.cs
- CompleteWizardStep.cs
- HtmlCalendarAdapter.cs
- NavigationProperty.cs
- DefaultValueTypeConverter.cs
- EdmFunctionAttribute.cs
- MessageQueuePermissionAttribute.cs
- SQLDateTime.cs
- NumberFormatter.cs
- EntityUtil.cs
- ZipIOLocalFileDataDescriptor.cs
- QilGeneratorEnv.cs
- SamlAuthenticationClaimResource.cs
- MD5.cs
- DataSourceCacheDurationConverter.cs
- LayoutExceptionEventArgs.cs
- StorageInfo.cs
- XmlCharacterData.cs
- DataTableCollection.cs
- TableColumn.cs
- ErrorFormatterPage.cs
- SocketException.cs
- SystemInfo.cs
- KerberosSecurityTokenAuthenticator.cs
- PageCatalogPart.cs
- XmlStringTable.cs
- __Filters.cs
- IPHostEntry.cs
- WindowsTooltip.cs
- PropertyRef.cs
- RolePrincipal.cs
- PeerCollaborationPermission.cs
- hwndwrapper.cs
- TransactionScopeDesigner.cs
- OLEDB_Util.cs
- MergeExecutor.cs
- XmlException.cs
- IdentifierService.cs
- Oci.cs
- XamlInt32CollectionSerializer.cs
- HttpServerUtilityWrapper.cs
- ResourceDisplayNameAttribute.cs
- ObjectPropertyMapping.cs
- UInt16Storage.cs
- xmlglyphRunInfo.cs
- KnownAssemblyEntry.cs