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
- WindowAutomationPeer.cs
- GetCryptoTransformRequest.cs
- AssociationSetMetadata.cs
- TextDecoration.cs
- FormattedTextSymbols.cs
- ReliableSessionBindingElement.cs
- QuaternionAnimationUsingKeyFrames.cs
- MeasureItemEvent.cs
- HtmlInputFile.cs
- StorageRoot.cs
- HttpProfileBase.cs
- CompilationLock.cs
- Stream.cs
- ChannelServices.cs
- IsolatedStorageException.cs
- ManagementObject.cs
- FunctionParameter.cs
- ComPlusContractBehavior.cs
- AssemblyNameUtility.cs
- CodeAttributeDeclaration.cs
- PlanCompilerUtil.cs
- FontNamesConverter.cs
- ClientTarget.cs
- DataServiceBehavior.cs
- ValidatorCollection.cs
- IteratorFilter.cs
- Collection.cs
- NativeMethodsCLR.cs
- ElapsedEventArgs.cs
- BindingExpression.cs
- SubpageParaClient.cs
- StringValidatorAttribute.cs
- BamlResourceContent.cs
- Match.cs
- RenamedEventArgs.cs
- XsltSettings.cs
- bindurihelper.cs
- CoTaskMemHandle.cs
- HttpListener.cs
- SQLBoolean.cs
- ExpressionCopier.cs
- SelectingProviderEventArgs.cs
- BroadcastEventHelper.cs
- DiscoveryExceptionDictionary.cs
- _Rfc2616CacheValidators.cs
- XmlSubtreeReader.cs
- AddIn.cs
- ListBoxChrome.cs
- XsltLoader.cs
- SiteMapNodeItem.cs
- DbProviderFactoriesConfigurationHandler.cs
- ValidationEventArgs.cs
- CodeGenerator.cs
- ChangePasswordAutoFormat.cs
- GridPattern.cs
- SqlCacheDependencyDatabaseCollection.cs
- NumberFormatInfo.cs
- ThrowOnMultipleAssignment.cs
- HtmlTextArea.cs
- Transform.cs
- RemoteWebConfigurationHost.cs
- CreateUserWizard.cs
- DataView.cs
- WaitHandle.cs
- RelationshipFixer.cs
- LassoHelper.cs
- NamedObject.cs
- TypeBuilderInstantiation.cs
- ProviderIncompatibleException.cs
- InvalidTimeZoneException.cs
- DelayedRegex.cs
- WebSysDefaultValueAttribute.cs
- ConsoleCancelEventArgs.cs
- CursorInteropHelper.cs
- WinCategoryAttribute.cs
- HashAlgorithm.cs
- NavigationProgressEventArgs.cs
- PreservationFileWriter.cs
- AsmxEndpointPickerExtension.cs
- BitmapVisualManager.cs
- FormsAuthentication.cs
- DataGridViewRowErrorTextNeededEventArgs.cs
- EnumValidator.cs
- DateBoldEvent.cs
- ProcessThreadCollection.cs
- UpdateException.cs
- SelectorAutomationPeer.cs
- ByteStorage.cs
- ObjectPersistData.cs
- HostedAspNetEnvironment.cs
- QfeChecker.cs
- MetadataPropertyvalue.cs
- ImplicitInputBrush.cs
- Compiler.cs
- RelationshipEnd.cs
- ProcessThreadCollection.cs
- RequestCacheEntry.cs
- GridViewHeaderRowPresenter.cs
- FormatSelectingMessageInspector.cs
- SkewTransform.cs