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
- ProviderConnectionPointCollection.cs
- RegexParser.cs
- CodeIdentifiers.cs
- AjaxFrameworkAssemblyAttribute.cs
- CodeMemberEvent.cs
- BooleanKeyFrameCollection.cs
- HebrewCalendar.cs
- NumberFormatter.cs
- HtmlContainerControl.cs
- ThrowHelper.cs
- DropShadowEffect.cs
- JsonUriDataContract.cs
- GifBitmapEncoder.cs
- SiteMapNodeItem.cs
- ApplicationGesture.cs
- SqlDataSourceEnumerator.cs
- KeyGesture.cs
- SyndicationSerializer.cs
- FixedSOMContainer.cs
- FixedTextContainer.cs
- CommandDevice.cs
- CellIdBoolean.cs
- DataGridViewComboBoxEditingControl.cs
- XmlSchemaGroup.cs
- BoundField.cs
- FilteredDataSetHelper.cs
- MarshalDirectiveException.cs
- PageParser.cs
- WorkflowRuntimeBehavior.cs
- WeakReferenceList.cs
- CodeDomConfigurationHandler.cs
- DBSqlParserColumnCollection.cs
- XmlDictionaryWriter.cs
- TextComposition.cs
- NativeActivityTransactionContext.cs
- DataGrid.cs
- DataGridViewRow.cs
- Boolean.cs
- CallbackValidator.cs
- GeneralTransform3DGroup.cs
- WsatAdminException.cs
- BitmapFrame.cs
- SqlEnums.cs
- NativeObjectSecurity.cs
- CodeTypeDelegate.cs
- SqlGenericUtil.cs
- FlowDocumentFormatter.cs
- CleanUpVirtualizedItemEventArgs.cs
- ValidateNames.cs
- TypeUsage.cs
- InkCanvasInnerCanvas.cs
- CompilerParameters.cs
- GridViewHeaderRowPresenter.cs
- UnaryExpression.cs
- TabRenderer.cs
- DtrList.cs
- TTSVoice.cs
- ImageList.cs
- TableHeaderCell.cs
- SizeFConverter.cs
- EntityCommandCompilationException.cs
- GridView.cs
- SQLChars.cs
- TextClipboardData.cs
- UIElementIsland.cs
- Rectangle.cs
- ZoneLinkButton.cs
- InfoCardClaim.cs
- Parameter.cs
- XmlNodeList.cs
- WebPartConnectionCollection.cs
- DebugHandleTracker.cs
- InternalConfigRoot.cs
- WindowsFormsHostPropertyMap.cs
- CollectionBuilder.cs
- LocalTransaction.cs
- Separator.cs
- DictionarySurrogate.cs
- ArcSegment.cs
- localization.cs
- ExplicitDiscriminatorMap.cs
- LabelExpression.cs
- NetDataContractSerializer.cs
- SimpleParser.cs
- SafeUserTokenHandle.cs
- WebSysDescriptionAttribute.cs
- TableAdapterManagerGenerator.cs
- RemoteWebConfigurationHostServer.cs
- Accessible.cs
- WorkerRequest.cs
- ClientSettingsStore.cs
- ToolBarTray.cs
- OperationCanceledException.cs
- SecurityPolicySection.cs
- TdsValueSetter.cs
- BitmapFrameEncode.cs
- GPPOINT.cs
- SQLStringStorage.cs
- EndpointNotFoundException.cs
- GiveFeedbackEvent.cs