/// <summary> /// Creates and returns a permission that is the intersection of the current permission and the specified permission. /// </summary> /// <returns> /// A new permission that represents the intersection of the current permission and the specified permission. /// This new permission is <c>null</c> if the intersection is empty. /// </returns> /// <param name="target">A permission to intersect with the current permission. /// It must be of the same type as the current permission.</param> /// <exception cref="ArgumentException">The <paramref name="target"/> parameter is not <c>null</c> /// and is not an instance of the same class as the current permission.</exception> public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } LgLcdPermission permission = target as LgLcdPermission; if (permission == null) { throw new ArgumentException("The target permission must be of type LgLcdPermission.", "target"); } bool monochrome = _monochrome && permission._monochrome; bool qvga = _qvga && permission._qvga; return(monochrome || qvga ? new LgLcdPermission(monochrome, qvga) : null); }
/// <summary> /// Determines whether the current permission is a subset of the specified permission. /// </summary> /// <returns><c>true</c> if the current permission is a subset of the specified permission; /// otherwise, <c>false</c>.</returns> /// <param name="target">A permission that is to be tested for the subset relationship. /// This permission must be of the same type as the current permission.</param> /// <exception cref="ArgumentException">The <paramref name="target"/> parameter is /// not <c>null</c> and is not of the same type as the current permission.</exception> public override bool IsSubsetOf(IPermission target) { if (target == null) { return(!_monochrome && !_qvga); } LgLcdPermission permission = target as LgLcdPermission; if (permission == null) { throw new ArgumentException("The target permission must be of type LgLcdPermission.", "target"); } if (permission.IsUnrestricted()) { return(true); } if (IsUnrestricted()) { return(false); } return(_monochrome == permission._monochrome && _qvga == permission._qvga); }