Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory-5.5.0/Completion/CompletionExtensionMethods.cs @ 13397

Last change on this file since 13397 was 11700, checked in by jkarder, 10 years ago

#2077: created branch and added first version

File size: 2.8 KB
Line 
1//
2// CompletionExtensionMethods.cs
3//
4// Author:
5//       Mike KrÃŒger <mkrueger@xamarin.com>
6//
7// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
8//
9// Permission is hereby granted, free of charge, to any person obtaining a copy
10// of this software and associated documentation files (the "Software"), to deal
11// in the Software without restriction, including without limitation the rights
12// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13// copies of the Software, and to permit persons to whom the Software is
14// furnished to do so, subject to the following conditions:
15//
16// The above copyright notice and this permission notice shall be included in
17// all copies or substantial portions of the Software.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25// THE SOFTWARE.
26using System;
27using ICSharpCode.NRefactory.TypeSystem;
28using System.Linq;
29
30namespace ICSharpCode.NRefactory.Completion
31{
32  public static class CompletionExtensionMethods
33  {
34    /// <summary>
35    /// Gets the EditorBrowsableState of an entity.
36    /// </summary>
37    /// <returns>
38    /// The editor browsable state.
39    /// </returns>
40    /// <param name='entity'>
41    /// Entity.
42    /// </param>
43    public static System.ComponentModel.EditorBrowsableState GetEditorBrowsableState(this IEntity entity)
44    {
45      if (entity == null)
46        throw new ArgumentNullException ("entity");
47
48      var browsableState = entity.Attributes.FirstOrDefault(attr => attr.AttributeType.Name == "EditorBrowsableAttribute" && attr.AttributeType.Namespace == "System.ComponentModel");
49      if (browsableState != null && browsableState.PositionalArguments.Count == 1) {
50        if (browsableState.PositionalArguments [0].ConstantValue is int)
51          return (System.ComponentModel.EditorBrowsableState)(int)browsableState.PositionalArguments [0].ConstantValue;
52      }
53      return System.ComponentModel.EditorBrowsableState.Always;
54    }
55   
56    /// <summary>
57    /// Determines if an entity should be shown in the code completion window. This is the same as:
58    /// <c>GetEditorBrowsableState (entity) != System.ComponentModel.EditorBrowsableState.Never</c>
59    /// </summary>
60    /// <returns>
61    /// <c>true</c> if the entity should be shown; otherwise, <c>false</c>.
62    /// </returns>
63    /// <param name='entity'>
64    /// The entity.
65    /// </param>
66    public static bool IsBrowsable(this IEntity entity)
67    {
68      return GetEditorBrowsableState (entity) != System.ComponentModel.EditorBrowsableState.Never;
69    }
70  }
71}
72
Note: See TracBrowser for help on using the repository browser.