瀏覽代碼

Reflection protection properties

Brian Fiete 3 年之前
父節點
當前提交
fd9fa3ad89
共有 3 個文件被更改,包括 18 次插入16 次删除
  1. 3 0
      BeefLibs/corlib/src/Reflection/FieldInfo.bf
  2. 10 0
      BeefLibs/corlib/src/Reflection/MethodInfo.bf
  3. 5 16
      BeefLibs/corlib/src/Type.bf

+ 3 - 0
BeefLibs/corlib/src/Reflection/FieldInfo.bf

@@ -25,6 +25,9 @@ namespace System.Reflection
 	    public Type FieldType => Type.[Friend]GetType(mFieldData.mFieldTypeId);
 		public bool IsConst => mFieldData.mFlags.HasFlag(.Const);
 		public bool IsStatic => mFieldData.mFlags.HasFlag(.Static);
+		public bool IsPublic => (mFieldData.mFlags & .FieldAccessMask) == .Public;
+		public bool IsProtected => (mFieldData.mFlags & .FieldAccessMask) == .Protected;
+		public bool IsPrivate => (mFieldData.mFlags & .FieldAccessMask) == 0;
 		public bool IsInstanceField => !mFieldData.mFlags.HasFlag(.Static) && !mFieldData.mFlags.HasFlag(.Const);
 		public StringView Name => mFieldData.mName;
 		public int32 FieldIdx => Compiler.IsComptime ?

+ 10 - 0
BeefLibs/corlib/src/Reflection/MethodInfo.bf

@@ -38,6 +38,16 @@ namespace System.Reflection
 			(mData.mComptimeMethodInstance != 0) :
 			(mData.mMethodData != null);
 
+		public bool IsPublic => Compiler.IsComptime ?
+			(Type.[Friend]Comptime_Method_GetInfo(mData.mComptimeMethodInstance).mMethodFlags & .MethodAccessMask) == .Public :
+			(mData.mMethodData.[Friend]mFlags & .MethodAccessMask) == .Public;
+		public bool IsProtected => Compiler.IsComptime ?
+			(Type.[Friend]Comptime_Method_GetInfo(mData.mComptimeMethodInstance).mMethodFlags & .MethodAccessMask) == .Protected :
+			(mData.mMethodData.[Friend]mFlags & .MethodAccessMask) == .Protected;
+		public bool IsPrivate => Compiler.IsComptime ?
+			(Type.[Friend]Comptime_Method_GetInfo(mData.mComptimeMethodInstance).mMethodFlags & .MethodAccessMask) == 0 :
+			(mData.mMethodData.[Friend]mFlags & .MethodAccessMask) == 0;
+
 		public StringView Name => Compiler.IsComptime ?
 			Type.[Friend]Comptime_Method_GetName(mData.mComptimeMethodInstance) :
 			mData.mMethodData.[Friend]mName;

+ 5 - 16
BeefLibs/corlib/src/Type.bf

@@ -1466,13 +1466,8 @@ namespace System.Reflection
     {
         // member access mask - Use this mask to retrieve accessibility information.
         FieldAccessMask         = 0x0007,
-        PrivateScope            = 0x0000,    // Member not referenceable.
-        Private                 = 0x0001,    // Accessible only by the parent type.  
-        FamAndProject           = 0x0002,    // Accessible by sub-types only in this Assembly.
-        Project                 = 0x0003,    // Accessibly by anyone in the Assembly.
-        Family                  = 0x0004,    // Accessible only by type and sub-types.    
-        FamOrProject            = 0x0005,    // Accessibly by sub-types anywhere, plus anyone in assembly.
-        Public                  = 0x0006,    // Accessibly by anyone who has visibility to this scope.    
+        Protected               = 0x0003,
+        Public                  = 0x0006,
         // end member access mask
     
         // field contract attributes.
@@ -1487,15 +1482,9 @@ namespace System.Reflection
 
 	public enum MethodFlags : uint16
 	{
-		MethodAccessMask    	=  0x0007,
-		PrivateScope        	=  0x0000,     // Member not referenceable.
-		Private             	=  0x0001,     // Accessible only by the parent type.  
-		FamANDAssem         	=  0x0002,     // Accessible by sub-types only in this Assembly.
-		Assembly            	=  0x0003,     // Accessibly by anyone in the Assembly.
-		Family              	=  0x0004,     // Accessible only by type and sub-types.    
-		FamORAssem          	=  0x0005,     // Accessibly by sub-types anywhere, plus anyone in assembly.
-		Public              	=  0x0006,     // Accessibly by anyone who has visibility to this scope.    
-		// end member access mask
+		MethodAccessMask    	= 0x0007,
+		Protected               = 0x0003,
+		Public                  = 0x0006,
 
 		// method contract attributes.
 		Static              	=  0x0010,     // Defined on type, else per instance.