Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / Subtract.cs / 1305376 / Subtract.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Expressions { using System.Activities; using System.Activities.Statements; using System.Linq.Expressions; using System.Activities.Validation; using System.Collections.Generic; using System.ComponentModel; using System.Runtime; public sealed class Subtract: CodeActivity { //Lock is not needed for operationFunction here. The reason is that delegates for a given Subtract are the same. //It's possible that 2 threads are assigning the operationFucntion at the same time. But it's okay because the compiled codes are the same. static Func checkedOperationFunction; static Func uncheckedOperationFunction; bool checkedOperation = true; [RequiredArgument] [DefaultValue(null)] public InArgument Left { get; set; } [RequiredArgument] [DefaultValue(null)] public InArgument Right { get; set; } [DefaultValue(true)] public bool Checked { get { return this.checkedOperation; } set { this.checkedOperation = value; } } protected override void CacheMetadata(CodeActivityMetadata metadata) { BinaryExpressionHelper.OnGetArguments(metadata, this.Left, this.Right); if (this.checkedOperation) { EnsureOperationFunction(metadata, ref checkedOperationFunction, ExpressionType.SubtractChecked); } else { EnsureOperationFunction(metadata, ref uncheckedOperationFunction, ExpressionType.Subtract); } } void EnsureOperationFunction(CodeActivityMetadata metadata, ref Func operationFunction, ExpressionType operatorType) { if (operationFunction == null) { ValidationError validationError; if (!BinaryExpressionHelper.TryGenerateLinqDelegate( operatorType, out operationFunction, out validationError)) { metadata.AddValidationError(validationError); } } } protected override TResult Execute(CodeActivityContext context) { TLeft leftValue = this.Left.Get(context); TRight rightValue = this.Right.Get(context); //if user changed Checked flag between Open and Execution, //a NRE may be thrown and that's by design if (this.checkedOperation) { return checkedOperationFunction(leftValue, rightValue); } else { return uncheckedOperationFunction(leftValue, rightValue); } } } } // 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
- XamlVector3DCollectionSerializer.cs
- CryptoKeySecurity.cs
- SourceChangedEventArgs.cs
- ThousandthOfEmRealPoints.cs
- InfoCardRSAOAEPKeyExchangeDeformatter.cs
- CfgParser.cs
- RoutedPropertyChangedEventArgs.cs
- WorkerRequest.cs
- TextTreeRootNode.cs
- JapaneseCalendar.cs
- PlatformCulture.cs
- Header.cs
- SystemUdpStatistics.cs
- KeyNotFoundException.cs
- HttpListenerContext.cs
- PtsHelper.cs
- ObjectCloneHelper.cs
- SelectionRange.cs
- CriticalHandle.cs
- DataServiceClientException.cs
- XmlSchemas.cs
- AspNetRouteServiceHttpHandler.cs
- IPipelineRuntime.cs
- Environment.cs
- ConstraintCollection.cs
- ITextView.cs
- AQNBuilder.cs
- KeyboardDevice.cs
- InkCanvasInnerCanvas.cs
- SslStream.cs
- EventMappingSettingsCollection.cs
- EventSinkHelperWriter.cs
- Hex.cs
- GenericIdentity.cs
- XmlAttributeAttribute.cs
- ReliabilityContractAttribute.cs
- MinMaxParagraphWidth.cs
- InputReport.cs
- ScaleTransform.cs
- GlyphManager.cs
- DeadLetterQueue.cs
- Interlocked.cs
- TextLine.cs
- OperationContractAttribute.cs
- ChangeToolStripParentVerb.cs
- AliasGenerator.cs
- MemberHolder.cs
- SafeFileMapViewHandle.cs
- RequestResponse.cs
- SmtpFailedRecipientException.cs
- GcSettings.cs
- SliderAutomationPeer.cs
- ObjectDataSourceEventArgs.cs
- ListControlConvertEventArgs.cs
- MessageBuffer.cs
- SqlUserDefinedTypeAttribute.cs
- EnumBuilder.cs
- XmlSerializer.cs
- KeyEventArgs.cs
- Scalars.cs
- ProcessProtocolHandler.cs
- WorkflowRuntimeBehavior.cs
- CompositionAdorner.cs
- ThrowHelper.cs
- DataMisalignedException.cs
- ResourceAssociationType.cs
- SiteMapHierarchicalDataSourceView.cs
- InitiatorServiceModelSecurityTokenRequirement.cs
- Set.cs
- TextBoxRenderer.cs
- GroupBoxRenderer.cs
- CodePrimitiveExpression.cs
- DBPropSet.cs
- TypeUtil.cs
- ModuleConfigurationInfo.cs
- QueryStringParameter.cs
- IntellisenseTextBox.designer.cs
- TypeValidationEventArgs.cs
- DataGridViewCellEventArgs.cs
- ConstraintManager.cs
- InternalRelationshipCollection.cs
- MatrixAnimationUsingPath.cs
- CompositeActivityTypeDescriptorProvider.cs
- TimeSpanValidatorAttribute.cs
- XsltException.cs
- NumberSubstitution.cs
- ObjectAnimationUsingKeyFrames.cs
- QilInvokeLateBound.cs
- WindowsEditBoxRange.cs
- LinkButton.cs
- UriTemplateEquivalenceComparer.cs
- WaveHeader.cs
- WebSysDefaultValueAttribute.cs
- StreamGeometryContext.cs
- RawStylusInputCustomData.cs
- ControlCollection.cs
- BuildTopDownAttribute.cs
- DbConnectionFactory.cs
- AutomationPropertyInfo.cs
- AliasExpr.cs