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 * ***************************************************************************/
16 using System.ComponentModel;
17 using System.Diagnostics;
19 using System.Collections.Generic;
21 namespace System.Runtime.CompilerServices {
23 // Conceptually these are instance methods on CallSite<T> but
24 // we don't want users to see them
27 /// This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.
29 [EditorBrowsable(EditorBrowsableState.Never), DebuggerStepThrough]
30 public static class CallSiteOps {
33 /// Creates an instance of a dynamic call site used for cache lookup.
35 /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
36 /// <returns>The new call site.</returns>
37 [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
38 public static CallSite<T> CreateMatchmaker<T>(CallSite<T> site) where T : class {
39 var mm = site.CreateMatchMaker();
40 CallSiteOps.ClearMatch(mm);
45 /// Checks if a dynamic site requires an update.
47 /// <param name="site">An instance of the dynamic call site.</param>
48 /// <returns>true if rule does not need updating, false otherwise.</returns>
49 [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
50 public static bool SetNotMatched(CallSite site) {
51 var res = site._match;
52 site._match = false; //avoid branch here to make sure the method is inlined
57 /// Checks whether the executed rule matched
59 /// <param name="site">An instance of the dynamic call site.</param>
60 /// <returns>true if rule matched, false otherwise.</returns>
61 [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
62 public static bool GetMatch(CallSite site) {
67 /// Clears the match flag on the matchmaker call site.
69 /// <param name="site">An instance of the dynamic call site.</param>
70 [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
71 public static void ClearMatch(CallSite site) {
76 /// Adds a rule to the cache maintained on the dynamic call site.
78 /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
79 /// <param name="site">An instance of the dynamic call site.</param>
80 /// <param name="rule">An instance of the call site rule.</param>
81 [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
82 public static void AddRule<T>(CallSite<T> site, T rule) where T : class {
87 /// Updates rules in the cache.
89 /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
90 /// <param name="this">An instance of the dynamic call site.</param>
91 /// <param name="matched">The matched rule index.</param>
92 [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
93 public static void UpdateRules<T>(CallSite<T> @this, int matched) where T : class {
95 @this.MoveRule(matched);
100 /// Gets the dynamic binding rules from the call site.
102 /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
103 /// <param name="site">An instance of the dynamic call site.</param>
104 /// <returns>An array of dynamic binding rules.</returns>
105 [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
106 public static T[] GetRules<T>(CallSite<T> site) where T : class {
112 /// Retrieves binding rule cache.
114 /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
115 /// <param name="site">An instance of the dynamic call site.</param>
116 /// <returns>The cache.</returns>
117 [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
118 public static RuleCache<T> GetRuleCache<T>(CallSite<T> site) where T : class {
119 return site.Binder.GetRuleCache<T>();
124 /// Moves the binding rule within the cache.
126 /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
127 /// <param name="cache">The call site rule cache.</param>
128 /// <param name="rule">An instance of the call site rule.</param>
129 /// <param name="i">An index of the call site rule.</param>
130 [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
131 public static void MoveRule<T>(RuleCache<T> cache, T rule, int i) where T : class {
133 cache.MoveRule(rule, i);
138 /// Searches the dynamic rule cache for rules applicable to the dynamic operation.
140 /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
141 /// <param name="cache">The cache.</param>
142 /// <returns>The collection of applicable rules.</returns>
143 [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
144 public static T[] GetCachedRules<T>(RuleCache<T> cache) where T : class {
145 return cache.GetRules();
149 /// Updates the call site target with a new rule based on the arguments.
151 /// <typeparam name="T">The type of the delegate of the <see cref="CallSite"/>.</typeparam>
152 /// <param name="binder">The call site binder.</param>
153 /// <param name="site">An instance of the dynamic call site.</param>
154 /// <param name="args">Arguments to the call site.</param>
155 /// <returns>The new call site target.</returns>
156 [Obsolete("do not use this method", true), EditorBrowsable(EditorBrowsableState.Never)]
157 public static T Bind<T>(CallSiteBinder binder, CallSite<T> site, object[] args) where T : class {
158 return binder.BindCore(site, args);