Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / FieldReference.cs / 1305376 / FieldReference.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 FieldReference: CodeActivity > { FieldInfo fieldInfo; public FieldReference() : base() { } [DefaultValue(null)] public string FieldName { get; set; } [DefaultValue(null)] public InArgument Operand { get; set; } protected override void CacheMetadata(CodeActivityMetadata metadata) { bool isRequired = false; if (typeof(TOperand).IsEnum) { metadata.AddValidationError(SR.TargetTypeCannotBeEnum(this.GetType().Name, this.DisplayName)); } else if (typeof(TOperand).IsValueType) { metadata.AddValidationError(SR.TargetTypeIsValueType(this.GetType().Name, this.DisplayName)); } if (string.IsNullOrEmpty(this.FieldName)) { metadata.AddValidationError(SR.ActivityPropertyMustBeSet("FieldName", this.DisplayName)); } else { Type operandType = typeof(TOperand); this.fieldInfo = operandType.GetField(this.FieldName); if (this.fieldInfo == null) { metadata.AddValidationError(SR.MemberNotFound(this.FieldName, typeof(TOperand).Name)); } else { if (fieldInfo.IsInitOnly) { metadata.AddValidationError(SR.MemberIsReadOnly(this.FieldName, typeof(TOperand).Name)); } isRequired = !this.fieldInfo.IsStatic; } } MemberExpressionHelper.AddOperandArgument(metadata, this.Operand, isRequired); } protected override Location Execute(CodeActivityContext context) { Fx.Assert(this.fieldInfo != null, "fieldInfo must not be null."); return new FieldLocation(this.fieldInfo, this.Operand.Get(context)); } [DataContract] class FieldLocation : Location { [DataMember] FieldInfo fieldInfo; [DataMember(EmitDefaultValue = false)] object owner; public FieldLocation(FieldInfo fieldInfo, object owner) : base() { this.fieldInfo = fieldInfo; this.owner = owner; } public override TResult Value { get { //if (!this.fieldInfo.IsStatic && this.owner == null) //{ // // The field is non-static, and obj is a null reference // if (this.fieldInfo.DeclaringType != null) // { // throw FxTrace.Exception.AsError(new ValidationException(SR.NullReferencedMemberAccess(this.fieldInfo.DeclaringType.Name, this.fieldInfo.Name))); // } // else // { // throw FxTrace.Exception.AsError(new ValidationException(SR.NullReferencedMemberAccess(typeof(FieldInfo), "DeclaringType"))); // } //} return (TResult)this.fieldInfo.GetValue(this.owner); } set { //if (!this.fieldInfo.IsStatic && this.owner == null) //{ // if (this.fieldInfo.DeclaringType != null) // { // // The field is non-static, and obj is a null reference // throw FxTrace.Exception.AsError(new ValidationException(SR.NullReferencedMemberAccess(this.fieldInfo.DeclaringType.Name, this.fieldInfo.Name))); // } // else // { // throw FxTrace.Exception.AsError(new ValidationException(SR.NullReferencedMemberAccess(typeof(FieldInfo), "DeclaringType"))); // } //} this.fieldInfo.SetValue(this.owner, value); } } } } } // 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
- TreeWalkHelper.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- ChannelRequirements.cs
- FieldMetadata.cs
- DropTarget.cs
- Simplifier.cs
- DelayedRegex.cs
- TextMarkerSource.cs
- FlowDocumentView.cs
- DataControlFieldTypeEditor.cs
- StreamProxy.cs
- DateTimeConverter.cs
- LicenseProviderAttribute.cs
- MouseActionConverter.cs
- RelativeSource.cs
- DesignerDataColumn.cs
- NumericUpDownAccelerationCollection.cs
- NotificationContext.cs
- ServiceObjectContainer.cs
- CompilationUnit.cs
- FormViewInsertEventArgs.cs
- Menu.cs
- DesignerHierarchicalDataSourceView.cs
- ReadWriteObjectLock.cs
- CommonRemoteMemoryBlock.cs
- EpmTargetPathSegment.cs
- StructuredCompositeActivityDesigner.cs
- SystemIPGlobalStatistics.cs
- ArcSegment.cs
- ToolStripControlHost.cs
- GridViewSelectEventArgs.cs
- Variant.cs
- SqlTrackingService.cs
- ContainerAction.cs
- MasterPageCodeDomTreeGenerator.cs
- SqlDataSourceTableQuery.cs
- SHA1CryptoServiceProvider.cs
- CuspData.cs
- ConfigurationStrings.cs
- ItemChangedEventArgs.cs
- IDQuery.cs
- PathSegment.cs
- MetadataUtilsSmi.cs
- KeyEventArgs.cs
- InternalBufferOverflowException.cs
- _ListenerAsyncResult.cs
- AudienceUriMode.cs
- KeyedCollection.cs
- ReachFixedPageSerializer.cs
- ToolStripRendererSwitcher.cs
- MetadataSet.cs
- DataGridCaption.cs
- ImmutableAssemblyCacheEntry.cs
- InternalBase.cs
- Win32.cs
- AppLevelCompilationSectionCache.cs
- MouseOverProperty.cs
- DateTimeAutomationPeer.cs
- IntegerFacetDescriptionElement.cs
- HttpClientCertificate.cs
- CustomErrorCollection.cs
- TextDecorationCollectionConverter.cs
- Literal.cs
- ContractsBCL.cs
- BindingSource.cs
- XmlTextEncoder.cs
- Size.cs
- LinqToSqlWrapper.cs
- AttributeCollection.cs
- OracleSqlParser.cs
- DelegateSerializationHolder.cs
- GlyphTypeface.cs
- SmtpReplyReader.cs
- CodeTypeConstructor.cs
- PasswordBox.cs
- PartitionedStream.cs
- ToolstripProfessionalRenderer.cs
- BaseComponentEditor.cs
- Point.cs
- NullableBoolConverter.cs
- RSAPKCS1SignatureDeformatter.cs
- WebResponse.cs
- CachedCompositeFamily.cs
- DesignerAttributeInfo.cs
- CompareValidator.cs
- FilterInvalidBodyAccessException.cs
- FormatStringEditor.cs
- connectionpool.cs
- ResourceDisplayNameAttribute.cs
- ILGenerator.cs
- HeaderCollection.cs
- AffineTransform3D.cs
- Calendar.cs
- DbProviderFactories.cs
- AxisAngleRotation3D.cs
- ElementMarkupObject.cs
- contentDescriptor.cs
- IndicShape.cs
- CultureTableRecord.cs
- HyperLinkColumn.cs