Mono.CSharp.TypeManager.IsFamilyAccessible C# (CSharp) Method

IsFamilyAccessible() public static method

public static IsFamilyAccessible ( System.TypeSpec type, System.TypeSpec parent ) : bool
type System.TypeSpec
parent System.TypeSpec
return bool
	public static bool IsFamilyAccessible (TypeSpec type, TypeSpec parent)
	{
//		TypeParameter tparam = LookupTypeParameter (type);
//		TypeParameter pparam = LookupTypeParameter (parent);

		if (type.Kind == MemberKind.TypeParameter && parent.Kind == MemberKind.TypeParameter) { // (tparam != null) && (pparam != null)) {
			if (type == parent)
				return true;

			throw new NotImplementedException ("net");
//			return tparam.IsSubclassOf (parent);
		}

		do {
			if (IsInstantiationOfSameGenericType (type, parent))
				return true;

			type = type.BaseType;
		} while (type != null);

		return false;
	}

Usage Example

Example #1
0
        //
        // Is this member accessible from invocation context
        //
        public bool IsAccessible(IMemberContext ctx)
        {
            var ma = Modifiers & Modifiers.AccessibilityMask;
            if (ma == Modifiers.PUBLIC)
                return true;

            var parentType = /* this as TypeSpec ?? */ DeclaringType;
            var ctype = ctx.CurrentType;

            if (ma == Modifiers.PRIVATE) {
                if (ctype == null)
                    return false;
                //
                // It's only accessible to the current class or children
                //
                if (parentType.MemberDefinition == ctype.MemberDefinition)
                    return true;

                return TypeManager.IsNestedChildOf (ctype, parentType.MemberDefinition);
            }

            if ((ma & Modifiers.INTERNAL) != 0) {
                bool b;
                var assembly = ctype == null ? ctx.Module.DeclaringAssembly : ctype.MemberDefinition.DeclaringAssembly;

                if (parentType == null) {
                    b = ((ITypeDefinition) MemberDefinition).IsInternalAsPublic (assembly);
                } else {
                    b = DeclaringType.MemberDefinition.IsInternalAsPublic (assembly);
                }

                if (b || ma == Modifiers.INTERNAL)
                    return b;
            }

            //
            // Checks whether `ctype' is a subclass or nested child of `parentType'.
            //
            while (ctype != null) {
                if (TypeManager.IsFamilyAccessible (ctype, parentType))
                    return true;

                // Handle nested types.
                ctype = ctype.DeclaringType;	// TODO: Untested ???
            }

            return false;
        }