Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / Cast.cs / 1305376 / Cast.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Expressions { using System.Activities; using System.Activities.Statements; using System.Activities.Validation; using System.Collections.Generic; using System.ComponentModel; using System.Linq.Expressions; using System.Runtime; public sealed class Cast: CodeActivity { //Lock is not needed for operationFunction here. The reason is that delegates for a given Cast 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 Operand { get; set; } [DefaultValue(true)] public bool Checked { get { return this.checkedOperation; } set { this.checkedOperation = value; } } protected override void CacheMetadata(CodeActivityMetadata metadata) { UnaryExpressionHelper.OnGetArguments(metadata, this.Operand); if (this.checkedOperation) { EnsureOperationFunction(metadata, ref checkedOperationFunction, ExpressionType.ConvertChecked); } else { EnsureOperationFunction(metadata, ref uncheckedOperationFunction, ExpressionType.Convert); } } void EnsureOperationFunction(CodeActivityMetadata metadata, ref Func operationFunction, ExpressionType operatorType) { if (operationFunction == null) { ValidationError validationError; if (!UnaryExpressionHelper.TryGenerateLinqDelegate( operatorType, out operationFunction, out validationError)) { metadata.AddValidationError(validationError); } } } protected override TResult Execute(CodeActivityContext context) { TOperand operandValue = this.Operand.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(operandValue); } else { return uncheckedOperationFunction(operandValue); } } } } // 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
- webclient.cs
- HtmlElement.cs
- UInt32Converter.cs
- TypeReference.cs
- ProfileInfo.cs
- QuaternionValueSerializer.cs
- VarRefManager.cs
- ItemContainerProviderWrapper.cs
- SynchronizationLockException.cs
- HttpModuleActionCollection.cs
- listitem.cs
- SqlServer2KCompatibilityCheck.cs
- PlatformCulture.cs
- RestHandler.cs
- XmlSequenceWriter.cs
- SystemMulticastIPAddressInformation.cs
- ConnectionProviderAttribute.cs
- input.cs
- DataControlFieldCell.cs
- wmiprovider.cs
- _NetworkingPerfCounters.cs
- SqlCommandBuilder.cs
- TypefaceMetricsCache.cs
- CLSCompliantAttribute.cs
- Win32Exception.cs
- RequestNavigateEventArgs.cs
- MediaScriptCommandRoutedEventArgs.cs
- ConsoleTraceListener.cs
- WindowsAuthenticationModule.cs
- ChainOfDependencies.cs
- TraceContextEventArgs.cs
- _TLSstream.cs
- SelectionItemPattern.cs
- XmlSchemaSimpleType.cs
- IsolatedStorageFile.cs
- OperatorExpressions.cs
- RSAProtectedConfigurationProvider.cs
- MemberRelationshipService.cs
- CompositeDesignerAccessibleObject.cs
- WhiteSpaceTrimStringConverter.cs
- InputLanguageEventArgs.cs
- ReachUIElementCollectionSerializer.cs
- PrimitiveType.cs
- ComponentResourceManager.cs
- AccessKeyManager.cs
- InteropExecutor.cs
- ExternalFile.cs
- ProgressBarBrushConverter.cs
- CursorConverter.cs
- DataGridViewCellStyleConverter.cs
- BuiltInPermissionSets.cs
- WrappedReader.cs
- basenumberconverter.cs
- Graph.cs
- InputLanguageSource.cs
- ApplicationServicesHostFactory.cs
- SafeCoTaskMem.cs
- Root.cs
- XmlTextEncoder.cs
- EmptyImpersonationContext.cs
- FormsAuthentication.cs
- basenumberconverter.cs
- TextServicesManager.cs
- ReflectionHelper.cs
- DiscreteKeyFrames.cs
- XD.cs
- DrawingGroup.cs
- PropertyCondition.cs
- OracleLob.cs
- CapabilitiesAssignment.cs
- WebPartMinimizeVerb.cs
- FlowLayoutSettings.cs
- PrintController.cs
- TypefaceCollection.cs
- WebPartMinimizeVerb.cs
- ThemeDictionaryExtension.cs
- HttpSessionStateWrapper.cs
- ContentPropertyAttribute.cs
- CompilationPass2Task.cs
- OperationPerformanceCounters.cs
- SchemaEntity.cs
- TemplatedMailWebEventProvider.cs
- SqlNotificationRequest.cs
- __FastResourceComparer.cs
- XmlRootAttribute.cs
- Policy.cs
- VersionedStreamOwner.cs
- RoleGroupCollection.cs
- RunInstallerAttribute.cs
- AssemblyAssociatedContentFileAttribute.cs
- NamespaceQuery.cs
- SqlWriter.cs
- ResourceExpression.cs
- ObjectStateEntryDbDataRecord.cs
- WebRequest.cs
- hwndwrapper.cs
- CheckBoxPopupAdapter.cs
- ExpressionBuilder.cs
- LinqDataSourceContextEventArgs.cs
- AvtEvent.cs