Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / ValueTypeFieldReference.cs / 1305376 / ValueTypeFieldReference.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Expressions { using System.ComponentModel; using System.Reflection; using System.Runtime; using System.Runtime.Serialization; public sealed class ValueTypeFieldReference: CodeActivity > { FieldInfo fieldInfo; public ValueTypeFieldReference() : base() { } [DefaultValue(null)] public string FieldName { get; set; } [DefaultValue(null)] public InOutArgument OperandLocation { get; set; } protected override void CacheMetadata(CodeActivityMetadata metadata) { bool isRequired = false; if (!typeof(TOperand).IsValueType) { metadata.AddValidationError(SR.TypeMustbeValueType(typeof(TOperand).Name)); } if (typeof(TOperand).IsEnum) { metadata.AddValidationError(SR.TargetTypeCannotBeEnum(this.GetType().Name, this.DisplayName)); } if (string.IsNullOrEmpty(this.FieldName)) { metadata.AddValidationError(SR.ActivityPropertyMustBeSet("FieldName", this.DisplayName)); } else { this.fieldInfo = typeof(TOperand).GetField(this.FieldName); isRequired = this.fieldInfo != null && !this.fieldInfo.IsStatic; if (this.fieldInfo == null) { metadata.AddValidationError(SR.MemberNotFound(this.FieldName, typeof(TOperand).Name)); } else if (this.fieldInfo.IsInitOnly) { metadata.AddValidationError(SR.MemberIsReadOnly(this.FieldName, typeof(TOperand).Name)); } } MemberExpressionHelper.AddOperandLocationArgument (metadata, this.OperandLocation, isRequired); } protected override Location Execute(CodeActivityContext context) { Location operandLocationValue = this.OperandLocation.GetLocation(context); Fx.Assert(operandLocationValue != null, "OperandLocation must not be null"); Fx.Assert(this.fieldInfo != null, "fieldInfo must not be null."); return new FieldLocation(this.fieldInfo, operandLocationValue); } [DataContract] class FieldLocation : Location { [DataMember] FieldInfo fieldInfo; [DataMember(EmitDefaultValue = false)] Location ownerLocation; public FieldLocation(FieldInfo fieldInfo, Location ownerLocation) : base() { this.fieldInfo = fieldInfo; this.ownerLocation = ownerLocation; } public override TResult Value { get { return (TResult)this.fieldInfo.GetValue(this.ownerLocation.Value); } set { object copy = this.ownerLocation.Value; this.fieldInfo.SetValue(copy, value); this.ownerLocation.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
- DuplexSecurityProtocolFactory.cs
- ListenerChannelContext.cs
- ChameleonKey.cs
- JsonGlobals.cs
- LogEntry.cs
- UrlPath.cs
- RIPEMD160.cs
- PLINQETWProvider.cs
- DeferrableContentConverter.cs
- TextBox.cs
- StateMachineDesignerPaint.cs
- TraceUtility.cs
- ResourceAssociationSetEnd.cs
- ActivityExecutionContext.cs
- ZoneIdentityPermission.cs
- RegexGroupCollection.cs
- Row.cs
- ConnectionStringsSection.cs
- ElementHostPropertyMap.cs
- OutputCacheProviderCollection.cs
- DataBinding.cs
- ToolboxItemLoader.cs
- Vector.cs
- Vars.cs
- DBDataPermissionAttribute.cs
- SuppressMessageAttribute.cs
- controlskin.cs
- TypeRefElement.cs
- ModuleConfigurationInfo.cs
- PropertyEntry.cs
- RNGCryptoServiceProvider.cs
- ReliableOutputConnection.cs
- WebEventTraceProvider.cs
- DataBindingExpressionBuilder.cs
- XmlSchemaException.cs
- UrlPath.cs
- ButtonRenderer.cs
- PaperSize.cs
- RelationshipConverter.cs
- RectIndependentAnimationStorage.cs
- ComplexObject.cs
- PrintDialog.cs
- EntityDataSourceChangedEventArgs.cs
- StrongName.cs
- TreeViewAutomationPeer.cs
- ShaderEffect.cs
- odbcmetadatacolumnnames.cs
- ContourSegment.cs
- TransportSecurityBindingElement.cs
- CorrelationQueryBehavior.cs
- VariantWrapper.cs
- DataGridViewCheckBoxColumn.cs
- SerialPort.cs
- SafeHandles.cs
- InputDevice.cs
- _Events.cs
- SpecialNameAttribute.cs
- AutoFocusStyle.xaml.cs
- TemplateControl.cs
- TimeIntervalCollection.cs
- ActivityStateQuery.cs
- ResXFileRef.cs
- CurrentChangingEventManager.cs
- TransformGroup.cs
- AudioFileOut.cs
- EndpointDiscoveryMetadata.cs
- SizeChangedInfo.cs
- XhtmlTextWriter.cs
- QilTargetType.cs
- DrawListViewItemEventArgs.cs
- DbProviderManifest.cs
- AQNBuilder.cs
- PersistChildrenAttribute.cs
- SupportingTokenProviderSpecification.cs
- Statements.cs
- Decoder.cs
- VirtualPathData.cs
- CommandManager.cs
- _SpnDictionary.cs
- BehaviorService.cs
- ParameterEditorUserControl.cs
- EventLogPermissionAttribute.cs
- Debug.cs
- DecimalAnimationBase.cs
- SQLGuidStorage.cs
- RecordConverter.cs
- DeclarativeExpressionConditionDeclaration.cs
- ImageKeyConverter.cs
- BasicViewGenerator.cs
- Function.cs
- BuildManager.cs
- Configuration.cs
- EncryptedReference.cs
- XhtmlConformanceSection.cs
- PassportIdentity.cs
- _Connection.cs
- Rfc2898DeriveBytes.cs
- RawAppCommandInputReport.cs
- RegistryPermission.cs
- Debug.cs