forked from IronLanguages/ironpython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonHiddenAttribute.cs
More file actions
40 lines (35 loc) · 1.86 KB
/
PythonHiddenAttribute.cs
File metadata and controls
40 lines (35 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using System;
using System.Reflection;
namespace IronPython.Runtime {
/// <summary>
/// Marks a member as being hidden from Python code.
/// </summary>
/// <inheritdoc />
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class PythonHiddenAttribute : PlatformsAttribute {
public PythonHiddenAttribute(params PlatformID[] hiddenPlatforms) {
ValidPlatforms = hiddenPlatforms;
}
public PythonHiddenAttribute(PlatformsAttribute.PlatformFamily hiddenPlatformFamily) {
SetValidPlatforms(hiddenPlatformFamily);
}
public PythonHiddenAttribute(PlatformsAttribute.PlatformFamily hiddenPlatformFamily, params PlatformID[] hiddenPlatforms)
: this(hiddenPlatformFamily) {
var allHiddenPlatforms = new PlatformID[ValidPlatforms.Length + hiddenPlatforms.Length];
Array.Copy(ValidPlatforms, allHiddenPlatforms, ValidPlatforms.Length);
Array.Copy(hiddenPlatforms, 0, allHiddenPlatforms, ValidPlatforms.Length, hiddenPlatforms.Length);
ValidPlatforms = allHiddenPlatforms;
}
public static bool IsHidden(MemberInfo m, bool inherit = false) {
var hasHiddenAttribute = m.IsDefined(typeof(PythonHiddenAttribute), inherit);
if (hasHiddenAttribute) {
var attrs = m.GetCustomAttributes(typeof(PythonHiddenAttribute), inherit);
return ((PythonHiddenAttribute)attrs[0]).IsPlatformValid;
}
return false;
}
}
}