GenerateObjCName() public static méthode

Generates a valid Objective-C name.
public static GenerateObjCName ( String value ) : String
value String The value.
Résultat String
Exemple #1
0
        private static CodeMemberProperty GenerateProperty(GenerationContext context, @class cls, property property)
        {
            String propertyType = context.ConvertType(property.type, true);
            String propertyName = NamingHelper.GenerateDotNetName(String.Empty, property.name);

            // Define various references
            CodeTypeReference           typeReference           = new CodeTypeReference(propertyType);
            CodeThisReferenceExpression thisReferenceExpression = new CodeThisReferenceExpression();
            CodeTypeReferenceExpression typeReferenceExpression = new CodeTypeReferenceExpression("ObjectiveCRuntime");

            // Define the property
            CodeMemberProperty memberProperty = new CodeMemberProperty();

            memberProperty.Attributes = MemberAttributes.Public;
            memberProperty.Name       = propertyName;
            memberProperty.Type       = typeReference;

            // Generate getter
            switch (property.access)
            {
            case "r":
            case "rw":
            {
                String selector = NamingHelper.GenerateObjCName(property.name);

                CodeMethodReferenceExpression methodReferenceExpression = new CodeMethodReferenceExpression(typeReferenceExpression, "SendMessage");
                methodReferenceExpression.TypeArguments.Add(typeReference);
                CodeMethodInvokeExpression invokeExpression = new CodeMethodInvokeExpression(methodReferenceExpression, thisReferenceExpression, new CodePrimitiveExpression(selector));

                CodeMethodReturnStatement returnStatement = new CodeMethodReturnStatement(invokeExpression);
                memberProperty.GetStatements.Add(returnStatement);
                break;
            }

            default:
                break;
            }

            // Generate setter
            switch (property.access)
            {
            case "rw":
            case "w":
            {
                String selector = "set" + propertyName + ":";

                CodeMethodReferenceExpression methodReferenceExpression = new CodeMethodReferenceExpression(typeReferenceExpression, "SendMessage");
                CodeMethodInvokeExpression    invokeExpression          = new CodeMethodInvokeExpression(methodReferenceExpression, thisReferenceExpression, new CodePrimitiveExpression(selector), new CodeVariableReferenceExpression("value"));

                CodeExpressionStatement expressionStatement = new CodeExpressionStatement(invokeExpression);
                memberProperty.SetStatements.Add(expressionStatement);
                break;
            }

            default:
                break;
            }

            return(memberProperty);
        }
Exemple #2
0
        private static CodeMemberProperty GenerateElement(GenerationContext context, @class cls, element element)
        {
            String value;
            @class typeCls = context.Classes.FirstOrDefault(c => String.Equals(c.name, element.type));

            if (typeCls != null)
            {
                // Make sure that we use the correct plural
                value = typeCls.plural ?? typeCls.name + "s";
            }
            else
            {
                // Use the default name
                value = element.type;
            }
            String elementName = NamingHelper.GenerateDotNetName(String.Empty, value);
            String selector    = NamingHelper.GenerateObjCName(value);

            // Define various references
            CodeTypeReference           typeReference           = new CodeTypeReference("SBElementArray");
            CodeThisReferenceExpression thisReferenceExpression = new CodeThisReferenceExpression();
            CodeTypeReferenceExpression typeReferenceExpression = new CodeTypeReferenceExpression("ObjectiveCRuntime");

            // Define the property
            CodeMemberProperty memberProperty = new CodeMemberProperty();

            memberProperty.Attributes = MemberAttributes.Public;
            memberProperty.Name       = elementName;
            memberProperty.Type       = typeReference;

            // Generate the getter
            CodeMethodReferenceExpression methodReferenceExpression = new CodeMethodReferenceExpression(typeReferenceExpression, "SendMessage");

            methodReferenceExpression.TypeArguments.Add(typeReference);
            CodeMethodInvokeExpression invokeExpression = new CodeMethodInvokeExpression(methodReferenceExpression, thisReferenceExpression, new CodePrimitiveExpression(selector));

            CodeMethodReturnStatement returnStatement = new CodeMethodReturnStatement(invokeExpression);

            memberProperty.GetStatements.Add(returnStatement);

            return(memberProperty);
        }
Exemple #3
0
        private static CodeMemberMethod GenerateCommand(GenerationContext context, @class cls, command command)
        {
            bool   isApplication      = GenerationContext.IsApplicationClass(cls);
            String returnType         = context.ConvertType(GenerationContext.GetType(command.result) ?? "void", true);
            bool   hasReturnType      = returnType != "void";
            bool   useDirectParameter = isApplication && command.directparameter != null && command.directparameter.type != "specifier";
            String methodName         = NamingHelper.GenerateDotNetMethodsName(command);

            // Define various references
            CodeTypeReference             typeReference             = new CodeTypeReference(returnType);
            CodeThisReferenceExpression   thisReferenceExpression   = new CodeThisReferenceExpression();
            CodeTypeReferenceExpression   typeReferenceExpression   = new CodeTypeReferenceExpression("ObjectiveCRuntime");
            CodeMethodReferenceExpression methodReferenceExpression = new CodeMethodReferenceExpression(typeReferenceExpression, "SendMessage");

            if (hasReturnType)
            {
                methodReferenceExpression.TypeArguments.Add(typeReference);
            }

            // Define the method
            CodeMemberMethod memberMethod = new CodeMemberMethod();

            memberMethod.Attributes = MemberAttributes.Public;
            memberMethod.Name       = methodName;
            if (hasReturnType)
            {
                memberMethod.ReturnType = typeReference;
            }

            // Gather all the expressions needed for the invocation.
            List <CodeExpression> expressions = new List <CodeExpression>();

            expressions.Add(thisReferenceExpression);
            expressions.Add(new CodePrimitiveExpression(NamingHelper.GenerateObjCSelector(command, isApplication)));

            // If the command is for the application and the direct parameter is not an object specifier, add it to the signature
            if (useDirectParameter)
            {
                CodeParameterDeclarationExpression parameterDeclarationExpression = new CodeParameterDeclarationExpression();
                parameterDeclarationExpression.Type = new CodeTypeReference(context.ConvertType(GenerationContext.GetType(command.directparameter), true));
                parameterDeclarationExpression.Name = "x";
                memberMethod.Parameters.Add(parameterDeclarationExpression);

                expressions.Add(new CodeVariableReferenceExpression(parameterDeclarationExpression.Name));
            }

            // Add all the parameters
            if (command.parameter != null)
            {
                foreach (parameter parameter in command.parameter)
                {
                    CodeParameterDeclarationExpression parameterDeclarationExpression = new CodeParameterDeclarationExpression();
                    parameterDeclarationExpression.Type = new CodeTypeReference(context.ConvertType(GenerationContext.GetType(parameter), true));
                    parameterDeclarationExpression.Name = GenerationContext.ConvertParameterName(NamingHelper.GenerateObjCName(parameter.name));
                    memberMethod.Parameters.Add(parameterDeclarationExpression);

                    expressions.Add(new CodeVariableReferenceExpression(parameterDeclarationExpression.Name));
                }
            }

            // Generate the runtime invocation
            CodeMethodInvokeExpression invokeExpression = new CodeMethodInvokeExpression(methodReferenceExpression, expressions.ToArray());
            CodeStatement expressionStatement;

            if (hasReturnType)
            {
                expressionStatement = new CodeMethodReturnStatement(invokeExpression);
            }
            else
            {
                expressionStatement = new CodeExpressionStatement(invokeExpression);
            }
            memberMethod.Statements.Add(expressionStatement);

            return(memberMethod);
        }