/// <summary> /// Gets the feature output format. /// </summary> /// <param name="selectedOverloadType">The selected overload type.</param> /// <param name="outgoingParameterCount">The number of 'out' parameters upon return.</param> /// <param name="returnValueIndex">Index of the return value if the feature returns a value, -1 otherwise.</param> public override void GetOutputFormat(ICSharpQueryOverloadType selectedOverloadType, out int outgoingParameterCount, out int returnValueIndex) { Debug.Assert(selectedOverloadType == null); outgoingParameterCount = 0; returnValueIndex = -1; }
/// <summary> /// Initializes a new instance of the <see cref="CSharpFunctionType"/> class. /// </summary> /// <param name="context">The creation context.</param> /// <param name="source">The Easly type from which the C# type is created.</param> /// <param name="originatingTypedef">The typedef where this type is declared.</param> protected CSharpFunctionType(ICSharpContext context, IFunctionType source, ICSharpTypedef originatingTypedef) : base(context, source, originatingTypedef) { Debug.Assert(source.OverloadList.Count > 0); ICSharpClass Owner = context.GetClass(source.EmbeddingClass); BaseType = Create(context, source.ResolvedBaseType.Item) as ICSharpTypeWithFeature; Debug.Assert(BaseType != null); foreach (IQueryOverloadType OverloadType in source.OverloadList) { ICSharpQueryOverloadType NewOverloadType = CSharpQueryOverloadType.Create(context, OverloadType, Owner); OverloadTypeList.Add(NewOverloadType); } }
/// <summary> /// Gets the feature output format. /// </summary> /// <param name="selectedOverloadType">The selected overload type.</param> /// <param name="outgoingParameterCount">The number of 'out' parameters upon return.</param> /// <param name="returnValueIndex">Index of the return value if the feature returns a value, -1 otherwise.</param> public abstract void GetOutputFormat(ICSharpQueryOverloadType selectedOverloadType, out int outgoingParameterCount, out int returnValueIndex);
/// <summary> /// Get the name of a type. /// </summary> /// <param name="usingCollection">The collection of using directives.</param> /// <param name="cSharpTypeFormat">The type format.</param> /// <param name="cSharpNamespaceFormat">The namespace format.</param> public override string Type2CSharpString(ICSharpUsingCollection usingCollection, CSharpTypeFormats cSharpTypeFormat, CSharpNamespaceFormats cSharpNamespaceFormat) { SetUsedInCode(); string Result; if (OriginatingTypedef != null) { // TODO: detect delegate call parameters to select the proper overload string DelegateName = CSharpNames.ToCSharpIdentifier(OriginatingTypedef.Name); Result = QueryOverloadType2CSharpString(DelegateName, Source.OverloadList[0]); } else { ICSharpQueryOverloadType OverloadType = OverloadTypeList[0]; string ActionArgumentText = BaseType.Type2CSharpString(usingCollection, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None); foreach (ICSharpParameter Parameter in OverloadType.ParameterList) { ICSharpType ParameterType = Parameter.Feature.Type; CSharpTypeFormats ParameterFormat = ParameterType.HasInterfaceText ? CSharpTypeFormats.AsInterface : CSharpTypeFormats.Normal; string ParameterText = ParameterType.Type2CSharpString(usingCollection, ParameterFormat, CSharpNamespaceFormats.None); ActionArgumentText += $", {ParameterText}"; } Debug.Assert(OverloadType.ResultList.Count >= 1); if (OverloadType.ResultList.Count == 1) { ICSharpParameter Parameter = OverloadType.ResultList[0]; ICSharpType ResultType = Parameter.Feature.Type; CSharpTypeFormats ResultFormat = ResultType.HasInterfaceText ? CSharpTypeFormats.AsInterface : CSharpTypeFormats.Normal; string ResultText = ResultType.Type2CSharpString(usingCollection, ResultFormat, CSharpNamespaceFormats.None); ActionArgumentText += $", {ResultText}"; } else { string FuncResultText = string.Empty; foreach (ICSharpParameter Parameter in OverloadType.ResultList) { if (FuncResultText.Length > 0) { FuncResultText += ", "; } ICSharpType ResultType = Parameter.Feature.Type; CSharpTypeFormats ResultFormat = ResultType.HasInterfaceText ? CSharpTypeFormats.AsInterface : CSharpTypeFormats.Normal; string ResultText = ResultType.Type2CSharpString(usingCollection, ResultFormat, CSharpNamespaceFormats.None); FuncResultText += $", {ResultText}"; } ActionArgumentText += $", Tuple<{FuncResultText}>"; } Result = $"Func<{ActionArgumentText}>"; usingCollection.AddUsing(nameof(System)); } return(Result); }