1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
5 * This source code is subject to terms and conditions of the Microsoft Public License. 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 Microsoft Public License, 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 Microsoft Public License.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
15 using System; using Microsoft;
19 using System.Dynamic.Utils;
21 using Microsoft.Scripting.Utils;
25 namespace System.Linq.Expressions {
27 namespace Microsoft.Linq.Expressions {
31 /// Used to denote the target of a <see cref="GotoExpression"/>.
33 public sealed class LabelTarget {
34 private readonly Type _type;
35 private readonly string _name;
37 internal LabelTarget(Type type, string name) {
43 /// Gets the name of the label.
45 /// <remarks>The label's name is provided for information purposes only.</remarks>
51 /// The type of value that is passed when jumping to the label
52 /// (or System.Void if no value should be passed).
54 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")]
60 /// Returns a <see cref="String"/> that represents the current <see cref="Object"/>.
62 /// <returns>A <see cref="String"/> that represents the current <see cref="Object"/>. </returns>
63 public override string ToString() {
64 return String.IsNullOrEmpty(this.Name) ? "UnamedLabel" : this.Name;
68 public partial class Expression {
70 /// Creates a <see cref="LabelTarget"/> representing a label with void type and no name.
72 /// <returns>The new <see cref="LabelTarget"/>.</returns>
73 public static LabelTarget Label() {
74 return Label(typeof(void), null);
78 /// Creates a <see cref="LabelTarget"/> representing a label with void type and the given name.
80 /// <param name="name">The name of the label.</param>
81 /// <returns>The new <see cref="LabelTarget"/>.</returns>
82 public static LabelTarget Label(string name) {
83 return Label(typeof(void), name);
87 /// Creates a <see cref="LabelTarget"/> representing a label with the given type.
89 /// <param name="type">The type of value that is passed when jumping to the label.</param>
90 /// <returns>The new <see cref="LabelTarget"/>.</returns>
91 public static LabelTarget Label(Type type) {
92 return Label(type, null);
96 /// Creates a <see cref="LabelTarget"/> representing a label with the given type and name.
98 /// <param name="type">The type of value that is passed when jumping to the label.</param>
99 /// <param name="name">The name of the label.</param>
100 /// <returns>The new <see cref="LabelTarget"/>.</returns>
101 public static LabelTarget Label(Type type, string name) {
102 ContractUtils.RequiresNotNull(type, "type");
103 TypeUtils.ValidateType(type);
104 return new LabelTarget(type, name);