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
- FtpWebResponse.cs
- GridViewPageEventArgs.cs
- WinInetCache.cs
- RequestCache.cs
- documentation.cs
- PocoEntityKeyStrategy.cs
- Converter.cs
- SettingsProperty.cs
- SecurityVerifiedMessage.cs
- DispatcherProcessingDisabled.cs
- EntityDataSourceDataSelectionPanel.designer.cs
- XmlSchemaComplexContentRestriction.cs
- WindowsAuthenticationModule.cs
- ICspAsymmetricAlgorithm.cs
- ConfigurationPropertyAttribute.cs
- Simplifier.cs
- MemoryFailPoint.cs
- LayoutManager.cs
- Point3DCollection.cs
- DoubleAnimationBase.cs
- HierarchicalDataSourceIDConverter.cs
- NetStream.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- ImageListImage.cs
- HostingEnvironmentException.cs
- VirtualDirectoryMapping.cs
- EdmSchemaError.cs
- CngKey.cs
- InkCanvas.cs
- CodeTypeOfExpression.cs
- TextBounds.cs
- ObjRef.cs
- Cursor.cs
- XPathSelectionIterator.cs
- RadioButton.cs
- Sentence.cs
- SQLInt32Storage.cs
- Or.cs
- PenContext.cs
- CaseInsensitiveOrdinalStringComparer.cs
- TypeDescriptor.cs
- List.cs
- RadioButtonAutomationPeer.cs
- UDPClient.cs
- GridView.cs
- XamlHostingSectionGroup.cs
- ActivityCodeDomReferenceService.cs
- ImageConverter.cs
- SchemaExporter.cs
- IdentifierCollection.cs
- HeaderCollection.cs
- LoggedException.cs
- WSSecureConversation.cs
- CounterCreationDataCollection.cs
- UserNamePasswordServiceCredential.cs
- WebPartVerbsEventArgs.cs
- ConstraintCollection.cs
- NamespaceMapping.cs
- ContentElementAutomationPeer.cs
- XhtmlBasicCommandAdapter.cs
- SyndicationFeedFormatter.cs
- TargetParameterCountException.cs
- PKCS1MaskGenerationMethod.cs
- TimeSpanSecondsConverter.cs
- UriScheme.cs
- Selection.cs
- Operand.cs
- LinkClickEvent.cs
- DetailsViewModeEventArgs.cs
- HttpResponseInternalWrapper.cs
- InputScopeConverter.cs
- DiscreteKeyFrames.cs
- LocatorBase.cs
- Drawing.cs
- WebPartConnectionsDisconnectVerb.cs
- Size.cs
- ResourceReferenceKeyNotFoundException.cs
- PersonalizationEntry.cs
- DataGridItem.cs
- RichTextBoxConstants.cs
- AssemblyHash.cs
- WaitHandle.cs
- CacheChildrenQuery.cs
- XmlIlGenerator.cs
- SchemaInfo.cs
- SQLSingle.cs
- AccessorTable.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- CallbackValidator.cs
- ComplexTypeEmitter.cs
- LogLogRecordHeader.cs
- DataException.cs
- MDIControlStrip.cs
- CommandHelpers.cs
- ScriptControl.cs
- HideDisabledControlAdapter.cs
- HwndStylusInputProvider.cs
- DataSourceXmlElementAttribute.cs
- WebPartConnectionsCancelEventArgs.cs
- ProfileModule.cs