/// <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
                string DelegateName = CSharpNames.ToCSharpIdentifier(OriginatingTypedef.Name);

                Result = PropertyType2CSharpString(DelegateName);
            }
            else
            {
                string BaseTypeText   = BaseType.Type2CSharpString(usingCollection, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);
                string EntityTypeText = EntityType.Type2CSharpString(usingCollection, CSharpTypeFormats.AsInterface, CSharpNamespaceFormats.None);

                Result = $"Func<{BaseTypeText}, {EntityTypeText}>";

                usingCollection.AddUsing(nameof(System));
            }

            return(Result);
        }
Exemple #2
0
        /// <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;

            // TODO: detect delegate call parameters to select the proper overload

            if (OriginatingTypedef != null)
            {
                string DelegateName = CSharpNames.ToCSharpIdentifier(OriginatingTypedef.Name);

                Result = CommandOverloadType2CSharpString(DelegateName, Source.OverloadList[0]);
            }
            else
            {
                ICSharpCommandOverloadType 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}";
                }

                Result = $"Action<{ActionArgumentText}>";

                usingCollection.AddUsing(nameof(System));
            }

            return(Result);
        }
Exemple #3
0
        /// <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();

            Debug.Assert(Class != null);
            Debug.Assert(Class.Source != null);

            Guid   BaseClassGuid = Class.Source.ClassGuid;
            bool   AsInterface   = cSharpTypeFormat == CSharpTypeFormats.AsInterface;
            bool   TypeArgumentsWithInterface      = true;
            bool   TypeArgumentsWithImplementation = false;
            string Result = null;

            if (BaseClassGuid == LanguageClasses.BitFieldEnumeration.Guid)
            {
                Result = CSharpNames.ToCSharpIdentifier(Class.ValidClassName);
            }
            else if (BaseClassGuid == LanguageClasses.DetachableReference.Guid)
            {
                Result = "DetachableReference" + TypeArguments2CSharpName(usingCollection, TypeArgumentList, TypeArgumentsWithInterface, TypeArgumentsWithImplementation);
            }
            else if (BaseClassGuid == LanguageClasses.Hashtable.Guid)
            {
                Result = "Hashtable" + TypeArguments2CSharpName(usingCollection, TypeArgumentList, TypeArgumentsWithInterface, TypeArgumentsWithImplementation);
            }
            else if (BaseClassGuid == LanguageClasses.KeyValuePair.Guid)
            {
                Result = "KeyValuePair" + TypeArguments2CSharpName(usingCollection, TypeArgumentList, TypeArgumentsWithInterface, TypeArgumentsWithImplementation);
            }
            else if (BaseClassGuid == LanguageClasses.List.Guid)
            {
                string ClassName;

                if (AsInterface)
                {
                    ClassName = "IList";
                }
                else
                {
                    ClassName = "List";
                }

                Result = ClassName + TypeArguments2CSharpName(usingCollection, TypeArgumentList, TypeArgumentsWithInterface, TypeArgumentsWithImplementation);

                usingCollection.AddUsing("System.Collections.Generic");
            }
            else if (BaseClassGuid == LanguageClasses.OnceReference.Guid)
            {
                Result = "OnceReference" + TypeArguments2CSharpName(usingCollection, TypeArgumentList, TypeArgumentsWithInterface, TypeArgumentsWithImplementation);
            }
            else if (BaseClassGuid == LanguageClasses.OptionalReference.Guid)
            {
                Result = "OptionalReference" + TypeArguments2CSharpName(usingCollection, TypeArgumentList, TypeArgumentsWithInterface, TypeArgumentsWithImplementation);
            }
            else if (BaseClassGuid == LanguageClasses.OverLoopSource.Guid)
            {
                Result = "Enumerable" + TypeArguments2CSharpName(usingCollection, TypeArgumentList, TypeArgumentsWithInterface, TypeArgumentsWithImplementation);
            }
            else if (BaseClassGuid == LanguageClasses.SealableHashtable.Guid)
            {
                Result = "Hashtable" + TypeArguments2CSharpName(usingCollection, TypeArgumentList, TypeArgumentsWithInterface, TypeArgumentsWithImplementation);
            }
            else if (BaseClassGuid == LanguageClasses.SpecializedTypeEntity.Guid)
            {
                Result = "SpecializedTypeEntity" + TypeArguments2CSharpName(usingCollection, TypeArgumentList, false, true);
            }
            else if (BaseClassGuid == LanguageClasses.StableReference.Guid)
            {
                Result = "StableReference" + TypeArguments2CSharpName(usingCollection, TypeArgumentList, TypeArgumentsWithInterface, TypeArgumentsWithImplementation);
            }
            else if (LanguageClasses.GuidToName.ContainsKey(BaseClassGuid))
            {
                Result = null;

                if (BaseClassGuid == LanguageClasses.Number.Guid)
                {
                    Debug.Assert(Source.NumberKind != NumberKinds.NotChecked && Source.NumberKind != NumberKinds.NotApplicable);

                    if (Source.NumberKind == NumberKinds.Integer)
                    {
                        Result = "int";
                    }
                    else if (Source.NumberKind == NumberKinds.Real)
                    {
                        Result = "double";
                    }
                }

                if (Result == null)
                {
                    Result = CSharpLanguageClasses.GuidToName[BaseClassGuid];
                }

                if (CSharpLanguageClasses.NameUsingTable.ContainsKey(Result))
                {
                    string UsingDirective = CSharpLanguageClasses.NameUsingTable[Result];
                    usingCollection.AddUsing(UsingDirective);
                }
            }
            else
            {
                string ClassName;

                if (Class.Source.IsEnumeration)
                {
                    cSharpTypeFormat = CSharpTypeFormats.Normal;
                }
                ClassName = Class.BasicClassName2CSharpClassName(usingCollection, cSharpTypeFormat, cSharpNamespaceFormat);

                Result = ClassName + TypeArguments2CSharpName(usingCollection, TypeArgumentList, true, true);
            }

            return(Result);
        }
        /// <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);
        }