Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / PropertyReference.cs / 1305376 / PropertyReference.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 PropertyReference: CodeActivity > { PropertyInfo propertyInfo; [DefaultValue(null)] public string PropertyName { get; set; } 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.PropertyName)) { metadata.AddValidationError(SR.ActivityPropertyMustBeSet("PropertyName", this.DisplayName)); } else { Type operandType = typeof(TOperand); this.propertyInfo = operandType.GetProperty(this.PropertyName); if (this.propertyInfo == null) { metadata.AddValidationError(SR.MemberNotFound(PropertyName, typeof(TOperand).Name)); } else { MethodInfo getMethod = this.propertyInfo.GetGetMethod(); MethodInfo setMethod = this.propertyInfo.GetSetMethod(); // 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 (setMethod == null && TypeHelper.AreTypesCompatible(this.propertyInfo.DeclaringType, typeof(Location)) == false) { metadata.AddValidationError(SR.ReadonlyPropertyCannotBeSet(this.propertyInfo.DeclaringType, this.propertyInfo.Name)); } if ((getMethod != null && !getMethod.IsStatic) || (setMethod != null && !setMethod.IsStatic)) { isRequired = true; } } } MemberExpressionHelper.AddOperandArgument(metadata, this.Operand, isRequired); } protected override Location Execute(CodeActivityContext context) { Fx.Assert(this.propertyInfo != null, "propertyInfo must not be null"); return new PropertyLocation (this.propertyInfo, this.Operand.Get(context)); } [DataContract] class PropertyLocation : Location { [DataMember(EmitDefaultValue = false)] object owner; [DataMember] PropertyInfo propertyInfo; public PropertyLocation(PropertyInfo propertyInfo, object owner) : base() { this.propertyInfo = propertyInfo; this.owner = owner; } public override T 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 (T)this.propertyInfo.GetValue(this.owner, null); } set { this.propertyInfo.SetValue(this.owner, value, null); } } } } } // 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
- QuotedStringWriteStateInfo.cs
- Message.cs
- MarkupWriter.cs
- DataGridTextBox.cs
- SchemaMapping.cs
- AttributeCollection.cs
- ListViewInsertEventArgs.cs
- Animatable.cs
- ClickablePoint.cs
- CategoryGridEntry.cs
- MemoryStream.cs
- SplineKeyFrames.cs
- lengthconverter.cs
- AsymmetricSignatureDeformatter.cs
- IPPacketInformation.cs
- DefaultBindingPropertyAttribute.cs
- ThousandthOfEmRealPoints.cs
- AnnotationComponentManager.cs
- BulletedListEventArgs.cs
- LogicalMethodInfo.cs
- SByte.cs
- Int32RectValueSerializer.cs
- NavigateEvent.cs
- AdPostCacheSubstitution.cs
- WebServiceClientProxyGenerator.cs
- CompilerGeneratedAttribute.cs
- DataSysAttribute.cs
- FastEncoderWindow.cs
- HostedAspNetEnvironment.cs
- SafeViewOfFileHandle.cs
- BindingNavigator.cs
- AmbientProperties.cs
- Pkcs9Attribute.cs
- ServicePoint.cs
- CurrencyWrapper.cs
- RangeExpression.cs
- VariableQuery.cs
- DocumentPageViewAutomationPeer.cs
- StrokeCollectionDefaultValueFactory.cs
- BinaryCommonClasses.cs
- DatatypeImplementation.cs
- GroupBoxRenderer.cs
- ImageButton.cs
- DataAccessor.cs
- OdbcFactory.cs
- SizeConverter.cs
- DataServiceRequestOfT.cs
- XmlSignificantWhitespace.cs
- MenuAutomationPeer.cs
- NameValuePair.cs
- BamlTreeMap.cs
- regiisutil.cs
- XmlAutoDetectWriter.cs
- codemethodreferenceexpression.cs
- SelectedGridItemChangedEvent.cs
- ActiveDocumentEvent.cs
- PrePostDescendentsWalker.cs
- WpfKnownTypeInvoker.cs
- InvokeMemberBinder.cs
- X509Utils.cs
- OdbcRowUpdatingEvent.cs
- DataGridViewTopRowAccessibleObject.cs
- ContextMenuAutomationPeer.cs
- SqlRemoveConstantOrderBy.cs
- DataSource.cs
- WebConfigurationManager.cs
- XsltQilFactory.cs
- StylusDevice.cs
- BamlResourceContent.cs
- PassportAuthenticationEventArgs.cs
- Visual3DCollection.cs
- BindingObserver.cs
- EditorZone.cs
- TypeConverter.cs
- WMIGenerator.cs
- StackSpiller.Generated.cs
- TextSpanModifier.cs
- DateTimeConverter2.cs
- XmlObjectSerializerReadContextComplexJson.cs
- LayoutTable.cs
- PingReply.cs
- OleDbDataAdapter.cs
- ToolStripSettings.cs
- EdmToObjectNamespaceMap.cs
- LinqDataSourceStatusEventArgs.cs
- QilIterator.cs
- Axis.cs
- TripleDESCryptoServiceProvider.cs
- IntPtr.cs
- MgmtConfigurationRecord.cs
- BitmapEffectDrawingContextWalker.cs
- RootBrowserWindow.cs
- TemporaryBitmapFile.cs
- EventHandlerList.cs
- OutputCacheSettings.cs
- dbenumerator.cs
- FontNamesConverter.cs
- TokenBasedSetEnumerator.cs
- Operators.cs
- DnsPermission.cs