Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / ValueTypePropertyReference.cs / 1305376 / ValueTypePropertyReference.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.Expressions
{
using System;
using System.ComponentModel;
using System.Reflection;
using System.Runtime;
using System.Runtime.Serialization;
public sealed class ValueTypePropertyReference : CodeActivity>
{
PropertyInfo propertyInfo;
[DefaultValue(null)]
public string PropertyName
{
get;
set;
}
[DefaultValue(null)]
public InOutArgument OperandLocation
{
get;
set;
}
protected override void CacheMetadata(CodeActivityMetadata metadata)
{
if (!typeof(TOperand).IsValueType)
{
metadata.AddValidationError(SR.TypeMustbeValueType(typeof(TOperand).Name));
}
if (typeof(TOperand).IsEnum)
{
metadata.AddValidationError(SR.TargetTypeCannotBeEnum(this.GetType().Name, this.DisplayName));
}
else if (String.IsNullOrEmpty(this.PropertyName))
{
metadata.AddValidationError(SR.ActivityPropertyMustBeSet("PropertyName", this.DisplayName));
}
else
{
this.propertyInfo = typeof(TOperand).GetProperty(this.PropertyName);
if (this.propertyInfo == null)
{
metadata.AddValidationError(SR.MemberNotFound(PropertyName, typeof(TOperand).Name));
}
}
bool isRequired = false;
if (this.propertyInfo != null)
{
MethodInfo setMethod = this.propertyInfo.GetSetMethod();
if (setMethod == null)
{
metadata.AddValidationError(SR.MemberIsReadOnly(propertyInfo.Name, typeof(TOperand)));
}
if (setMethod != null && !setMethod.IsStatic)
{
isRequired = true;
}
}
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.propertyInfo != null, "propertyInfo must not be null");
return new PropertyLocation(this.propertyInfo, operandLocationValue);
}
[DataContract]
class PropertyLocation : Location
{
[DataMember(EmitDefaultValue = false)]
Location ownerLocation;
[DataMember]
PropertyInfo propertyInfo;
public PropertyLocation(PropertyInfo propertyInfo, Location ownerLocation)
: base()
{
this.propertyInfo = propertyInfo;
this.ownerLocation = ownerLocation;
}
public override TResult Value
{
get
{
// Only allow access to public properties, EXCEPT that Locations are top-level variables
// from the other's perspective, not internal properties, so they're okay as a special case.
// E.g. "[N]" from the user's perspective is not accessing a nonpublic property, even though
// at an implementation level it is.
if (this.propertyInfo.GetGetMethod() == null && TypeHelper.AreTypesCompatible(this.propertyInfo.DeclaringType, typeof(Location)) == false)
{
throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WriteonlyPropertyCannotBeRead(this.propertyInfo.DeclaringType, this.propertyInfo.Name)));
}
return (TResult)this.propertyInfo.GetValue(this.ownerLocation.Value, null);
}
set
{
object copy = this.ownerLocation.Value;
this.propertyInfo.SetValue(copy, value, null);
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
- RoutedCommand.cs
- DataGridViewToolTip.cs
- SectionXmlInfo.cs
- HtmlTableCell.cs
- RecordsAffectedEventArgs.cs
- SiteIdentityPermission.cs
- DesignerSerializerAttribute.cs
- GeneralTransform3D.cs
- HitTestResult.cs
- LineServicesCallbacks.cs
- NameService.cs
- PageContent.cs
- BinaryReader.cs
- WindowsClaimSet.cs
- SoapTransportImporter.cs
- Debugger.cs
- UInt32Storage.cs
- AppDomainProtocolHandler.cs
- Crc32.cs
- DataListCommandEventArgs.cs
- IPEndPoint.cs
- CommonDialog.cs
- TextSelection.cs
- RSAOAEPKeyExchangeDeformatter.cs
- ColumnResizeAdorner.cs
- X509AsymmetricSecurityKey.cs
- DataGridViewColumnCollection.cs
- SQLInt32Storage.cs
- SetterBaseCollection.cs
- FilterQuery.cs
- PrivateFontCollection.cs
- TypeExtensionSerializer.cs
- StoragePropertyMapping.cs
- wmiprovider.cs
- CurrentChangingEventManager.cs
- ExpressionReplacer.cs
- LabelEditEvent.cs
- CodeAttributeDeclarationCollection.cs
- ArrayList.cs
- TextPatternIdentifiers.cs
- EntityConnectionStringBuilder.cs
- ArrayMergeHelper.cs
- GenericWebPart.cs
- XmlDataSourceNodeDescriptor.cs
- SelectingProviderEventArgs.cs
- DataBindingExpressionBuilder.cs
- StandardToolWindows.cs
- TcpAppDomainProtocolHandler.cs
- UnsafeNativeMethodsMilCoreApi.cs
- ReaderContextStackData.cs
- CatalogPartCollection.cs
- DataControlCommands.cs
- Help.cs
- SslSecurityTokenParameters.cs
- DataTrigger.cs
- MenuItemStyle.cs
- ExpressionCopier.cs
- ClientScriptManagerWrapper.cs
- IntSecurity.cs
- DesignerProperties.cs
- TransformationRules.cs
- XmlQueryCardinality.cs
- CompiledQuery.cs
- ControlBuilder.cs
- TypographyProperties.cs
- Transform3DGroup.cs
- UniqueIdentifierService.cs
- SQLDateTime.cs
- PrinterSettings.cs
- NetworkInterface.cs
- KernelTypeValidation.cs
- TypeSystem.cs
- WS2007FederationHttpBindingElement.cs
- MenuItemStyleCollectionEditor.cs
- ToolBarPanel.cs
- Helper.cs
- AssemblyName.cs
- XmlEncodedRawTextWriter.cs
- BamlLocalizer.cs
- RuntimeHelpers.cs
- InputBinder.cs
- BorderGapMaskConverter.cs
- BitmapEffectInputConnector.cs
- ComplexTypeEmitter.cs
- TextControl.cs
- ExpressionEditorSheet.cs
- XamlInt32CollectionSerializer.cs
- ThreadStaticAttribute.cs
- OleDbRowUpdatedEvent.cs
- BooleanStorage.cs
- ManualResetEvent.cs
- ScrollableControlDesigner.cs
- WebHttpDispatchOperationSelector.cs
- BamlLocalizableResourceKey.cs
- WindowsListViewScroll.cs
- BinHexEncoder.cs
- CounterNameConverter.cs
- AutoSizeComboBox.cs
- ArcSegment.cs
- ServiceReflector.cs