コード例 #1
0
            public override void VisitLiteralExpression(LiteralExpression literalExpression)
            {
                var parts = literalExpression?.Value?.Split ('_');
                if (parts == null || parts.Length < 2)
                    return;

                string platformName;
                switch (parts [0]) {
                case "Platform.Mac":
                    platformName = "PlatformName.MacOSX";
                    break;
                case "Platform.iOS":
                    platformName = "PlatformName.iOS";
                    break;
                default:
                    return;
                }

                if (currentAvailability == null) {
                    switch (originalArgIndex) {
                    case 0:
                        currentAvailability = "Introduced";
                        break;
                    case 1:
                        currentAvailability = "Deprecated";
                        break;
                    case 2:
                        currentAvailability = "Obsoleted";
                        break;
                    case 3:
                        currentAvailability = "Unavailable";
                        break;
                    }
                }

                var attr = new InvocationExpression (currentAvailability);
                attr.AddArgument (new LiteralExpression (platformName));

                if (parts.Length == 2) {
                    switch (parts [1]) {
                    case "Version":
                        break;
                    case "Arch32":
                        attr.AddArgument (new LiteralExpression ("PlatformArchitecture.Arch32"));
                        break;
                    case "Arch64":
                        attr.AddArgument (new LiteralExpression ("PlatformArchitecture.Arch64"));
                        break;
                    }
                } else {
                    for (int i = 1; i < parts.Length; i++)
                        attr.AddArgument (new LiteralExpression (parts [i]));
                }

                invocations.Add (attr);
            }
コード例 #2
0
        static void VisitShorthandIntroducedAttribute(InvocationExpression invocationExpression,
            string platformName)
        {
            bool isTripleVersion = invocationExpression.Arguments.Count () > 2 && invocationExpression.Arguments.Take (3).All (x => x is LiteralExpression && IsNumber(((LiteralExpression)x).Value));

            invocationExpression.Target = new LiteralExpression ("Introduced");

            invocationExpression.Parent.InsertChildBefore (
                invocationExpression.FirstArgument,
                new LiteralExpression (platformName),
                InvocationExpression.ArgumentRole
            );

            foreach (var onlyOn64 in invocationExpression.Arguments.Skip (isTripleVersion ? 4 : 3).Take (2)) {
                var onlyOn64BoolValue = onlyOn64 as LiteralExpression;
                if (onlyOn64 is NamedExpression)
                    onlyOn64BoolValue = onlyOn64.GetChild<Expression> (
                        BinaryExpression.RightOperandRole) as LiteralExpression;
                if (onlyOn64BoolValue != null && onlyOn64BoolValue.Value == "true")
                    invocationExpression.AddArgument (
                        new LiteralExpression ("PlatformArchitecture.Arch64"));
                if (onlyOn64BoolValue != null)
                    onlyOn64.Remove ();
            }
        }
コード例 #3
0
 static void VisitShorthandUnavailableAttribute(LiteralExpression oldAttr, string platformName)
 {
     var newAttr = new InvocationExpression ("Unavailable");
     newAttr.AddArgument (new LiteralExpression (platformName));
     oldAttr.Parent.InsertChildBefore (oldAttr, newAttr);
     oldAttr.Remove ();
 }
コード例 #4
0
 static void VisitMacNamedIntroducedAttribute(LiteralExpression oldAttr, string macMinorVersion)
 {
     var newAttr = new InvocationExpression ("Introduced");
     newAttr.AddArgument (new LiteralExpression ("PlatformName.MacOSX"));
     newAttr.AddArgument (new LiteralExpression ("10"));
     newAttr.AddArgument (new LiteralExpression (macMinorVersion));
     oldAttr.Parent.InsertChildBefore (oldAttr, newAttr);
     oldAttr.Remove ();
 }