/// <summary>
        /// Given an IDLProperty, generate all the necessaries
        /// </summary>
        /// <remarks>Override to expand functionality or replace it</remarks>
        /// <param name="idlIntf"></param>
        /// <param name="idlProperty"></param>
        /// <returns></returns>
        public virtual CodeTypeMember HandleProperty(IDLInterface idlIntf, IDLProperty idlProperty)
        {
            CodeMemberProperty property = new CodeMemberProperty();

            property.Comments.Add(new CodeCommentStatement(idlProperty.Name));
            property.Name       = CodeBuilderCommon.GetCompilableName(idlProperty.Name);
            property.Attributes = MemberAttributes.Abstract;
            IDLMethodArgument idlMethodArgGet = new IDLMethodArgument {
                Direction = "out", Name = "value", Type = idlProperty.Type
            };
            IDLMethod idlMethodGet = new IDLMethod
            {
                Arguments = new List <IDLMethodArgument>(new IDLMethodArgument[] { idlMethodArgGet }),
                Name      = "get",
            };

            Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethodGet);
            property.Comments.Add(new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArgGet.Direction, idlMethodArgGet.Name, idlMethodArgGet.Type)));
            // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
            ParamCodeTypeFactory paramtypeHolder = this.CreateParamCodeTypeFactoryForProperty(idlIntf, idlProperty.Name, idlMethodArgGet.Name, idlMethodArgGet.Type, idlMethodArgGet.Direction);

            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);
            Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArgGet.Type, context);

            // Arguments.
            CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(paramtypeHolder.paramtype.CodeType, idlMethodArgGet.Name);

            property.Type   = paramtypeHolder.paramtype.CodeType;
            property.HasGet = CodeBuilderCommon.HasGet(idlProperty);
            property.HasSet = CodeBuilderCommon.HasSet(idlProperty);
            property.Parameters.Add(param);

            return(property);
        }
Example #2
0
        private void GenerateProperty(IDLInterface idlIntf, IDLProperty idlProperty
                                      , CodeTypeReference typerefDbusInterface
                                      , CodeTypeReference typerefDbusMarshal
                                      , CodeTypeDeclaration typeProxy)
        {
            bool hasGet = CodeBuilderCommon.HasGet(idlProperty);
            bool hasSet = CodeBuilderCommon.HasSet(idlProperty);

            if (hasGet || hasSet)
            {
                CodeMemberProperty property = new CodeMemberProperty();
                property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                property.Name       = CodeBuilderCommon.GetCompilableName(idlProperty.Name);
                property.HasGet     = hasGet;
                property.HasSet     = hasSet;
                property.Type       = CodeBuilderCommon.PropertyType(CodeTypeFactory.DefaultProperty, idlProperty.Type);

                property.Comments.Add(new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlProperty.Access, idlProperty.Name, idlProperty.Type)));
                // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.

                CodeVariableDeclarationStatement vardeclTarget         = this.DeclareTargetVariable(typerefDbusInterface, typerefDbusMarshal);
                CodePropertyReferenceExpression  proprefTargetProperty = new CodePropertyReferenceExpression(varrefTarget, property.Name);
                if (hasGet)
                {
                    property.GetStatements.Add(vardeclTarget);
                    property.GetStatements.Add(
                        new CodeMethodReturnStatement(
                            proprefTargetProperty
                            )
                        );
                }

                if (hasSet)
                {
                    property.SetStatements.Add(vardeclTarget);
                    property.SetStatements.Add(
                        new CodeAssignStatement(proprefTargetProperty
                                                , new CodePropertySetValueReferenceExpression()
                                                )
                        );
                }

                // Finish up.
                typeProxy.Members.Add(property);
            }
        }
Example #3
0
        public override CodeTypeMember HandleProperty(IDLInterface idlIntf, IDLProperty idlProperty)
        {
            CodeMemberProperty property = (CodeMemberProperty)base.HandleProperty(idlIntf, idlProperty);

            if (property.HasGet || property.HasSet)
            {
                // Generate the property out of context.
                CodeDomProvider      provider   = CodeDomProvider.CreateProvider("CSharp");
                CodeGeneratorOptions genOptions = CodeBuilderHelper.getCodeGeneratorOptions();
                StringWriter         temp       = new StringWriter();
                provider.GenerateCodeFromMember(property, temp, genOptions);
                string propertyText = temp.ToString();
                propertyText = propertyText.TrimStart();

                //Get ready to store all the output
                StringBuilder result = new StringBuilder();

                // Figure out how much comments exist before doing the real work
                int posSkipStatements = 0;
                while (posSkipStatements + 1 < propertyText.Length && propertyText[posSkipStatements] == '/' && propertyText[posSkipStatements + 1] == '/')
                {
                    posSkipStatements  = propertyText.IndexOf(temp.NewLine, posSkipStatements);
                    posSkipStatements += temp.NewLine.Length;
                }

                //Insert comments into output
                if (posSkipStatements > 0)
                {
                    result.Append(propertyText.Substring(0, posSkipStatements));
                    propertyText = propertyText.Substring(posSkipStatements);
                }

                //Remove abstract modifiers
                const string abstractName = "abstract ";
                if (propertyText.StartsWith(abstractName))
                {
                    propertyText = propertyText.Substring(abstractName.Length);
                }

                // Hacky rewrite of the getter/setter for CSharp.
                if (property.HasGet)
                {
                    propertyText = AddOperationContractToProperty(propertyText, "get;", temp.NewLine);
                }
                if (property.HasSet)
                {
                    propertyText = AddOperationContractToProperty(propertyText, "set;", temp.NewLine);
                }

                // Add the altered text.
                result.Append(propertyText);

                // Mess around with padding.
                string resultText = result.ToString();
                resultText = resultText.Replace(temp.NewLine, temp.NewLine + "        ");
                resultText = "        " + resultText;

                // Add the snippet.
                CodeSnippetTypeMember snipProperty = new CodeSnippetTypeMember(resultText);
                snipProperty.Name = property.Name;
                return(snipProperty);
            }
            else
            {
                return(property);
            }
        }
        /// <summary>
        /// Given an IDLProperty, generate all the necessaries
        /// </summary>
        /// <remarks>Override to expand functionality or replace it</remarks>
        /// <param name="idlIntf"></param>
        /// <param name="idlProperty"></param>
        /// <returns></returns>
        public virtual CodeTypeMember HandleProperty(IDLInterface idlIntf, IDLProperty idlProperty)
        {
            CodeMemberProperty property = new CodeMemberProperty();
            property.Comments.Add(new CodeCommentStatement(idlProperty.Name));
            property.Name = CodeBuilderCommon.GetCompilableName(idlProperty.Name);
            property.Attributes = MemberAttributes.Abstract;
            IDLMethodArgument idlMethodArgGet = new IDLMethodArgument { Direction = "out", Name = "value", Type = idlProperty.Type };
            IDLMethod idlMethodGet = new IDLMethod
            {
                Arguments = new List<IDLMethodArgument>(new IDLMethodArgument[] { idlMethodArgGet }),
                Name = "get",
            };
            Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethodGet);
            property.Comments.Add(new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArgGet.Direction, idlMethodArgGet.Name, idlMethodArgGet.Type)));
            // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
            ParamCodeTypeFactory paramtypeHolder = this.CreateParamCodeTypeFactoryForProperty(idlIntf, idlProperty.Name, idlMethodArgGet.Name, idlMethodArgGet.Type, idlMethodArgGet.Direction);
            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);
            Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArgGet.Type, context);

            // Arguments.
            CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(paramtypeHolder.paramtype.CodeType, idlMethodArgGet.Name);
            property.Type = paramtypeHolder.paramtype.CodeType;
            property.HasGet = CodeBuilderCommon.HasGet(idlProperty);
            property.HasSet = CodeBuilderCommon.HasSet(idlProperty);
            property.Parameters.Add(param);

            return property;
        }
        public override CodeTypeMember HandleProperty(IDLInterface idlIntf, IDLProperty idlProperty)
        {
            CodeMemberProperty property = (CodeMemberProperty)base.HandleProperty(idlIntf, idlProperty);

            if (property.HasGet || property.HasSet)
            {
                // Generate the property out of context.
                CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
                CodeGeneratorOptions genOptions = CodeBuilderHelper.getCodeGeneratorOptions();
                StringWriter temp = new StringWriter();
                provider.GenerateCodeFromMember(property, temp, genOptions);
                string propertyText = temp.ToString();
                propertyText = propertyText.TrimStart();

                //Get ready to store all the output
                StringBuilder result = new StringBuilder();

                // Figure out how much comments exist before doing the real work
                int posSkipStatements = 0;
                while (posSkipStatements + 1 < propertyText.Length && propertyText[posSkipStatements] == '/' && propertyText[posSkipStatements + 1] == '/')
                {
                    posSkipStatements = propertyText.IndexOf(temp.NewLine, posSkipStatements);
                    posSkipStatements += temp.NewLine.Length;
                }

                //Insert comments into output
                if (posSkipStatements > 0)
                {
                    result.Append(propertyText.Substring(0, posSkipStatements));
                    propertyText = propertyText.Substring(posSkipStatements);
                }

                //Remove abstract modifiers
                const string abstractName = "abstract ";
                if (propertyText.StartsWith(abstractName))
                {
                    propertyText = propertyText.Substring(abstractName.Length);
                }

                // Hacky rewrite of the getter/setter for CSharp.
                if (property.HasGet)
                {
                    propertyText = AddOperationContractToProperty(propertyText, "get;", temp.NewLine);
                }
                if (property.HasSet)
                {
                    propertyText = AddOperationContractToProperty(propertyText, "set;", temp.NewLine);
                }

                // Add the altered text.
                result.Append(propertyText);

                // Mess around with padding.
                string resultText = result.ToString();
                resultText = resultText.Replace(temp.NewLine, temp.NewLine + "        ");
                resultText = "        " + resultText;

                // Add the snippet.
                CodeSnippetTypeMember snipProperty = new CodeSnippetTypeMember(resultText);
                snipProperty.Name = property.Name;
                return snipProperty;
            }
            else
            {
                return property;
            }
        }
Example #6
0
 public static bool HasSet(IDLProperty idlProperty)
 {
     return(idlProperty.Access == "readwrite" || idlProperty.Access == "write");
 }
        private void GenerateProperty(IDLInterface idlIntf, IDLProperty idlProperty
            , CodeTypeReference typerefDbusInterface
            , CodeTypeReference typerefDbusMarshal
            , CodeTypeDeclaration typeProxy)
        {
            bool hasGet = CodeBuilderCommon.HasGet(idlProperty);
            bool hasSet = CodeBuilderCommon.HasSet(idlProperty);

            if (hasGet || hasSet)
            {
                CodeMemberProperty property = new CodeMemberProperty();
                property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                property.Name = CodeBuilderCommon.GetCompilableName(idlProperty.Name);
                property.HasGet = hasGet;
                property.HasSet = hasSet;
                property.Type = CodeBuilderCommon.PropertyType(CodeTypeFactory.DefaultProperty, idlProperty.Type);

                property.Comments.Add(new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlProperty.Access, idlProperty.Name, idlProperty.Type)));
                // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.

                CodeVariableDeclarationStatement vardeclTarget = this.DeclareTargetVariable(typerefDbusInterface, typerefDbusMarshal);
                CodePropertyReferenceExpression proprefTargetProperty = new CodePropertyReferenceExpression(varrefTarget, property.Name);
                if (hasGet)
                {
                    property.GetStatements.Add(vardeclTarget);
                    property.GetStatements.Add(
                        new CodeMethodReturnStatement(
                            proprefTargetProperty
                        )
                    );
                }

                if (hasSet)
                {
                    property.SetStatements.Add(vardeclTarget);
                    property.SetStatements.Add(
                        new CodeAssignStatement(proprefTargetProperty
                            , new CodePropertySetValueReferenceExpression()
                        )
                    );
                }

                // Finish up.
                typeProxy.Members.Add(property);
            }
        }
Example #8
0
 private static CodeMemberProperty MakePropertySet(CodeMemberProperty property, CodeTypeFactory codetypefactoryOut, CodeTypeFactory codetypefactoryIn,
     Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
     IDLInterface idlIntf,
     IDLProperty idlProperty,
     Udbus.Parsing.BuildContext context,
     MarshalBuilderHelper codebuilder)
 {
     List<IDLMethodArgument> arguments = new List<IDLMethodArgument>(new IDLMethodArgument[]
     {
         //<arg name="interface_name" type="s"/>
         //<arg name="property_name" type="s"/>
         new IDLMethodArgument{ Name="interface_name", Type="s", Direction="in" },
         new IDLMethodArgument{ Name="property_name", Type="s", Direction="in" },
         //<arg name="value" type="<PropertyType>"/>
         new IDLMethodArgument{ Name="value", Type=idlProperty.Type, Direction="in"}
     }
     );
     MakeMethodParameters(codetypefactoryOut, codetypefactoryIn,
         declarationHolder,
         idlIntf,
         "Set",
         idlProperty.Name,
         arguments,
         new CodeParameterDeclarationExpressionCollection(),
         property.SetStatements,
         context,
         codebuilder
     );
     return property;
 }
Example #9
0
 private static CodeMemberProperty MakePropertySet(CodeMemberProperty property, CodeTypeFactory codetypefactoryOut, CodeTypeFactory codetypefactoryIn,
     Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
     IDLInterface idlIntf,
     IDLProperty idlProperty,
     Udbus.Parsing.BuildContext context)
 {
     return MakePropertySet(property, codetypefactoryOut, codetypefactoryIn, declarationHolder, idlIntf, idlProperty, context, new MarshalBuilderHelperProperty());
 }
Example #10
0
        private static void MakeProperty(CodeTypeFactory codetypefactoryOut, CodeTypeFactory codetypefactoryIn, Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
            IDLInterface idlIntf, CodeTypeDeclaration typeMarshal, IDLProperty idlProperty, bool hasGet, bool hasSet,
            Udbus.Parsing.BuildContext context)
        {
            CodeMemberProperty property = new CodeMemberProperty();
            property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            property.Name = CodeBuilderCommon.GetCompilableName(idlProperty.Name);
            property.HasGet = hasGet;
            property.HasSet = hasSet;

            property.Comments.Add(new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlProperty.Access, idlProperty.Name, idlProperty.Type)));
            // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
            // We use the out factory because its out types we have to return and they tend to be less forgiving than in types.
            property.Type = CodeBuilderCommon.PropertyType(codetypefactoryOut, idlProperty.Type);

            if (hasGet) // If gettable property
            {
                MakePropertyGet(property, codetypefactoryOut, codetypefactoryIn, declarationHolder, idlIntf, idlProperty, context);

            } // Ends if gettable property

            if (hasSet) // If settable property
            {
                MakePropertySet(property, codetypefactoryOut, codetypefactoryIn, declarationHolder, idlIntf, idlProperty, context);

            } // Ends if settable property

            typeMarshal.Members.Add(property);
        }