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

IsNestedChildOf() public static method

public static IsNestedChildOf ( System.TypeSpec type, ITypeDefinition parent ) : bool
type System.TypeSpec
parent ITypeDefinition
return bool
	public static bool IsNestedChildOf (TypeSpec type, ITypeDefinition parent)
	{
		if (type == null)
			return false;

		if (type.MemberDefinition == parent)
			return false;

		type = type.DeclaringType;
		while (type != null) {
			if (type.MemberDefinition == parent)
				return true;

			type = type.DeclaringType;
		}

		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;
        }