Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Expressions / LambdaReference.cs / 1305376 / LambdaReference.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.Expressions
{
using System;
using System.Activities.ExpressionParser;
using System.Activities.XamlIntegration;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Runtime;
using System.Windows.Markup;
// consciously not XAML-friendly since Linq Expressions aren't create-set-use
[Fx.Tag.XamlVisible(false)]
public sealed class LambdaReference : CodeActivity>, IExpressionContainer, IValueSerializableExpression
{
Expression> locationExpression;
Expression> rewrittenTree;
LocationFactory locationFactory;
public LambdaReference(Expression> locationExpression)
{
Fx.Assert(locationExpression != null, "locationExpression should not be null");
this.locationExpression = locationExpression;
this.SkipArgumentResolution = true;
}
Expression IExpressionContainer.Expression
{
get
{
return this.locationExpression;
}
}
protected override void CacheMetadata(CodeActivityMetadata metadata)
{
// We need to rewrite the tree.
Expression newTree;
if (ExpressionUtilities.TryRewriteLambdaExpression(this.locationExpression, out newTree, metadata))
{
this.rewrittenTree = (Expression>)newTree;
}
else
{
this.rewrittenTree = this.locationExpression;
}
// inspect the expressionTree to see if it is a valid location expression(L-value)
string extraErrorMessage = null;
if (!ExpressionUtilities.IsLocation(this.rewrittenTree, typeof(T), out extraErrorMessage))
{
string errorMessage = SR.InvalidLValueExpression;
if (extraErrorMessage != null)
{
errorMessage += ":" + extraErrorMessage;
}
metadata.AddValidationError(errorMessage);
}
}
internal override bool TryGetValue(ActivityContext context, out Location value)
{
if (this.locationFactory == null)
{
this.locationFactory = ExpressionUtilities.CreateLocationFactory(this.rewrittenTree);
}
value = this.locationFactory.CreateLocation(context);
return true;
}
protected override Location Execute(CodeActivityContext context)
{
return ExecuteWithTryGetValue(context);
}
public bool CanConvertToString(IValueSerializerContext context)
{
return true;
}
public string ConvertToString(IValueSerializerContext context)
{
// This workflow contains lambda expressions specified in code.
// These expressions are not XAML serializable.
// In order to make your workflow XAML-serializable,
// use either VisualBasicValue/Reference or ExpressionServices.Convert
// This will convert your lambda expressions into expression activities.
throw FxTrace.Exception.AsError(new LambdaSerializationException());
}
}
}
// 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
- WebPartMenu.cs
- SimpleWebHandlerParser.cs
- StorageEntityContainerMapping.cs
- Button.cs
- LoginNameDesigner.cs
- BinHexEncoder.cs
- Vector.cs
- Point.cs
- ExpressionConverter.cs
- SoapElementAttribute.cs
- NCryptNative.cs
- RangeBaseAutomationPeer.cs
- StateChangeEvent.cs
- TranslateTransform.cs
- ObsoleteAttribute.cs
- PerfService.cs
- GridViewAutomationPeer.cs
- DataGridViewTextBoxColumn.cs
- SubstitutionList.cs
- SecurityManager.cs
- DataObjectAttribute.cs
- FixedTextContainer.cs
- SqlNotificationEventArgs.cs
- Maps.cs
- CompiledXpathExpr.cs
- CollectionBuilder.cs
- Schema.cs
- RoleBoolean.cs
- ThreadStaticAttribute.cs
- Helper.cs
- Canvas.cs
- SoapEnvelopeProcessingElement.cs
- ArgumentsParser.cs
- UserInitiatedNavigationPermission.cs
- xmlfixedPageInfo.cs
- InfoCardAsymmetricCrypto.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- SplineKeyFrames.cs
- ComplexTypeEmitter.cs
- MouseWheelEventArgs.cs
- XmlChoiceIdentifierAttribute.cs
- _SSPIWrapper.cs
- GridViewRowEventArgs.cs
- FontFamilyConverter.cs
- ObjectTag.cs
- MappingMetadataHelper.cs
- DesignerOptionService.cs
- TagMapCollection.cs
- PackageProperties.cs
- CursorEditor.cs
- SocketPermission.cs
- ProtocolInformationReader.cs
- SpecialNameAttribute.cs
- XmlSchemaInferenceException.cs
- Interop.cs
- Rectangle.cs
- ImageSource.cs
- TextRangeProviderWrapper.cs
- DataGridCellAutomationPeer.cs
- ConfigurationSectionGroup.cs
- CustomMenuItemCollection.cs
- OracleConnectionString.cs
- EncoderParameter.cs
- ObjectSet.cs
- GcSettings.cs
- RuleSettingsCollection.cs
- EntityDataSourceSelectedEventArgs.cs
- Vector3DAnimation.cs
- IdnElement.cs
- SpeechUI.cs
- ColorMatrix.cs
- PathData.cs
- SqlStatistics.cs
- ConnectionStringSettingsCollection.cs
- Interlocked.cs
- ResourcesBuildProvider.cs
- ValidationError.cs
- ReadOnlyTernaryTree.cs
- EnvironmentPermission.cs
- PropertyEmitterBase.cs
- CompilerGlobalScopeAttribute.cs
- Type.cs
- Keyboard.cs
- StrokeCollection2.cs
- QueryExpr.cs
- ResourceExpression.cs
- Point3DValueSerializer.cs
- PeerPresenceInfo.cs
- ConstraintStruct.cs
- CollectionBase.cs
- columnmapfactory.cs
- Site.cs
- RegexCode.cs
- ArraySegment.cs
- WindowsSlider.cs
- CompoundFileReference.cs
- SecurityDescriptor.cs
- BrowserDefinition.cs
- ArrayWithOffset.cs
- processwaithandle.cs