Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / MemberExpressionHelper.cs / 1305376 / MemberExpressionHelper.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Expressions { using System.Activities.Statements; using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; using System.Runtime; using System.Collections.ObjectModel; using System.Activities.Validation; static class MemberExpressionHelper { public static void AddOperandArgument(CodeActivityMetadata metadata, InArgument operand, bool isRequired) { RuntimeArgument operandArgument = new RuntimeArgument("Operand", typeof(TOperand), ArgumentDirection.In, isRequired); metadata.Bind(operand, operandArgument); metadata.AddArgument(operandArgument); } public static void AddOperandLocationArgument (CodeActivityMetadata metadata, InOutArgument operandLocation, bool isRequired) { RuntimeArgument operandLocationArgument = new RuntimeArgument("OperandLocation", typeof(TOperand), ArgumentDirection.InOut, isRequired); metadata.Bind(operandLocation, operandLocationArgument); metadata.AddArgument(operandLocationArgument); } public static bool TryGenerateLinqDelegate (string memberName, bool isField, bool isStatic, out Func operation, out ValidationError validationError) { operation = null; validationError = null; try { ParameterExpression operandParameter = Expression.Parameter(typeof(TOperand), "operand"); MemberExpression memberExpression = null; if (isStatic) { memberExpression = Expression.MakeMemberAccess(null, GetMemberInfo (memberName, isField)); } else { memberExpression = Expression.MakeMemberAccess(operandParameter, GetMemberInfo (memberName, isField)); } Expression > lambdaExpression = Expression.Lambda >(memberExpression, operandParameter); operation = lambdaExpression.Compile(); return true; } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } validationError = new ValidationError(e.Message); return false; } } static MemberInfo GetMemberInfo (string memberName, bool isField) { MemberInfo result = null; Type declaringType = typeof(TOperand); if (!isField) { result = declaringType.GetProperty(memberName); } else { result = declaringType.GetField(memberName); } if (result == null) { throw FxTrace.Exception.AsError(new ValidationException(SR.MemberNotFound(memberName, typeof(TOperand).Name))); } return result; } } } // 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
- AffineTransform3D.cs
- ActiveDocumentEvent.cs
- LogicalExpr.cs
- SqlCrossApplyToCrossJoin.cs
- WindowManager.cs
- securitycriticaldata.cs
- XmlChildEnumerator.cs
- AccessibleObject.cs
- XPathChildIterator.cs
- EntityCommandExecutionException.cs
- ScrollProperties.cs
- IssuedTokenClientCredential.cs
- SqlOuterApplyReducer.cs
- DataGridCommandEventArgs.cs
- HandlerBase.cs
- HashAlgorithm.cs
- CaseInsensitiveHashCodeProvider.cs
- MessageContractMemberAttribute.cs
- EventEntry.cs
- GrammarBuilder.cs
- BackgroundWorker.cs
- MultiDataTrigger.cs
- TitleStyle.cs
- TableLayoutPanel.cs
- CodeCommentStatementCollection.cs
- DataGridViewCheckBoxColumn.cs
- TextBoxView.cs
- DrawListViewSubItemEventArgs.cs
- InternalConfigHost.cs
- WebPartDescriptionCollection.cs
- DrawingCollection.cs
- ExpressionParser.cs
- Aggregates.cs
- ConfigurationSectionCollection.cs
- ReadOnlyDictionary.cs
- Focus.cs
- base64Transforms.cs
- SubpageParaClient.cs
- OracleConnectionFactory.cs
- TextPattern.cs
- ScriptMethodAttribute.cs
- _IPv4Address.cs
- ToolTipAutomationPeer.cs
- DesignerActionPanel.cs
- SafeBitVector32.cs
- SuppressMessageAttribute.cs
- BindingGraph.cs
- SQLRoleProvider.cs
- DiagnosticTraceSource.cs
- ExceptionRoutedEventArgs.cs
- _HelperAsyncResults.cs
- StringSorter.cs
- StringKeyFrameCollection.cs
- DataGridViewImageCell.cs
- ActiveXContainer.cs
- UnsafeNativeMethods.cs
- CopyCodeAction.cs
- OptionalRstParameters.cs
- TimeSpan.cs
- MachineKeySection.cs
- QueryStringHandler.cs
- IconBitmapDecoder.cs
- ReliableChannelFactory.cs
- ConfigsHelper.cs
- HScrollProperties.cs
- DropShadowBitmapEffect.cs
- Page.cs
- DataTableMapping.cs
- DrawingServices.cs
- FlowDocumentPageViewerAutomationPeer.cs
- ContextMenuService.cs
- ProxyWebPartConnectionCollection.cs
- XmlNodeList.cs
- LinqDataSourceStatusEventArgs.cs
- XmlDownloadManager.cs
- XPathNodeHelper.cs
- Lasso.cs
- PointUtil.cs
- GridViewItemAutomationPeer.cs
- NavigationService.cs
- Axis.cs
- PropertyValueChangedEvent.cs
- CodeLabeledStatement.cs
- ValidationSettings.cs
- DependencyPropertyDescriptor.cs
- GiveFeedbackEvent.cs
- XmlChildNodes.cs
- KeyTimeConverter.cs
- Viewport3DVisual.cs
- BitmapCodecInfoInternal.cs
- LayoutEvent.cs
- KeyedCollection.cs
- Tile.cs
- CatchBlock.cs
- XslTransformFileEditor.cs
- ContentFileHelper.cs
- NullableConverter.cs
- WindowsFormsHostPropertyMap.cs
- CalendarTable.cs
- ProgressBarRenderer.cs