/// <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 void GenerateProperties(IDLInterface idlIntf) { if (idlIntf.Properties != null && idlIntf.Properties.Count > 0) // If got properties { foreach (IDLProperty idlProperty in idlIntf.Properties) { bool hasGet = CodeBuilderCommon.HasGet(idlProperty); bool hasSet = CodeBuilderCommon.HasSet(idlProperty); if (!hasGet && !hasSet) { continue; } 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.Default, 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. CodePropertyReferenceExpression proprefTargetProperty = new CodePropertyReferenceExpression(thisProxyFieldRef, property.Name); if (hasGet) { property.GetStatements.Add( new CodeMethodReturnStatement( proprefTargetProperty ) ); } if (hasSet) { property.SetStatements.Add( new CodeAssignStatement(proprefTargetProperty , new CodePropertySetValueReferenceExpression() ) ); } // Finish up. typeProxy.Members.Add(property); } // Ends loop over properties } // Ends if got properties }
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); } }