Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / ValueTypeIndexerReference.cs / 1305376 / ValueTypeIndexerReference.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Expressions { using System.Collections.ObjectModel; using System.ComponentModel; using System.Reflection; using System.Runtime; using System.Runtime.Collections; using System.Runtime.Serialization; using System.Windows.Markup; [ContentProperty("Indices")] public sealed class ValueTypeIndexerReference: CodeActivity > { Collection indices; MethodInfo getMethod; MethodInfo setMethod; [RequiredArgument] [DefaultValue(null)] public InOutArgument OperandLocation { get; set; } [RequiredArgument] [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 (!typeof(TOperand).IsValueType) { metadata.AddValidationError(SR.TypeMustbeValueType(typeof(TOperand).Name)); } if (this.Indices.Count == 0) { metadata.AddValidationError(SR.IndicesAreNeeded(this.GetType().Name, this.DisplayName)); } else { IndexerHelper.CacheMethod (this.Indices, ref this.getMethod, ref this.setMethod); if (this.setMethod == null) { metadata.AddValidationError(SR.SpecialMethodNotFound("set_Item", typeof(TOperand).Name)); } } RuntimeArgument operandArgument = new RuntimeArgument("OperandLocation", typeof(TOperand), ArgumentDirection.InOut, true); metadata.Bind(this.OperandLocation, operandArgument); metadata.AddArgument(operandArgument); IndexerHelper.OnGetArguments (this.Indices, this.Result, metadata); } protected override Location Execute(CodeActivityContext context) { object[] indicesValue = new object[this.Indices.Count]; for (int i = 0; i < this.Indices.Count; i++) { indicesValue[i] = this.Indices[i].Get(context); } Location operandLocationValue = this.OperandLocation.GetLocation(context); Fx.Assert(operandLocationValue != null, "OperandLocation must not be null"); return new IndexerLocation(operandLocationValue, indicesValue, getMethod, setMethod); } [DataContract] class IndexerLocation : Location { [DataMember(EmitDefaultValue = false)] Location operandLocation; [DataMember(EmitDefaultValue = false)] object[] indices; [DataMember(EmitDefaultValue = false)] object[] parameters; [DataMember(EmitDefaultValue = false)] MethodInfo getMethod; [DataMember(EmitDefaultValue = false)] MethodInfo setMethod; public IndexerLocation(Location operandLocation, object[] indices, MethodInfo getMethod, MethodInfo setMethod) : base() { this.operandLocation = operandLocation; this.indices = indices; this.getMethod = getMethod; this.setMethod = setMethod; } public override TItem Value { get { Fx.Assert(this.operandLocation != null, "operandLocation must not be null"); Fx.Assert(this.indices != null, "indices must not be null"); if (this.getMethod == null) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.SpecialMethodNotFound("get_Item", typeof(TOperand).Name))); } return (TItem)this.getMethod.Invoke(this.operandLocation.Value, indices); } set { Fx.Assert(this.setMethod != null, "setMethod must not be null"); Fx.Assert(this.operandLocation != null, "operandLocation must not be null"); Fx.Assert(this.indices != null, "indices must not be null"); if (this.parameters == null) { this.parameters = new object[this.indices.Length + 1]; for (int i = 0; i < this.indices.Length; i++) { parameters[i] = this.indices[i]; } parameters[parameters.Length - 1] = value; } object copy = this.operandLocation.Value; this.setMethod.Invoke(copy, parameters); this.operandLocation.Value = (TOperand) copy; } } } } } // 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
- VisualTreeUtils.cs
- BehaviorEditorPart.cs
- WebScriptMetadataFormatter.cs
- ParallelRangeManager.cs
- AvtEvent.cs
- ApplicationContext.cs
- PageContentAsyncResult.cs
- DateTime.cs
- linebase.cs
- DataListItemCollection.cs
- CodeDelegateInvokeExpression.cs
- WorkingDirectoryEditor.cs
- EncoderNLS.cs
- Label.cs
- Decoder.cs
- ConnectorSelectionGlyph.cs
- PassportAuthenticationEventArgs.cs
- IisTraceListener.cs
- Run.cs
- ConnectionStringsSection.cs
- CuspData.cs
- InkCollectionBehavior.cs
- SafeHandles.cs
- PenLineJoinValidation.cs
- XmlCustomFormatter.cs
- TemplateControl.cs
- EditingMode.cs
- SamlSecurityTokenAuthenticator.cs
- MsmqChannelFactory.cs
- EntityDescriptor.cs
- ISAPIRuntime.cs
- Composition.cs
- CapabilitiesAssignment.cs
- WebDisplayNameAttribute.cs
- EventHandlerList.cs
- AttachedAnnotationChangedEventArgs.cs
- SizeChangedInfo.cs
- AlphabeticalEnumConverter.cs
- SQLBoolean.cs
- EntityDataSource.cs
- PropertyMetadata.cs
- _NativeSSPI.cs
- QilStrConcat.cs
- RawStylusActions.cs
- StrokeNodeEnumerator.cs
- PointCollection.cs
- Visual3D.cs
- FrameworkElementFactory.cs
- DataServiceHostFactory.cs
- VariantWrapper.cs
- ItemContainerProviderWrapper.cs
- EdmValidator.cs
- ImageSource.cs
- ResourceAttributes.cs
- CompilerGeneratedAttribute.cs
- XmlSortKeyAccumulator.cs
- RecipientInfo.cs
- ListControl.cs
- EntityDataSourceWrapperCollection.cs
- DataTableTypeConverter.cs
- DbModificationClause.cs
- Selector.cs
- InProcStateClientManager.cs
- ContractMapping.cs
- WebServicesDescriptionAttribute.cs
- BigInt.cs
- PositiveTimeSpanValidator.cs
- XmlDocumentFragment.cs
- sqlmetadatafactory.cs
- ExeConfigurationFileMap.cs
- UserPersonalizationStateInfo.cs
- SapiRecoInterop.cs
- TextRunCacheImp.cs
- GenericIdentity.cs
- CounterCreationData.cs
- RepeaterItem.cs
- TaiwanCalendar.cs
- SecurityVerifiedMessage.cs
- XmlElementList.cs
- Rectangle.cs
- ErrorFormatter.cs
- JsonEnumDataContract.cs
- InputBuffer.cs
- SiteMapProvider.cs
- SrgsRulesCollection.cs
- RawUIStateInputReport.cs
- PerspectiveCamera.cs
- NodeFunctions.cs
- GenerateTemporaryTargetAssembly.cs
- SerialPinChanges.cs
- GridEntryCollection.cs
- MasterPageCodeDomTreeGenerator.cs
- TreeNodeConverter.cs
- SchemaManager.cs
- BinaryMessageEncodingBindingElement.cs
- XmlWrappingWriter.cs
- ToolStripHighContrastRenderer.cs
- DataMemberAttribute.cs
- ChannelManager.cs
- List.cs