1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
6 * copy of the license can be found in the License.html file at the root of this distribution. If
7 * you cannot locate the Apache License, Version 2.0, please send an email to
8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
9 * by the terms of the Apache License, Version 2.0.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
17 using System.Dynamic.Utils;
20 namespace Microsoft.Scripting.Ast {
22 namespace System.Linq.Expressions {
26 /// Used to denote the target of a <see cref="GotoExpression"/>.
28 public sealed class LabelTarget {
29 private readonly Type _type;
30 private readonly string _name;
32 internal LabelTarget(Type type, string name) {
38 /// Gets the name of the label.
40 /// <remarks>The label's name is provided for information purposes only.</remarks>
46 /// The type of value that is passed when jumping to the label
47 /// (or System.Void if no value should be passed).
49 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")]
55 /// Returns a <see cref="String"/> that represents the current <see cref="Object"/>.
57 /// <returns>A <see cref="String"/> that represents the current <see cref="Object"/>. </returns>
58 public override string ToString() {
59 return String.IsNullOrEmpty(this.Name) ? "UnamedLabel" : this.Name;
63 public partial class Expression {
65 /// Creates a <see cref="LabelTarget"/> representing a label with void type and no name.
67 /// <returns>The new <see cref="LabelTarget"/>.</returns>
68 public static LabelTarget Label() {
69 return Label(typeof(void), null);
73 /// Creates a <see cref="LabelTarget"/> representing a label with void type and the given name.
75 /// <param name="name">The name of the label.</param>
76 /// <returns>The new <see cref="LabelTarget"/>.</returns>
77 public static LabelTarget Label(string name) {
78 return Label(typeof(void), name);
82 /// Creates a <see cref="LabelTarget"/> representing a label with the given type.
84 /// <param name="type">The type of value that is passed when jumping to the label.</param>
85 /// <returns>The new <see cref="LabelTarget"/>.</returns>
86 public static LabelTarget Label(Type type) {
87 return Label(type, null);
91 /// Creates a <see cref="LabelTarget"/> representing a label with the given type and name.
93 /// <param name="type">The type of value that is passed when jumping to the label.</param>
94 /// <param name="name">The name of the label.</param>
95 /// <returns>The new <see cref="LabelTarget"/>.</returns>
96 public static LabelTarget Label(Type type, string name) {
97 ContractUtils.RequiresNotNull(type, "type");
98 TypeUtils.ValidateType(type);
99 return new LabelTarget(type, name);