Пример #1
0
        public static PlatformSet operator |(PlatformSet a, PlatformSet b)
        {
            if (a == null && b == null)
            {
                return(null);
            }

            var result = new PlatformSet();

            if (a == null)
            {
                result.MacOSX.value  = b.MacOSX.value;
                result.iOS.value     = b.iOS.value;
                result.WatchOS.value = b.WatchOS.value;
                result.TvOS.value    = b.TvOS.value;
            }
            else if (b == null)
            {
                result.MacOSX.value  = a.MacOSX.value;
                result.iOS.value     = a.iOS.value;
                result.WatchOS.value = a.WatchOS.value;
                result.TvOS.value    = a.TvOS.value;
            }
            else
            {
                result.MacOSX.value  = a.MacOSX.value | b.MacOSX.value;
                result.iOS.value     = a.iOS.value | b.iOS.value;
                result.WatchOS.value = a.WatchOS.value | b.WatchOS.value;
                result.TvOS.value    = a.TvOS.value | b.TvOS.value;
            }

            return(result);
        }
        static PlatformAvailability MergeNewStyleAvailabilityAttribute(PlatformAvailability availability, AttributeData attr, AvailabilityKind availabilityKind)
        {
            var      platformName = (PlatformName)(byte)attr.ConstructorArguments[0].Value;
            var      platformSet  = new PlatformSet();
            Platform platform     = platformSet.GetPlatform(platformName);

            if (platform == null)
            {
                throw new ArgumentOutOfRangeException($"Platform name: {platformName}.");
            }

            if (availability == null)
            {
                availability = new PlatformAvailability();
            }

            switch (attr.ConstructorArguments.Length)
            {
            case 3:     //PlatformName platform, PlatformArchitecture architecture, string message
                platform.Architecture = (PlatformArchitecture)(byte)attr.ConstructorArguments[1].Value;
                break;

            case 5:     //PlatformName platform, int majorVersion, int minorVersion, PlatformArchitecture architecture, string message
                platform.Major        = (byte)(int)attr.ConstructorArguments[1].Value;
                platform.Minor        = (byte)(int)attr.ConstructorArguments[2].Value;
                platform.Architecture = (PlatformArchitecture)(byte)attr.ConstructorArguments[3].Value;
                availability.Message  = (string)attr.ConstructorArguments[4].Value;
                break;

            case 6:     //PlatformName platform, int majorVersion, int minorVersion, int subminorVersion, PlatformArchitecture architecture, string message
                platform.Major        = (byte)(int)attr.ConstructorArguments[1].Value;
                platform.Minor        = (byte)(int)attr.ConstructorArguments[2].Value;
                platform.Minor        = (byte)(int)attr.ConstructorArguments[3].Value;
                platform.Architecture = (PlatformArchitecture)(byte)attr.ConstructorArguments[4].Value;
                availability.Message  = (string)attr.ConstructorArguments[5].Value;
                break;
            }

            switch (availabilityKind)
            {
            case AvailabilityKind.Introduced:
                availability.Introduced |= platformSet;
                break;

            case AvailabilityKind.Deprecated:
                availability.Deprecated |= platformSet;
                break;

            case AvailabilityKind.Obsoleted:
                availability.Obsoleted |= platformSet;
                break;

            case AvailabilityKind.Unavailable:
                availability.Unavailable |= platformSet;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(availability);
        }
 static string GetFullName(PlatformSet platformSet, PlatformName platformName) =>
 (platformSet != null) ? platformSet.GetFullName(platformName) : throw new ArgumentNullException();
 static Boolean IsAttributeOfCurrentPlatform(PlatformSet platformSet, PlatformName platformName)
 => (platformSet == null) ? false : platformSet.IsSpecifiedFor(platformName);
        static PlatformAvailability MergeAvailabilityAttribute(PlatformAvailability availability, AttributeData attr)
        {
            if (availability == null)
            {
                availability = new PlatformAvailability();
            }

            // first read positional arguments as they come first syntatically
            int n = Math.Min(attr.ConstructorArguments.Length, 4);

            for (int i = 0; i < n; i++)
            {
                var value = (ulong)attr.ConstructorArguments[i].Value;
                if (value == 0)
                {
                    continue;
                }

                var platform = new PlatformSet(value);

                switch (i)
                {
                case 0:
                    availability.Introduced |= platform;
                    break;

                case 1:
                    availability.Deprecated |= platform;
                    break;

                case 2:
                    availability.Obsoleted |= platform;
                    break;

                case 3:
                    availability.Unavailable |= platform;
                    break;
                }
            }

            // (e.g. [Availability (Platform.Mac_10_9, Introduced = Platform.Mac_10_10)]
            // makes no sense, but could technically happen, in which case Platform.Mac_10_10
            // would be the winner).
            foreach (var named in attr.NamedArguments)
            {
                switch (named.Key)
                {
                case "Introduced":
                    availability.Introduced |= new PlatformSet((ulong)named.Value.Value);
                    break;

                case "Deprecated":
                    availability.Deprecated |= new PlatformSet((ulong)named.Value.Value);
                    break;

                case "Obsoleted":
                    availability.Obsoleted |= new PlatformSet((ulong)named.Value.Value);
                    break;

                case "Unavailable":
                    availability.Unavailable |= new PlatformSet((ulong)named.Value.Value);
                    break;

                case "Message":
                    string message = named.Value.Value as string;

                    if (message != null)     // maybe throw an exception here instead of silently skipping this?
                    {
                        availability.Message += (availability.Message == null) ? message : string.Join("; ", message);
                    }

                    break;
                }
            }

            return(availability);
        }