Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / Microsoft / Scripting / Ast / GotoExpression.cs / 1305376 / GotoExpression.cs
/* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Microsoft Public License. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Microsoft Public License, please send an email to * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Microsoft Public License. * * You must not remove this notice, or any other, from this software. * * * ***************************************************************************/ using System.Diagnostics; using System.Dynamic.Utils; #if SILVERLIGHT using System.Core; #endif namespace System.Linq.Expressions { ////// Specifies what kind of jump this public enum GotoExpressionKind { ///represents. /// /// A Goto, ///that represents a jump to some location. /// /// A Return, ///that represents a return statement. /// /// A Break, ///that represents a break statement. /// /// A Continue, } ///that represents a continue statement. /// /// Represents an unconditional jump. This includes return statements, break and continue statements, and other jumps. /// #if !SILVERLIGHT [DebuggerTypeProxy(typeof(Expression.GotoExpressionProxy))] #endif public sealed class GotoExpression : Expression { private readonly GotoExpressionKind _kind; private readonly Expression _value; private readonly LabelTarget _target; private readonly Type _type; internal GotoExpression(GotoExpressionKind kind, LabelTarget target, Expression value, Type type) { _kind = kind; _value = value; _target = target; _type = type; } ////// Gets the static type of the expression that this ///represents. (Inherited from .) /// The public sealed override Type Type { get { return _type; } } ///that represents the static type of the expression. /// Returns the node type of this ///. (Inherited from .) /// The public sealed override ExpressionType NodeType { get { return ExpressionType.Goto; } } ///that represents this expression. /// The value passed to the target, or null if the target is of type /// System.Void. /// public Expression Value { get { return _value; } } ////// The target label where this node jumps to. /// public LabelTarget Target { get { return _target; } } ////// The kind of the goto. For information purposes only. /// public GotoExpressionKind Kind { get { return _kind; } } ////// Dispatches to the specific visit method for this node type. /// protected internal override Expression Accept(ExpressionVisitor visitor) { return visitor.VisitGoto(this); } ////// Creates a new expression that is like this one, but using the /// supplied children. If all of the children are the same, it will /// return this expression. /// /// Theproperty of the result. /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public GotoExpression Update(LabelTarget target, Expression value) { if (target == Target && value == Value) { return this; } return Expression.MakeGoto(Kind, target, value, Type); } } public partial class Expression { ////// Creates a /// Therepresenting a break statement. /// that the will jump to. /// /// A public static GotoExpression Break(LabelTarget target) { return MakeGoto(GotoExpressionKind.Break, target, null, typeof(void)); } ///with equal to Break, /// the property set to , and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a break statement. The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// /// A public static GotoExpression Break(LabelTarget target, Expression value) { return MakeGoto(GotoExpressionKind.Break, target, value, typeof(void)); } ///with equal to Break, /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a break statement with the specified type. /// that the will jump to. /// An to set the property equal to. /// /// A public static GotoExpression Break(LabelTarget target, Type type) { return MakeGoto(GotoExpressionKind.Break, target, null, type); } ///with equal to Break, /// the property set to , /// and the property set to . /// /// Creates a /// Therepresenting a break statement with the specified type. /// The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// An to set the property equal to. /// /// A public static GotoExpression Break(LabelTarget target, Expression value, Type type) { return MakeGoto(GotoExpressionKind.Break, target, value, type); } ///with equal to Break, /// the property set to , /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a continue statement. /// that the will jump to. /// /// A public static GotoExpression Continue(LabelTarget target) { return MakeGoto(GotoExpressionKind.Continue, target, null, typeof(void)); } ///with equal to Continue, /// the property set to , /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a continue statement with the specified type. /// that the will jump to. /// An to set the property equal to. /// /// A public static GotoExpression Continue(LabelTarget target, Type type) { return MakeGoto(GotoExpressionKind.Continue, target, null, type); } ///with equal to Continue, /// the property set to , /// the property set to , /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a return statement. /// that the will jump to. /// /// A public static GotoExpression Return(LabelTarget target) { return MakeGoto(GotoExpressionKind.Return, target, null, typeof(void)); } ///with equal to Return, /// the property set to , /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a return statement with the specified type. /// that the will jump to. /// An to set the property equal to. /// /// A public static GotoExpression Return(LabelTarget target, Type type) { return MakeGoto(GotoExpressionKind.Return, target, null, type); } ///with equal to Return, /// the property set to , /// the property set to , /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a return statement. The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// /// A public static GotoExpression Return(LabelTarget target, Expression value) { return MakeGoto(GotoExpressionKind.Return, target, value, typeof(void)); } ///with equal to Continue, /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a return statement with the specified type. /// The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// An to set the property equal to. /// /// A public static GotoExpression Return(LabelTarget target, Expression value, Type type) { return MakeGoto(GotoExpressionKind.Return, target, value, type); } ///with equal to Continue, /// the property set to , /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a goto. /// that the will jump to. /// /// A public static GotoExpression Goto(LabelTarget target) { return MakeGoto(GotoExpressionKind.Goto, target, null, typeof(void)); } ///with equal to Goto, /// the property set to the specified value, /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a goto with the specified type. /// that the will jump to. /// An to set the property equal to. /// /// A public static GotoExpression Goto(LabelTarget target, Type type) { return MakeGoto(GotoExpressionKind.Goto, target, null, type); } ///with equal to Goto, /// the property set to the specified value, /// the property set to , /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a goto. The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// /// A public static GotoExpression Goto(LabelTarget target, Expression value) { return MakeGoto(GotoExpressionKind.Goto, target, value, typeof(void)); } ///with equal to Goto, /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a goto with the specified type. /// The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// An to set the property equal to. /// /// A public static GotoExpression Goto(LabelTarget target, Expression value, Type type) { return MakeGoto(GotoExpressionKind.Goto, target, value, type); } ///with equal to Goto, /// the property set to , /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a jump of the specified . /// The value passed to the label upon jumping can also be specified. /// of the . /// The that the will jump to. /// The value that will be passed to the associated label upon jumping. /// An to set the property equal to. /// /// A public static GotoExpression MakeGoto(GotoExpressionKind kind, LabelTarget target, Expression value, Type type) { ValidateGoto(target, ref value, "target", "value"); return new GotoExpression(kind, target, value, type); } private static void ValidateGoto(LabelTarget target, ref Expression value, string targetParameter, string valueParameter) { ContractUtils.RequiresNotNull(target, targetParameter); if (value == null) { if (target.Type != typeof(void)) throw Error.LabelMustBeVoidOrHaveExpression(); } else { ValidateGotoType(target.Type, ref value, valueParameter); } } // Standard argument validation, taken from ValidateArgumentTypes private static void ValidateGotoType(Type expectedType, ref Expression value, string paramName) { RequiresCanRead(value, paramName); if (expectedType != typeof(void)) { if (!TypeUtils.AreReferenceAssignable(expectedType, value.Type)) { // C# autoquotes return values, so we'll do that here if (TypeUtils.IsSameOrSubclass(typeof(LambdaExpression), expectedType) && expectedType.IsAssignableFrom(value.GetType())) { value = Expression.Quote(value); } throw Error.ExpressionTypeDoesNotMatchLabel(value.Type, expectedType); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /* **************************************************************************** * * Copyright (c) Microsoft Corporation. * * This source code is subject to terms and conditions of the Microsoft Public License. A * copy of the license can be found in the License.html file at the root of this distribution. If * you cannot locate the Microsoft Public License, please send an email to * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound * by the terms of the Microsoft Public License. * * You must not remove this notice, or any other, from this software. * * * ***************************************************************************/ using System.Diagnostics; using System.Dynamic.Utils; #if SILVERLIGHT using System.Core; #endif namespace System.Linq.Expressions { ///with equal to , /// the property set to , /// the property set to , /// and to be passed to the target label upon jumping. /// /// Specifies what kind of jump this public enum GotoExpressionKind { ///represents. /// /// A Goto, ///that represents a jump to some location. /// /// A Return, ///that represents a return statement. /// /// A Break, ///that represents a break statement. /// /// A Continue, } ///that represents a continue statement. /// /// Represents an unconditional jump. This includes return statements, break and continue statements, and other jumps. /// #if !SILVERLIGHT [DebuggerTypeProxy(typeof(Expression.GotoExpressionProxy))] #endif public sealed class GotoExpression : Expression { private readonly GotoExpressionKind _kind; private readonly Expression _value; private readonly LabelTarget _target; private readonly Type _type; internal GotoExpression(GotoExpressionKind kind, LabelTarget target, Expression value, Type type) { _kind = kind; _value = value; _target = target; _type = type; } ////// Gets the static type of the expression that this ///represents. (Inherited from .) /// The public sealed override Type Type { get { return _type; } } ///that represents the static type of the expression. /// Returns the node type of this ///. (Inherited from .) /// The public sealed override ExpressionType NodeType { get { return ExpressionType.Goto; } } ///that represents this expression. /// The value passed to the target, or null if the target is of type /// System.Void. /// public Expression Value { get { return _value; } } ////// The target label where this node jumps to. /// public LabelTarget Target { get { return _target; } } ////// The kind of the goto. For information purposes only. /// public GotoExpressionKind Kind { get { return _kind; } } ////// Dispatches to the specific visit method for this node type. /// protected internal override Expression Accept(ExpressionVisitor visitor) { return visitor.VisitGoto(this); } ////// Creates a new expression that is like this one, but using the /// supplied children. If all of the children are the same, it will /// return this expression. /// /// Theproperty of the result. /// The property of the result. /// This expression if no children changed, or an expression with the updated children. public GotoExpression Update(LabelTarget target, Expression value) { if (target == Target && value == Value) { return this; } return Expression.MakeGoto(Kind, target, value, Type); } } public partial class Expression { ////// Creates a /// Therepresenting a break statement. /// that the will jump to. /// /// A public static GotoExpression Break(LabelTarget target) { return MakeGoto(GotoExpressionKind.Break, target, null, typeof(void)); } ///with equal to Break, /// the property set to , and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a break statement. The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// /// A public static GotoExpression Break(LabelTarget target, Expression value) { return MakeGoto(GotoExpressionKind.Break, target, value, typeof(void)); } ///with equal to Break, /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a break statement with the specified type. /// that the will jump to. /// An to set the property equal to. /// /// A public static GotoExpression Break(LabelTarget target, Type type) { return MakeGoto(GotoExpressionKind.Break, target, null, type); } ///with equal to Break, /// the property set to , /// and the property set to . /// /// Creates a /// Therepresenting a break statement with the specified type. /// The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// An to set the property equal to. /// /// A public static GotoExpression Break(LabelTarget target, Expression value, Type type) { return MakeGoto(GotoExpressionKind.Break, target, value, type); } ///with equal to Break, /// the property set to , /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a continue statement. /// that the will jump to. /// /// A public static GotoExpression Continue(LabelTarget target) { return MakeGoto(GotoExpressionKind.Continue, target, null, typeof(void)); } ///with equal to Continue, /// the property set to , /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a continue statement with the specified type. /// that the will jump to. /// An to set the property equal to. /// /// A public static GotoExpression Continue(LabelTarget target, Type type) { return MakeGoto(GotoExpressionKind.Continue, target, null, type); } ///with equal to Continue, /// the property set to , /// the property set to , /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a return statement. /// that the will jump to. /// /// A public static GotoExpression Return(LabelTarget target) { return MakeGoto(GotoExpressionKind.Return, target, null, typeof(void)); } ///with equal to Return, /// the property set to , /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a return statement with the specified type. /// that the will jump to. /// An to set the property equal to. /// /// A public static GotoExpression Return(LabelTarget target, Type type) { return MakeGoto(GotoExpressionKind.Return, target, null, type); } ///with equal to Return, /// the property set to , /// the property set to , /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a return statement. The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// /// A public static GotoExpression Return(LabelTarget target, Expression value) { return MakeGoto(GotoExpressionKind.Return, target, value, typeof(void)); } ///with equal to Continue, /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a return statement with the specified type. /// The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// An to set the property equal to. /// /// A public static GotoExpression Return(LabelTarget target, Expression value, Type type) { return MakeGoto(GotoExpressionKind.Return, target, value, type); } ///with equal to Continue, /// the property set to , /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a goto. /// that the will jump to. /// /// A public static GotoExpression Goto(LabelTarget target) { return MakeGoto(GotoExpressionKind.Goto, target, null, typeof(void)); } ///with equal to Goto, /// the property set to the specified value, /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a goto with the specified type. /// that the will jump to. /// An to set the property equal to. /// /// A public static GotoExpression Goto(LabelTarget target, Type type) { return MakeGoto(GotoExpressionKind.Goto, target, null, type); } ///with equal to Goto, /// the property set to the specified value, /// the property set to , /// and a null value to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a goto. The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// /// A public static GotoExpression Goto(LabelTarget target, Expression value) { return MakeGoto(GotoExpressionKind.Goto, target, value, typeof(void)); } ///with equal to Goto, /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a goto with the specified type. /// The value passed to the label upon jumping can be specified. /// that the will jump to. /// The value that will be passed to the associated label upon jumping. /// An to set the property equal to. /// /// A public static GotoExpression Goto(LabelTarget target, Expression value, Type type) { return MakeGoto(GotoExpressionKind.Goto, target, value, type); } ///with equal to Goto, /// the property set to , /// the property set to , /// and to be passed to the target label upon jumping. /// /// Creates a /// Therepresenting a jump of the specified . /// The value passed to the label upon jumping can also be specified. /// of the . /// The that the will jump to. /// The value that will be passed to the associated label upon jumping. /// An to set the property equal to. /// /// A public static GotoExpression MakeGoto(GotoExpressionKind kind, LabelTarget target, Expression value, Type type) { ValidateGoto(target, ref value, "target", "value"); return new GotoExpression(kind, target, value, type); } private static void ValidateGoto(LabelTarget target, ref Expression value, string targetParameter, string valueParameter) { ContractUtils.RequiresNotNull(target, targetParameter); if (value == null) { if (target.Type != typeof(void)) throw Error.LabelMustBeVoidOrHaveExpression(); } else { ValidateGotoType(target.Type, ref value, valueParameter); } } // Standard argument validation, taken from ValidateArgumentTypes private static void ValidateGotoType(Type expectedType, ref Expression value, string paramName) { RequiresCanRead(value, paramName); if (expectedType != typeof(void)) { if (!TypeUtils.AreReferenceAssignable(expectedType, value.Type)) { // C# autoquotes return values, so we'll do that here if (TypeUtils.IsSameOrSubclass(typeof(LambdaExpression), expectedType) && expectedType.IsAssignableFrom(value.GetType())) { value = Expression.Quote(value); } throw Error.ExpressionTypeDoesNotMatchLabel(value.Type, expectedType); } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.with equal to , /// the property set to , /// the property set to , /// and to be passed to the target label upon jumping. ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EventsTab.cs
- TableColumn.cs
- ParseHttpDate.cs
- WebPartCatalogCloseVerb.cs
- recordstatefactory.cs
- AuthenticationException.cs
- InvalidMessageContractException.cs
- SHA256.cs
- EntityKeyElement.cs
- DesignerSerializerAttribute.cs
- SessionEndingCancelEventArgs.cs
- AsyncStreamReader.cs
- PackUriHelper.cs
- SystemTcpStatistics.cs
- TableCellCollection.cs
- CompModSwitches.cs
- MemberDescriptor.cs
- If.cs
- AutoGeneratedFieldProperties.cs
- WasNotInstalledException.cs
- ConfigurationSectionCollection.cs
- NamedPipeTransportSecurityElement.cs
- METAHEADER.cs
- GAC.cs
- EntitySqlException.cs
- XmlSchemaAttributeGroup.cs
- ProcessModuleCollection.cs
- PartialArray.cs
- BridgeDataReader.cs
- BaseResourcesBuildProvider.cs
- ParamArrayAttribute.cs
- WindowsScrollBar.cs
- SemanticAnalyzer.cs
- TreeView.cs
- MessageSmuggler.cs
- EncoderNLS.cs
- ConstraintConverter.cs
- HttpResponse.cs
- XamlPoint3DCollectionSerializer.cs
- CharacterBuffer.cs
- webproxy.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- EpmCustomContentDeSerializer.cs
- WebPartConnectionsEventArgs.cs
- Rotation3DAnimationUsingKeyFrames.cs
- ProviderBase.cs
- DataRowIndexBuffer.cs
- ObjectStorage.cs
- AxParameterData.cs
- StaticContext.cs
- PermissionListSet.cs
- NodeLabelEditEvent.cs
- TemplateBindingExpression.cs
- CultureInfoConverter.cs
- EndpointReference.cs
- ResourcePermissionBaseEntry.cs
- SharedDp.cs
- FlowThrottle.cs
- TextRangeBase.cs
- JapaneseCalendar.cs
- ValidatorCompatibilityHelper.cs
- XPathAncestorIterator.cs
- _SpnDictionary.cs
- UidPropertyAttribute.cs
- GenericsInstances.cs
- LayoutTableCell.cs
- SystemNetworkInterface.cs
- RowCache.cs
- MsdtcWrapper.cs
- WebPartEditVerb.cs
- SecurityAttributeGenerationHelper.cs
- TiffBitmapDecoder.cs
- StylusSystemGestureEventArgs.cs
- HotSpotCollection.cs
- CapabilitiesUse.cs
- SoapCommonClasses.cs
- TraceLog.cs
- Int64Converter.cs
- NullExtension.cs
- SslStreamSecurityBindingElement.cs
- RelatedPropertyManager.cs
- AnnouncementInnerClient11.cs
- BitStream.cs
- XmlSchemaGroupRef.cs
- RegexMatchCollection.cs
- PersonalizationProviderCollection.cs
- ParserStack.cs
- ZipIOLocalFileDataDescriptor.cs
- RTLAwareMessageBox.cs
- OutputCacheSection.cs
- ProxyWebPartConnectionCollection.cs
- ValidatingPropertiesEventArgs.cs
- XmlReader.cs
- HtmlInputSubmit.cs
- ProxyFragment.cs
- TreeViewImageIndexConverter.cs
- RemoveFromCollection.cs
- GridViewDeletedEventArgs.cs
- XmlMembersMapping.cs
- TransformedBitmap.cs