public void InitializeInterface(IDLInterface idlIntf) { this.bAddNamespace = false; this.ifName = CodeBuilderCommon.GetName(idlIntf.Name, null); this.nsName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new InterfaceVisitor()); this.service = CodeBuilderCommon.GetName(idlIntf.Name, null); this.nsServiceName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFServiceVisitor()); this.nsWCFInterfaceName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFContractVisitor()); this.wcfinterface = CodeBuilderCommon.GetName(idlIntf.Name, null); this.genInterfaceName = CodeBuilderCommon.GetName(idlIntf.Name, new InterfaceVisitor()); this.scopedGenInterfaceName = CodeBuilderCommon.GetScopedName(nsName, genInterfaceName); this.scopedWCFInterface = CodeBuilderCommon.GetScopedName(this.nsWCFInterfaceName, CodeBuilderCommon.GetName(idlIntf.Name, new InterfaceVisitor())); this.dbusservice = CodeBuilderCommon.GetName(idlIntf.Name, new DBUSServiceVisitor()); this.scopedDbusServiceName = CodeBuilderCommon.GetScopedName(this.nsName, this.dbusservice); this.callbackInterfaceName = CodeBuilderCommon.GetSignalCallbackInterfaceName(this.wcfinterface); this.scopedCallbackInterfaceName = CodeBuilderCommon.GetScopedName(this.nsWCFInterfaceName, this.callbackInterfaceName); this.typerefDbusInterface = new CodeTypeReference(this.scopedGenInterfaceName); this.typerefWCFInterface = new CodeTypeReference(this.scopedWCFInterface); this.typerefDbusMarshal = new CodeTypeReference(this.scopedDbusServiceName); this.typerefexprDbusMarshal = new CodeTypeReferenceExpression(this.typerefDbusMarshal); this.typerefWCFCallbackInterface = new CodeTypeReference(this.scopedCallbackInterfaceName); }
private string getScopedNamesResult(ref string fullName, string result) { result = CodeBuilderCommon.GetScopedName(this.intf.Name, result); fullName = CodeBuilderCommon.GetScopedName(this.intf.Name, result); return(result); }
public override void EndStruct(Udbus.Parsing.BuildContext context, Udbus.Parsing.IParamCodeTypeHandler paramtypeHandler) { base.EndStruct(context, paramtypeHandler); context.declarationHolder.Add(this.declaration); paramtypeHandler.HandleStruct(new Udbus.Parsing.CodeParamDeclaredType(this.declaration), this.name, CodeBuilderCommon.GetScopedName(CodeBuilderCommon.nsDbusMarshalCustom, context.declarationHolder.Name) ); }
public override void ProcessNamespaces(IDLInterface idlIntf) { //Get the necessary names this.ifName = CodeBuilderCommon.GetName(idlIntf.Name, null); this.nsName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new InterfaceVisitor()); this.nsContractName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFContractVisitor()); string nsServiceName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFServiceVisitor()); //Local scope, not needed later //Get the necessary scoped names this.scopedDbusServiceName = CodeBuilderCommon.GetScopedName(this.nsName, CodeBuilderCommon.GetName(idlIntf.Name, new DBUSServiceVisitor())); this.scopedWCFContractName = CodeBuilderCommon.GetScopedName(this.nsContractName, CodeBuilderCommon.GetName(idlIntf.Name, new InterfaceVisitor())); this.scopedWCFServiceName = CodeBuilderCommon.GetScopedName(nsServiceName, CodeBuilderCommon.GetName(idlIntf.Name, new WCFServiceVisitor())); //Get our the Host's namespace and give it all the imports it requires this.nsHost = new CodeNamespace(CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFHostVisitor())); CodeBuilderCommon.AddUsingNamespaces(this.nsHost, new WCFHostVisitor()); }
public override void DeclareCodeType(IDLInterface idlIntf) { //Declare code type references this.typerefWCFService = new CodeTypeReference(this.scopedWCFServiceName); CodeTypeReference typerefConstants = new CodeTypeReference(CodeBuilderCommon.GetScopedName(this.nsName, CodeBuilderCommon.nameConstantsClass)); CodeTypeReference typerefWCFContract = new CodeTypeReference(this.scopedWCFContractName); CodeTypeReference typerefDbusService = new CodeTypeReference(this.scopedDbusServiceName); //No idea... this.type = BuildMakeServiceHostCreationDataImplementation(this.ifName, this.nsContractName, this.typerefWCFService, typerefWCFContract, typerefDbusService); this.nsHost.Types.Add(this.type); CodeTypeReference typeref = new CodeTypeReference(CodeBuilderCommon.GetScopedName(nsHost.Name, this.type.Name)); // Idiotic Partial class for initialisation. this.typedeclInitHostMakerRegistry = new CodeTypeDeclaration("InitHostMakerRegistry"); this.typedeclInitHostMakerRegistry.IsPartial = true; this.typedeclInitHostMakerRegistry.Attributes = MemberAttributes.Public | MemberAttributes.Final; this.typerefInitService = new CodeTypeReference(this.typeRegistryListEntry); this.typerefInitService.TypeArguments.Add(typeref); this.fieldAddInit = new CodeMemberField(typerefRegistryListEntryBase, "add" + typerefWCFService.BaseType.Replace('.', '_')); }
private CodeTypeDeclaration BuildMakeServiceHostCreationDataImplementation(string ifName, string nsWCFContractsName, CodeTypeReference typerefWCFService, CodeTypeReference typerefWCFContract, CodeTypeReference typerefService) { string nsWCFHost = CodeBuilderCommon.typeServiceHostCreationData.Namespace; string scopedWCFServiceParams = CodeBuilderCommon.GetScopedName(nsWCFHost, nameWCFServiceParams); CodeTypeReferenceExpression typerefexprWCFService = new CodeTypeReferenceExpression(typerefWCFService); CodeArgumentReferenceExpression argrefUriBase = new CodeArgumentReferenceExpression(nameUriBaseArg); CodeTypeReference typerefConstants = new CodeTypeReference(CodeBuilderCommon.GetScopedName(nsWCFContractsName, CodeBuilderCommon.nameConstantsClass)); CodeTypeReferenceExpression typerefexprConstants = new CodeTypeReferenceExpression(typerefConstants); Type typeIMakeServiceHostCreationData = typeof(Udbus.WCF.Service.Host.IMakeServiceHostCreationData); CodeTypeDeclaration typeImpl = new CodeTypeDeclaration(string.Format("MakeServiceHostCreationData{0}", ifName)); typeImpl.Attributes = MemberAttributes.Public; typeImpl.BaseTypes.Add(new CodeTypeReference(typeIMakeServiceHostCreationData)); CodeTypeReference typerefImpl = new CodeTypeReference(typeImpl.Name); CodeMethodInvokeExpression invokeGetDbusServiceCreationParams = new CodeMethodInvokeExpression(null, GetDbusServiceCreationParams); CodeTypeOfExpression typeofWCFService = new CodeTypeOfExpression(typerefWCFService); // CreateService() CodeMemberMethod methodCreateService = this.CreateService(typerefWCFService, typerefService); CodeMemberMethod methodCreateServiceCreationData = new CodeMemberMethod(); methodCreateServiceCreationData.Name = "CreateServiceCreationData"; methodCreateServiceCreationData.Attributes = MemberAttributes.Static; CodeTypeReference typerefServiceCreationData = new CodeTypeReference(typeof(Udbus.WCF.Service.Host.WCFServiceCreationData <,>)); typerefServiceCreationData.TypeArguments.Add(typerefWCFService); typerefServiceCreationData.TypeArguments.Add(CodeBuilderCommon.typerefWCFServiceParams); methodCreateServiceCreationData.ReturnType = typerefServiceCreationData; methodCreateServiceCreationData.Statements.Add(new CodeMethodReturnStatement( new CodeObjectCreateExpression(typerefServiceCreationData // CreateService // Static creation method in this class , new CodeMethodReferenceExpression(null, CreateServiceName) // GetDbusServiceCreationParams() , invokeGetDbusServiceCreationParams //// <wcf_contracts>.Constants.DbusServiceRelativeAddress //, new CodeFieldReferenceExpression(typerefexprConstants, CodeBuilderCommon.nameRelativeAddress) //// typeof(<contract>) //, new CodeTypeOfExpression(typerefWCFContract) ))); // static Udbus.WCF.Host.DbusServiceCreationParams GetDbusServiceCreationParams() //{ // return new Udbus.WCF.Host.DbusServiceCreationParams(org.freedesktop.DBus.Properties.wcf.Contracts.Constants.DbusServiceRelativeAddress, typeof(org.freedesktop.DBus.Properties.wcf.Contracts.IProperties)); //} CodeMemberMethod methodGetDbusServiceCreationParams = new CodeMemberMethod(); methodGetDbusServiceCreationParams.Name = GetDbusServiceCreationParams; methodGetDbusServiceCreationParams.Attributes = MemberAttributes.Static; methodGetDbusServiceCreationParams.ReturnType = CodeBuilderCommon.typerefDbusServiceCreationParams; methodGetDbusServiceCreationParams.Statements.Add(new CodeMethodReturnStatement(new CodeObjectCreateExpression( CodeBuilderCommon.typerefDbusServiceCreationParams // <wcf_contracts>.Constants.DbusServiceRelativeAddress , new CodeFieldReferenceExpression(typerefexprConstants, CodeBuilderCommon.nameRelativeAddress) // typeof(<contract>) , new CodeTypeOfExpression(typerefWCFContract) ))); CodeMemberMethod methodContainsService = new CodeMemberMethod(); methodContainsService.Name = ContainsService; methodContainsService.ReturnType = CodeBuilderCommon.typerefBool; CodeParameterDeclarationExpression paramdeclServiceTypes = new CodeParameterDeclarationExpression(typeof(Type[]), ServiceTypesArg); paramdeclServiceTypes.CustomAttributes.Add(CodeBuilderCommon.attribParams); methodContainsService.Parameters.Add(paramdeclServiceTypes); methodContainsService.Attributes = MemberAttributes.Public | MemberAttributes.Final; methodContainsService.Statements.Add(new CodeMethodReturnStatement( new CodeMethodInvokeExpression(new CodeArgumentReferenceExpression(ServiceTypesArg), "Contains", typeofWCFService ) )); // * public Udbus.WCF.Service.Host.ServiceHostCreationData MakeServiceHostCreationData(Udbus.WCF.Host.WCFServiceParams wcfserviceparams, params System.Uri[] uriBase) // * { // * Udbus.WCF.Service.Host.ServiceHostCreationData create = Udbus.WCF.Service.Host.DbusServiceHost.CreateWithData< <wcf_service>, Udbus.WCF.Host.WCFServiceParams>(wcfserviceparams, CreateServiceCreationData, uriBase); // * return create; // * } CodeMethodInvokeExpression invokeCreateWithData = new CodeMethodInvokeExpression(CodeBuilderCommon.typerefexprDbusServiceHost, CodeBuilderCommon.nameDbusServiceHostCreateWithDataMethod // wcfserviceparams , argrefWCFServiceParams // CreateServiceCreationData , new CodeMethodReferenceExpression(null, methodCreateServiceCreationData.Name) //, uriBase) , argrefUriBase ); invokeCreateWithData.Method.TypeArguments.Add(typerefWCFService); invokeCreateWithData.Method.TypeArguments.Add(CodeBuilderCommon.typerefWCFServiceParams); CodeMemberMethod methodMakeServiceCreationData = new CodeMemberMethod(); methodMakeServiceCreationData.Name = MakeServiceHostCreationData; methodMakeServiceCreationData.ReturnType = CodeBuilderCommon.typerefServiceHostCreationData; methodMakeServiceCreationData.Parameters.Add(new CodeParameterDeclarationExpression(CodeBuilderCommon.typerefWCFServiceParams, nameWCFServiceParamsArg)); CodeParameterDeclarationExpression paramdeclUriBase = new CodeParameterDeclarationExpression(typeof(System.Uri[]), nameUriBaseArg); paramdeclUriBase.CustomAttributes.Add(CodeBuilderCommon.attribParams); methodMakeServiceCreationData.Parameters.Add(paramdeclUriBase); methodMakeServiceCreationData.Attributes = MemberAttributes.Public | MemberAttributes.Final; methodMakeServiceCreationData.Statements.Add( new CodeVariableDeclarationStatement(CodeBuilderCommon.typerefServiceHostCreationData, "create", invokeCreateWithData ) ); methodMakeServiceCreationData.Statements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("create"))); CodeMemberMethod methodGetHostDbusServiceRegistrationParams = BuildGetDbusServiceRegistrationParamsMethod(GetHostDbusServiceRegistrationParams); methodGetHostDbusServiceRegistrationParams.Attributes = MemberAttributes.Public | MemberAttributes.Static; methodGetHostDbusServiceRegistrationParams.Statements.Add(new CodeMethodReturnStatement(new CodeObjectCreateExpression( CodeBuilderCommon.typerefRegistrationParams , invokeGetDbusServiceCreationParams , typeofWCFService ))); CodeMemberMethod methodGetDbusServiceRegistrationParams = BuildGetDbusServiceRegistrationParamsMethod("GetDbusServiceRegistrationParams"); methodGetDbusServiceRegistrationParams.Attributes = MemberAttributes.Public | MemberAttributes.Final; methodGetDbusServiceRegistrationParams.Statements.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression(null, GetHostDbusServiceRegistrationParams))); typeImpl.Members.Add(methodCreateService); typeImpl.Members.Add(methodCreateServiceCreationData); typeImpl.Members.Add(methodGetDbusServiceCreationParams); typeImpl.Members.Add(methodGetHostDbusServiceRegistrationParams); string regionIMakeServiceHostCreationData = string.Format("{0} functions", typeIMakeServiceHostCreationData.FullName); methodContainsService.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, regionIMakeServiceHostCreationData)); typeImpl.Members.Add(methodContainsService); typeImpl.Members.Add(methodGetDbusServiceRegistrationParams); typeImpl.Members.Add(methodMakeServiceCreationData); methodMakeServiceCreationData.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, regionIMakeServiceHostCreationData)); return(typeImpl); }
private void GenerateSignals(IDLInterface idlIntf, string nsName , CodeTypeReference typerefDbusInterface , CodeTypeReference typerefDbusMarshal , CodeTypeReference typerefWCFCallbackInterface , CodeTypeDeclaration typeProxy) { #region list of callbacks // Callbacks field. // * LinkedList<I<interface>Callback> callbacks = null; CodeTypeReference typerefCallbacksLinkedList = new CodeTypeReference(typeof(LinkedList <>)); typerefCallbacksLinkedList.TypeArguments.Add(typerefWCFCallbackInterface); CodeMemberField fieldCallbacks = new CodeMemberField(typerefCallbacksLinkedList, callbacks); fieldCallbacks.InitExpression = new CodePrimitiveExpression(null); typeProxy.Members.Add(fieldCallbacks); #endregion #region Method: OnCallBackClosing // Write: // private void OnCallbackClosing(object sender, System.EventArgs e) // { // RemoveCallback(sender, this.callbacks); // } CodeMemberMethod methodOnCallbackClosing = new CodeMemberMethod(); methodOnCallbackClosing.Attributes = MemberAttributes.Private; methodOnCallbackClosing.Name = "OnCallbackClosing"; CodeParameterDeclarationExpression paramdeclSender = new CodeParameterDeclarationExpression(typerefObject, "sender"); CodeArgumentReferenceExpression argrefSender = new CodeArgumentReferenceExpression(paramdeclSender.Name); CodeParameterDeclarationExpression paramdeclEventArgs = new CodeParameterDeclarationExpression(typeof(System.EventArgs), "e"); CodeArgumentReferenceExpression argrefEventArgs = new CodeArgumentReferenceExpression(paramdeclEventArgs.Name); methodOnCallbackClosing.Parameters.Add(paramdeclSender); methodOnCallbackClosing.Parameters.Add(paramdeclEventArgs); methodOnCallbackClosing.Statements.Add(new CodeExpressionStatement(new CodeMethodInvokeExpression(null, RemoveCallback, argrefSender, fieldrefCallbacks))); typeProxy.Members.Add(methodOnCallbackClosing); #endregion #region Method: AddCallBack // AddCallback(). // * private void AddCallback(I<interface>Callback callback) CodeParameterDeclarationExpression paramdeclCallback = new CodeParameterDeclarationExpression(typerefWCFCallbackInterface, CodeBuilderCommon.callback); CodeArgumentReferenceExpression argrefCallback = new CodeArgumentReferenceExpression(paramdeclCallback.Name); CodeMemberMethod methodAddCallback = new CodeMemberMethod(); methodAddCallback.Attributes = MemberAttributes.Private; methodAddCallback.Name = AddCallback; methodAddCallback.Parameters.Add(paramdeclCallback); CodeArrayCreateExpression arraycreatexprCallbacks = new CodeArrayCreateExpression(typerefWCFCallbackInterface); arraycreatexprCallbacks.Initializers.Add(argrefCallback); CodeVariableReferenceExpression varrefRegisterComms = new CodeVariableReferenceExpression("registerComms"); // * bool registerComms = true; methodAddCallback.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool) , varrefRegisterComms.VariableName , new CodePrimitiveExpression(true))); CodeTypeReference typerefCallbackEnumerator = new CodeTypeReference(typeof(System.Collections.Generic.IEnumerator <>)); typerefCallbackEnumerator.TypeArguments.Add(typerefWCFCallbackInterface); CodeVariableReferenceExpression varrefCallbackEnumerator = new CodeVariableReferenceExpression(callbackEnumerator); CodeVariableDeclarationStatement vardeclCallbackEnumerator = new CodeVariableDeclarationStatement(typerefCallbackEnumerator, varrefCallbackEnumerator.VariableName, new CodeMethodInvokeExpression(fieldrefCallbacks, "GetEnumerator")); CodePropertyReferenceExpression proprefCallbackEnumeratorCurrent = new CodePropertyReferenceExpression(varrefCallbackEnumerator, "Current"); CodeMethodInvokeExpression invokeCallbackEnumeratorMoveNext = new CodeMethodInvokeExpression(varrefCallbackEnumerator, "MoveNext"); CodeVariableDeclarationStatement vardeclCallbackEnumeratorMoveNext = new CodeVariableDeclarationStatement(typeof(bool), callbackEnumeratorMoveNext, invokeCallbackEnumeratorMoveNext); CodeVariableReferenceExpression varrefCallbackEnumeratorMoveNext = new CodeVariableReferenceExpression(vardeclCallbackEnumeratorMoveNext.Name); CodeAssignStatement assignCallbackEnumeratorMoveNext = new CodeAssignStatement(varrefCallbackEnumeratorMoveNext, invokeCallbackEnumeratorMoveNext); methodAddCallback.Statements.Add( // * if (this.callbacks == null) new CodeConditionStatement(new CodeBinaryOperatorExpression(fieldrefCallbacks , CodeBinaryOperatorType.IdentityEquality , new CodePrimitiveExpression(null)) , new CodeStatement[] { // * this.callbacks = new LinkedList<I<interface>Callback>(new I<interface>Callback[] { callback }); new CodeAssignStatement(fieldrefCallbacks , new CodeObjectCreateExpression(typerefCallbacksLinkedList , arraycreatexprCallbacks) ) } // * else , new CodeStatement[] { // * IEnumerator<[callback_interface]> callbacksEnumerator = this.callbacks.GetEnumerator(); vardeclCallbackEnumerator // * for (bool callbackEnumeratorMoveNext = callbackEnumerator.MoveNext(); callbackEnumeratorMoveNext; callbackEnumeratorMoveNext = callbackEnumerator.MoveNext()) // * { , new CodeIterationStatement(vardeclCallbackEnumeratorMoveNext , new CodeBinaryOperatorExpression(varrefCallbackEnumeratorMoveNext , CodeBinaryOperatorType.BooleanAnd , varrefRegisterComms) , assignCallbackEnumeratorMoveNext // * if (callbacksEnumerator.Current.Equals(callback)) // * { , new CodeConditionStatement(new CodeMethodInvokeExpression(proprefCallbackEnumeratorCurrent , "Equals" , argrefCallback) , new CodeStatement[] // True { // * registerComms = false; new CodeAssignStatement(varrefRegisterComms, new CodePrimitiveExpression(false)) } ) ) // * if (registerComms) , new CodeConditionStatement(varrefRegisterComms // * this.callbacks.AddLast(callback); , new CodeExpressionStatement(new CodeMethodInvokeExpression(fieldrefCallbacks , "AddLast" , argrefCallback)) ) } )); // * System.ServiceModel.ICommunicationObject commsCallback = callback as System.ServiceModel.ICommunicationObject; // * if (registerComms && (typeof(System.ServiceModel.ICommunicationObject).IsInstanceOfType(callback) != false)) // * { // * commsCallback.Closing += this.OnCallbackClosing; // * } CodeTypeReference typerefICommunicationObject = new CodeTypeReference(typeof(System.ServiceModel.ICommunicationObject)); CodeVariableDeclarationStatement vardeclCallbackAsComms = new CodeVariableDeclarationStatement(typerefICommunicationObject , "commsCallback" , new CodeCastExpression(typerefICommunicationObject, argrefCallback) ); CodeVariableReferenceExpression varrefCallbackAsComms = new CodeVariableReferenceExpression(vardeclCallbackAsComms.Name); methodAddCallback.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression( varrefRegisterComms , CodeBinaryOperatorType.BooleanAnd , new CodeBinaryOperatorExpression( new CodeMethodInvokeExpression(new CodeTypeOfExpression(typerefICommunicationObject), "IsInstanceOfType", argrefCallback) , CodeBinaryOperatorType.IdentityInequality , new CodePrimitiveExpression(false) ) ) , vardeclCallbackAsComms , new CodeAttachEventStatement(varrefCallbackAsComms, "Closing", new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), methodOnCallbackClosing.Name)) )); typeProxy.Members.Add(methodAddCallback); #endregion #region Method: RemoveCallBack // RemoveCallback(). /// * static private void RemoveCallback<T>(object callback, LinkedList<T> callbacks) /// * where T: class /// * { CodeMemberMethod methodRemoveCallback = new CodeMemberMethod(); methodRemoveCallback.Attributes = MemberAttributes.Static | MemberAttributes.Private; methodRemoveCallback.Name = RemoveCallback; CodeTypeParameter typeparamCallback = new CodeTypeParameter("TCallback"); CodeTypeReference typerefCallbackParam = new CodeTypeReference(typeparamCallback.Name); CodeParameterDeclarationExpression paramdeclRemoveCallback = new CodeParameterDeclarationExpression(typerefObject, CodeBuilderCommon.callback); CodeTypeReference typerefLinkedListRemoveCallback = new CodeTypeReference(typeof(System.Collections.Generic.LinkedList <>)); typerefLinkedListRemoveCallback.TypeArguments.Add(typerefCallbackParam); CodeTypeReference typerefLinkedListNodeRemoveCallback = new CodeTypeReference(typeof(System.Collections.Generic.LinkedListNode <>)); typerefLinkedListNodeRemoveCallback.TypeArguments.Add(typerefCallbackParam); CodeParameterDeclarationExpression paramdeclRemoveCallbacks = new CodeParameterDeclarationExpression(typerefLinkedListRemoveCallback, callbacks); CodeArgumentReferenceExpression argrefCallbacks = new CodeArgumentReferenceExpression(paramdeclRemoveCallbacks.Name); typeparamCallback.Constraints.Add(new CodeTypeReference(" class")); // Space before "class" bloody important, stupid CodeDOM and CSharp. methodRemoveCallback.TypeParameters.Add(typeparamCallback); methodRemoveCallback.Parameters.Add(paramdeclRemoveCallback); methodRemoveCallback.Parameters.Add(paramdeclRemoveCallbacks); CodeVariableDeclarationStatement vardeclIteratorNode = new CodeVariableDeclarationStatement( typerefLinkedListNodeRemoveCallback, "iteratorNode" , new CodePropertyReferenceExpression(argrefCallbacks, "First") ); CodeVariableReferenceExpression varrefIteratorNode = new CodeVariableReferenceExpression(vardeclIteratorNode.Name); CodeVariableDeclarationStatement vardeclRemoveNode = new CodeVariableDeclarationStatement( typerefLinkedListNodeRemoveCallback, "removeNode" , varrefIteratorNode ); CodeVariableReferenceExpression varrefRemoveNode = new CodeVariableReferenceExpression(vardeclRemoveNode.Name); CodeAssignStatement assignIteratorNode = new CodeAssignStatement(varrefIteratorNode, new CodePropertyReferenceExpression(varrefIteratorNode, "Next")); // * for (LinkedListNode<string> n = l.First; n != null; ) // * { methodRemoveCallback.Statements.Add(new CodeIterationStatement(vardeclIteratorNode , new CodeBinaryOperatorExpression(varrefIteratorNode , CodeBinaryOperatorType.IdentityInequality , new CodePrimitiveExpression(null)) , new CodeSnippetStatement(string.Empty) // Don't increment // * if (iteratorNode.Value == callback) // * { , new CodeConditionStatement( new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(varrefIteratorNode, "Value") , CodeBinaryOperatorType.IdentityEquality , argrefCallback) , new CodeStatement[] // True { // * LinkedListNode<string> removeNode = iteratorNode; vardeclRemoveNode // * iteratorNode = iteratorNode.Next; , assignIteratorNode // * l.Remove(removeNode); , new CodeExpressionStatement(new CodeMethodInvokeExpression(argrefCallbacks, "Remove", varrefRemoveNode)) // * } } // * else // * { , new CodeStatement[] // False { // * iteratorNode = iteratorNode.Next; assignIteratorNode // * } } // * } // * } ))); typeProxy.Members.Add(methodRemoveCallback); #endregion foreach (IDLSignal idlSignal in idlIntf.Signals) { #region Write method which will call every registered // Add private event handler function which delegates to callback interfaces. // * private void On<signal>(object sender, <signal_interface_ns>.<signal>Args e) string signalArgsName = CodeBuilderCommon.GetSignalEventTypeName(idlSignal.Name); string scopedSignalArgsName = CodeBuilderCommon.GetScopedName(nsName, signalArgsName); string signalEventMethodName = CodeBuilderCommon.GetSignalCallbackMethodName(idlSignal.Name); CodeTypeReference typerefSignalEventArgs = new CodeTypeReference(scopedSignalArgsName); CodeParameterDeclarationExpression paramdeclSignalEventArgs = new CodeParameterDeclarationExpression(typerefSignalEventArgs, eventArgsParamName); CodeArgumentReferenceExpression argrefSignalEventArgs = new CodeArgumentReferenceExpression(paramdeclSignalEventArgs.Name); CodeMemberMethod methodOnSignal = new CodeMemberMethod(); methodOnSignal.Attributes = MemberAttributes.Private; methodOnSignal.Name = signalEventMethodName; methodOnSignal.Parameters.Add(paramdeclSender); methodOnSignal.Parameters.Add(paramdeclSignalEventArgs); methodOnSignal.Statements.Add(new CodeConditionStatement( // * if (this.callbacks != null) new CodeBinaryOperatorExpression(fieldrefCallbacks, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)) // * IEnumerator< <interface>Callback > callbackEnumerator = this.callbacks.GetEnumerator(); , vardeclCallbackEnumerator // * for (bool callbackEnumeratorMoveNext = callbackEnumerator.MoveNext(); callbackEnumeratorMoveNext; callbackEnumeratorMoveNext = callbackEnumerator.MoveNext()) , new CodeIterationStatement(vardeclCallbackEnumeratorMoveNext, varrefCallbackEnumeratorMoveNext, assignCallbackEnumeratorMoveNext , new CodeExpressionStatement(new CodeMethodInvokeExpression(proprefCallbackEnumeratorCurrent, signalEventMethodName, argrefSignalEventArgs)) //// * callbackEnumerator.Current.On<signal>(e); //, new CodeExpressionStatement(new CodeMethodInvokeExpression(arrayindexCallbacks, signalEventMethodName, argrefSignalEventArgs)) ))); typeProxy.Members.Add(methodOnSignal); #endregion #region Write method to register for a signal // * public void RegisterFor<signal>() CodeMethodReferenceExpression methodrefGetCallbackChannel = new CodeMethodReferenceExpression(proprefOperationContextCurrent, "GetCallbackChannel", typerefWCFCallbackInterface); CodeMethodReferenceExpression methodrefOnSignal = new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), methodOnSignal.Name); CodeMemberMethod methodRegisterForSignal = new CodeMemberMethod(); methodRegisterForSignal.Attributes = MemberAttributes.Public; methodRegisterForSignal.Name = CodeBuilderCommon.GetSignalRegisterFunction(idlSignal.Name); // * <interface> target = this.GetWCFMethodTarget(); methodRegisterForSignal.Statements.Add(this.DeclareTargetVariable(typerefDbusInterface, typerefDbusMarshal)); // * AddCallback(System.ServiceModel.OperationContext.Current.GetCallbackChannel<I<interface>Callback>()); methodRegisterForSignal.Statements.Add(new CodeExpressionStatement(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), methodAddCallback.Name , new CodeMethodInvokeExpression(methodrefGetCallbackChannel)) )); CodePropertyReferenceExpression proprefDbusServiceSignal = new CodePropertyReferenceExpression(fieldrefDbusServices, CodeBuilderCommon.GetSignalEventPropertyName(idlSignal.Name)); CodeAttachEventStatement attacheventSignal = new CodeAttachEventStatement(new CodeEventReferenceExpression(varrefTarget, CodeBuilderCommon.GetSignalEventPropertyName(idlSignal.Name)), methodrefOnSignal); methodRegisterForSignal.Statements.Add(attacheventSignal); typeProxy.Members.Add(methodRegisterForSignal); #endregion } // Ends loop over signals }
override protected void PostHandleInterface(IDLInterface idlIntf, CodeCompileUnit unit, CodeNamespace ns, CodeTypeDeclaration typeInterface) { if (idlIntf.Signals == null || idlIntf.Signals.Count == 0) // If no signals { typeInterface.CustomAttributes.Add(CodeBuilderCommon.attribServiceContract); } // Ends if no signals // Add DbusServiceRelativeAddress constant to Constants class. // * public partial class Constants { CodeTypeDeclaration typedeclConstants = new CodeTypeDeclaration(CodeBuilderCommon.nameConstantsClass); typedeclConstants.Attributes = MemberAttributes.Public | MemberAttributes.Static; typedeclConstants.IsPartial = true; // * public const string DbusServiceRelativeAddress = "<contract_name>"; // * } CodeMemberField fieldRelativeAddress = new CodeMemberField(typeof(string), CodeBuilderCommon.nameRelativeAddress); fieldRelativeAddress.Attributes = MemberAttributes.Const | MemberAttributes.Public; fieldRelativeAddress.InitExpression = new CodePrimitiveExpression(idlIntf.Name.Replace('.', '/')); typedeclConstants.Members.Add(fieldRelativeAddress); ns.Types.Add(typedeclConstants); CodeTypeReference typerefInterface = new CodeTypeReference(CodeBuilderCommon.GetScopedName(ns.Name, typeInterface.Name)); CodeTypeReference typerefInterfaceProxy = new CodeTypeReference(typeof(Udbus.WCF.Client.Proxy <>)); typerefInterfaceProxy.TypeArguments.Add(typerefInterface); CodeTypeReference typerefProxy; // Worked out in following code... if (this.typedeclProxy == null) // If no proxy type defined yet { // Just knock up a nice vanilla one for consistency's sake. string nsWCFName, intfWCF; nsWCFName = CodeBuilderCommon.GetNamespace(idlIntf.Name, this.visitorType); intfWCF = CodeBuilderCommon.GetName(idlIntf.Name, null); CodeTypeDeclaration typedeclProxy = new CodeTypeDeclaration(CodeBuilderCommon.GetSignalProxyName(intfWCF)); typedeclProxy.BaseTypes.Add(typerefInterfaceProxy); AddProxyConstructors(typedeclProxy); CodeNamespace nsClient = this.GetClientNamespace(unit, idlIntf.Name); nsClient.Types.Add(typedeclProxy); typerefProxy = new CodeTypeReference(CodeBuilderCommon.GetScopedName(nsClient.Name, typedeclProxy.Name)); } // Ends if no proxy type defined yet else // Else added proxy type { // Grab holder of scoped type reference. string nsWCFClient = CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFClientVisitor()); typerefProxy = new CodeTypeReference(CodeBuilderCommon.GetScopedName(nsWCFClient, this.typedeclProxy.Name)); } // Ends else added proxy type // Reset helper types for next time. this.typedeclCallbackInterface = null; this.typedeclCallbackClient = null; this.typedeclProxy = null; // Add Proxy creation function to ProxyBuilder class via extension method. CodeTypeReference typerefEndpointComponents = new CodeTypeReference(typeof(Udbus.WCF.Client.DbusEndpointUriComponents)); CodeTypeReferenceExpression typerefexprEndpointComponents = new CodeTypeReferenceExpression(typerefEndpointComponents); CodeTypeReference typerefProxyManager = new CodeTypeReference(typeof(Udbus.WCF.Client.ProxyManager)); CodeTypeReferenceExpression typerefexprProxyManager = new CodeTypeReferenceExpression(typerefProxyManager); CodeTypeReference typerefProxyBuilder = new CodeTypeReference(typeof(Udbus.WCF.Client.ProxyBuilder)); CodeTypeReference typerefProxyBuilderExtension = new CodeTypeReference("this " + typerefProxyBuilder.BaseType); // No CodeDom support for extension methods. Awesome. CodeTypeReferenceExpression typerefexprProxyBuilder = new CodeTypeReferenceExpression(typerefProxyBuilder); CodeTypeReferenceExpression typerefexprConstants = new CodeTypeReferenceExpression(CodeBuilderCommon.GetScopedName(ns.Name, typedeclConstants.Name)); CodeParameterDeclarationExpression paramdeclInterfaceProxy = new CodeParameterDeclarationExpression(typerefInterfaceProxy, proxy); CodeParameterDeclarationExpression paramdeclProxyManagerExtension = new CodeParameterDeclarationExpression(typerefProxyBuilderExtension, proxyBuilder); CodeParameterDeclarationExpression paramdeclEndpointUri = new CodeParameterDeclarationExpression(typerefEndpointComponents, dbusEndpointUri); CodeArgumentReferenceExpression argrefProxy = new CodeArgumentReferenceExpression(proxy); CodeArgumentReferenceExpression argrefEndpointUri = new CodeArgumentReferenceExpression(paramdeclEndpointUri.Name); CodeExpression exprRelativeAddress = new CodeFieldReferenceExpression(typerefexprConstants, fieldRelativeAddress.Name); CodeArgumentReferenceExpression argrefProxyBuilder = new CodeArgumentReferenceExpression(proxyBuilder); CodePropertyReferenceExpression proprefBindingFactory = new CodePropertyReferenceExpression(argrefProxyBuilder, BindingFactory); // * static public partial class ProxyBuilderExtensions // * { CodeTypeDeclaration typedeclProxyBuilderExtensions = new CodeTypeDeclaration(CodeBuilderCommon.nameProxyBuilderExtensionsClass); typedeclProxyBuilderExtensions.Attributes = MemberAttributes.Public | MemberAttributes.Static; typedeclProxyBuilderExtensions.IsPartial = true; // http://stackoverflow.com/questions/6308310/creating-extension-method-using-codedom typedeclProxyBuilderExtensions.Attributes = MemberAttributes.Public; typedeclProxyBuilderExtensions.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, Environment.NewLine + "\tstatic")); typedeclProxyBuilderExtensions.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty)); // * static public void Create(this Udbus.WCF.Client.ProxyBuilder proxyBuilder, out Udbus.WCF.Client.Proxy< <wcf_contract> > proxy // * , Udbus.WCF.Client.DbusEndpointUriComponents dbusEndpointUri) // * { // * proxy = Udbus.WCF.Client.ProxyManager.Create< <wcf_contract> >( // * dbusEndpointUri.CreateUri(<wcf_namespace>.wcf.Contracts.Constants.DbusServiceRelativeAddress) // * , proxyBuilder.BindingFactory // * ); // * } CodeMemberMethod methodCreateInterfaceProxyWithEndpoint = new CodeMemberMethod(); methodCreateInterfaceProxyWithEndpoint.Name = "Create"; methodCreateInterfaceProxyWithEndpoint.Attributes = MemberAttributes.Static | MemberAttributes.Public; paramdeclInterfaceProxy.Direction = FieldDirection.Out; methodCreateInterfaceProxyWithEndpoint.Parameters.Add(paramdeclProxyManagerExtension); methodCreateInterfaceProxyWithEndpoint.Parameters.Add(paramdeclInterfaceProxy); methodCreateInterfaceProxyWithEndpoint.Parameters.Add(paramdeclEndpointUri); // * dbusEndpointUri.CreateUri(<ns>.wcf.Contracts.Constants.DbusServiceRelativeAddress) CodeMethodInvokeExpression invokeCreateUri = new CodeMethodInvokeExpression(argrefEndpointUri, CreateUri, exprRelativeAddress); CodeMethodInvokeExpression invokeProxyManagerCreate = new CodeMethodInvokeExpression(typerefexprProxyManager, "Create", invokeCreateUri, proprefBindingFactory); invokeProxyManagerCreate.Method.TypeArguments.Add(typerefInterface); methodCreateInterfaceProxyWithEndpoint.Statements.Add( new CodeAssignStatement( argrefProxy , invokeProxyManagerCreate ) ); typedeclProxyBuilderExtensions.Members.Add(methodCreateInterfaceProxyWithEndpoint); // * static public void Create(this Udbus.WCF.Client.ProxyBuilder proxyBuilder, out Udbus.WCF.Client.Proxy< <wcf_contract> > proxy) // * { // * proxyBuilder.Create(out proxy, Udbus.WCF.Client.DbusEndpointUriComponents.Create(proxyBuilder.AbsoluteUribuilder)); // * } CodeMemberMethod methodCreateInterfaceProxy = new CodeMemberMethod(); methodCreateInterfaceProxy.Name = "Create"; methodCreateInterfaceProxy.Attributes = MemberAttributes.Static | MemberAttributes.Public; methodCreateInterfaceProxy.Parameters.Add(paramdeclProxyManagerExtension); methodCreateInterfaceProxy.Parameters.Add(paramdeclInterfaceProxy); CodeMethodInvokeExpression invokeProxyManagerExtensionCreate = new CodeMethodInvokeExpression( argrefProxyBuilder , "Create" , new CodeDirectionExpression(FieldDirection.Out, argrefProxy) , new CodeMethodInvokeExpression( typerefexprEndpointComponents , "Create" , new CodePropertyReferenceExpression(argrefProxyBuilder, AbsoluteUribuilder) ) ); methodCreateInterfaceProxy.Statements.Add(invokeProxyManagerExtensionCreate); typedeclProxyBuilderExtensions.Members.Add(methodCreateInterfaceProxy); CodeParameterDeclarationExpression paramdeclProxy = new CodeParameterDeclarationExpression(typerefProxy, proxy); paramdeclProxy.Direction = FieldDirection.Out; // * public static void Create(this Udbus.WCF.Client.ProxyBuilder proxyBuilder, out <namespace>.Contracts.Clients.<interface>Proxy proxy, Udbus.WCF.Client.DbusEndpointUriComponents dbusEndpointUri) // * { // * proxy = new <wcf_namespace>.Contracts.Clients.<interface>Proxy(proxyBuilder.BindingFactory, dbusEndpointUri.CreateUri(<namespace>.wcf.Contracts.Constants.DbusServiceRelativeAddress)); // * } CodeMemberMethod methodCreateProxyWithEndpoint = new CodeMemberMethod(); methodCreateProxyWithEndpoint.Name = "Create"; methodCreateProxyWithEndpoint.Attributes = MemberAttributes.Static | MemberAttributes.Public; methodCreateProxyWithEndpoint.Parameters.Add(paramdeclProxyManagerExtension); methodCreateProxyWithEndpoint.Parameters.Add(paramdeclProxy); methodCreateProxyWithEndpoint.Parameters.Add(paramdeclEndpointUri); methodCreateProxyWithEndpoint.Statements.Add(new CodeAssignStatement( argrefProxy , new CodeObjectCreateExpression(typerefProxy , proprefBindingFactory , invokeCreateUri ) )); typedeclProxyBuilderExtensions.Members.Add(methodCreateProxyWithEndpoint); // * public static void Create(this Udbus.WCF.Client.ProxyBuilder proxyBuilder, out <namespace>.Contracts.Clients.<interface>Proxy proxy) // * { // * proxyBuilder.Create(out proxy, Udbus.WCF.Client.DbusEndpointUriComponents.Create(proxyBuilder.AbsoluteUribuilder)); // * } CodeMemberMethod methodCreateProxy = new CodeMemberMethod(); methodCreateProxy.Name = "Create"; methodCreateProxy.Attributes = MemberAttributes.Static | MemberAttributes.Public; methodCreateProxy.Parameters.Add(paramdeclProxyManagerExtension); methodCreateProxy.Parameters.Add(paramdeclProxy); methodCreateProxy.Statements.Add(invokeProxyManagerExtensionCreate); typedeclProxyBuilderExtensions.Members.Add(methodCreateProxy); CodeNamespace nsClientExtensions = new CodeNamespace(CodeBuilderCommon.nsClientExtensions); nsClientExtensions.Types.Add(typedeclProxyBuilderExtensions); unit.Namespaces.Add(nsClientExtensions); // * } }
override protected void PostHandleSignal(IDLInterface idlIntf, IDLSignal idlSignal, CodeCompileUnit unit, CodeNamespace ns, CodeTypeDeclaration typeInterface) { string nsName, intf; int lastDot = idlIntf.Name.LastIndexOf('.'); intf = idlIntf.Name.Substring(lastDot + 1); nsName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new InterfaceVisitor()); CodeFieldReferenceExpression fieldrefCallback = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CodeBuilderCommon.callback); CodeFieldReferenceExpression fieldrefTarget = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CodeBuilderCommon.targetName); CodeNamespace nsClient = this.GetClientNamespace(unit, idlIntf.Name); CodeNamespace nsClientTypes = nsClient; if (this.typedeclCallbackInterface == null) // If no callback interface yet { CodeTypeReference typerefInterface = new CodeTypeReference(typeInterface.Name); // Declare callback interface and hold onto it in field. // * public interface I<interface>Callback // * { string nsWCFName, intfWCF; nsWCFName = CodeBuilderCommon.GetNamespace(idlIntf.Name, this.visitorType); intfWCF = CodeBuilderCommon.GetName(idlIntf.Name, null); string callbackInterfaceName = CodeBuilderCommon.GetSignalCallbackInterfaceName(intfWCF); typedeclCallbackInterface = new CodeTypeDeclaration(callbackInterfaceName); typedeclCallbackInterface.Attributes = MemberAttributes.Public; typedeclCallbackInterface.IsInterface = true; ns.Types.Add(typedeclCallbackInterface); // * class <interface>CallbackClient : I<interface>Callback string wcfCallbackClientName = CodeBuilderCommon.GetSignalCompilableName(intfWCF) + "CallbackClient"; CodeTypeReference typerefCallbackInterface = new CodeTypeReference(typedeclCallbackInterface.Name); CodeAttributeDeclaration attribdeclServiceContract = new CodeAttributeDeclaration(CodeBuilderCommon.typerefServiceContract, new CodeAttributeArgument("CallbackContract", new CodeTypeOfExpression(typerefCallbackInterface)) ); typeInterface.CustomAttributes.Add(attribdeclServiceContract); //string scopedCallbackInterfaceName = CodeBuilderCommon.GetScopedName(nsWCFName, proxyInterfaceName); //typedeclCallbackClient = new CodeTypeDeclaration(CodeBuilderCommon.GetSignalCallbackName(intf)); typedeclCallbackClient = new CodeTypeDeclaration(wcfCallbackClientName); CodeTypeReference typerefWCFCallbackInterface = new CodeTypeReference(typedeclCallbackInterface.Name); typedeclCallbackClient.BaseTypes.Add(typerefWCFCallbackInterface); nsClientTypes.Types.Add(typedeclCallbackClient); // * public class <interface>Proxy : Udbus.WCF.Client.CallbackProxy< <wcf_contracts.interface>, <interface>CallbackClient > this.typedeclProxy = new CodeTypeDeclaration(CodeBuilderCommon.GetSignalProxyName(intfWCF)); CodeTypeReference typerefCallbackProxy = new CodeTypeReference(typeof(Udbus.WCF.Client.CallbackProxy <,>)); CodeTypeReference typerefCallbackClient = new CodeTypeReference(typedeclCallbackClient.Name); typerefCallbackProxy.TypeArguments.Add(typerefInterface); typerefCallbackProxy.TypeArguments.Add(typerefCallbackClient); this.typedeclProxy.BaseTypes.Add(typerefCallbackProxy); AddProxyConstructors(this.typedeclProxy); nsClientTypes.Types.Add(this.typedeclProxy); } // Ends if no callback interface yet // Add signal property to Proxy. CodeMemberProperty propProxySignal = CodeBuilderCommon.CreateSignalEventProperty(idlSignal); propProxySignal.Attributes = MemberAttributes.Public | MemberAttributes.Final; CodePropertyReferenceExpression proprefProxyInterface = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "ProxyInterface"); CodePropertyReferenceExpression proprefProxyCallback = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Callback"); CodePropertyReferenceExpression proprefProxyCallbackEvent = new CodePropertyReferenceExpression(proprefProxyCallback, propProxySignal.Name); propProxySignal.GetStatements.Add(new CodeMethodReturnStatement(proprefProxyCallbackEvent)); propProxySignal.SetStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(proprefProxyCallbackEvent, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null)) , new CodeExpressionStatement(new CodeMethodInvokeExpression(proprefProxyInterface, CodeBuilderCommon.GetSignalRegisterFunction(idlSignal.Name))) )); propProxySignal.SetStatements.Add(new CodeAssignStatement(proprefProxyCallbackEvent, new CodePropertySetValueReferenceExpression())); this.typedeclProxy.Members.Add(propProxySignal); // Add callback method to callback interface. // * [System.ServiceModel.OperationContract(IsOneWay=true)] // * void On<signal>(<interface_ns>.<signal>Args args); CodeMemberMethod methodOnSignal = new CodeMemberMethod(); methodOnSignal.Name = CodeBuilderCommon.GetSignalCallbackMethodName(idlSignal.Name); string signalArgsTypeName = CodeBuilderCommon.GetSignalEventTypeName(idlSignal.Name); string scopedSignalArgsTypeName = CodeBuilderCommon.GetScopedName(nsName, signalArgsTypeName); CodeParameterDeclarationExpression paramdeclSignalArgs = new CodeParameterDeclarationExpression(scopedSignalArgsTypeName, CodeBuilderCommon.SignalArgsName); methodOnSignal.Parameters.Add(paramdeclSignalArgs); methodOnSignal.CustomAttributes.Add(CodeBuilderCommon.attribOperationContractOneWay); typedeclCallbackInterface.Members.Add(methodOnSignal); // Add registration method to wcf interface. // * [System.ServiceModel.OperationContract] // * void RegisterForStorageSpaceLow(); CodeMemberMethod methodRegister = new CodeMemberMethod(); methodRegister.Name = CodeBuilderCommon.GetSignalRegisterFunction(idlSignal.Name); methodRegister.CustomAttributes.Add(CodeBuilderCommon.attribOperationContract); typeInterface.Members.Add(methodRegister); // Add event to callback client implementation. // * private event System.EventHandler< <signal>Args > <signal>Event; CodeMemberEvent eventSignal = CodeBuilderCommon.CreateSignalEvent(idlSignal); typedeclCallbackClient.Members.Add(eventSignal); // * public virtual System.EventHandler< <signal>Args > <signal> // * { // * get { return this.<signal>Event; } // * set { this.<signal>Event = value; } // * } CodeMemberProperty propSignal = CodeBuilderCommon.CreateSignalEventProperty(idlSignal); propSignal.Attributes = MemberAttributes.Public | MemberAttributes.Final; CodeEventReferenceExpression eventrefSignal = new CodeEventReferenceExpression(new CodeThisReferenceExpression(), eventSignal.Name); propSignal.GetStatements.Add(new CodeMethodReturnStatement(eventrefSignal)); propSignal.SetStatements.Add(new CodeAssignStatement(eventrefSignal, new CodePropertySetValueReferenceExpression())); typedeclCallbackClient.Members.Add(propSignal); // * public void On<signal>(<ns>.<signal>Args args) // * { // * if (this.<signal> != null) // * { // * this.<signal>(this, args); // * } //} CodeMemberMethod methodSignal = new CodeMemberMethod(); methodSignal.Name = CodeBuilderCommon.GetSignalCallbackMethodName(idlSignal.Name); methodSignal.Attributes = MemberAttributes.Public; methodSignal.Parameters.Add(paramdeclSignalArgs); CodePropertyReferenceExpression proprefSignal = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), propSignal.Name); methodSignal.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(eventrefSignal, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null)) , new CodeExpressionStatement(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), eventrefSignal.EventName, new CodeThisReferenceExpression(), new CodeArgumentReferenceExpression(paramdeclSignalArgs.Name))) )); typedeclCallbackClient.Members.Add(methodSignal); }
private string getParamScopedNameImpl(string name) { return(CodeBuilderCommon.GetScopedName(CodeBuilderCommon.GetParamsNamespaceName(this.intf.Name), name)); }
private string getScopedNameImpl(string name) { return(CodeBuilderCommon.GetScopedName(this.intf.Name, name)); }