コード例 #1
0
ファイル: Method.cs プロジェクト: knuxbbs/gapi
        private void GenerateDeclCommon(TextWriter textWriter, ClassBase implementor)
        {
            if (IsStatic)
            {
                textWriter.Write("static ");
            }

            textWriter.Write(Safety);

            Method dup = null;

            if (ContainerType != null)
            {
                dup = ContainerType.GetMethodRecursively(Name);
            }

            if (implementor != null)
            {
                dup = implementor.GetMethodRecursively(Name);
            }

            switch (Name)
            {
            case "ToString" when Parameters.Count == 0 && (!(ContainerType is InterfaceGen) || implementor != null):
                textWriter.Write("override ");
                break;

            case "GetGType" when ContainerType is ObjectGen || ContainerType?.Parent != null &&
                ContainerType.Parent.Methods.ContainsKey("GetType"):
                textWriter.Write("new ");
                break;

            default:
            {
                if (Modifiers == "new " || dup != null &&
                    (dup.Signature != null && Signature != null &&
                     dup.Signature.ToString() == Signature.ToString() ||
                     dup.Signature == null && Signature == null))
                {
                    textWriter.Write("new ");
                }

                break;
            }
            }

            if (Name.StartsWith(ContainerType.Name))
            {
                Name = Name.Substring(ContainerType.Name.Length);
            }

            if (IsGetter || IsSetter)
            {
                textWriter.Write(_returnValue.IsVoid ? Parameters.AccessorReturnType : _returnValue.CsType);
                textWriter.Write(" ");

                if (Name.StartsWith("Get") || Name.StartsWith("Set"))
                {
                    textWriter.Write(Name.Substring(3));
                }
                else
                {
                    var dotIndex = Name.LastIndexOf('.');

                    if (dotIndex != -1 && (Name.Substring(dotIndex + 1, 3) == "Get" ||
                                           Name.Substring(dotIndex + 1, 3) == "Set"))
                    {
                        textWriter.Write(Name.Substring(0, dotIndex + 1) + Name.Substring(dotIndex + 4));
                    }
                    else
                    {
                        textWriter.Write(Name);
                    }
                }

                textWriter.WriteLine(" { ");
            }
            else if (IsAccessor)
            {
                textWriter.Write($"{Signature.AccessorType} {Name}({Signature.AsAccessor})");
            }
            else
            {
                textWriter.Write($"{_returnValue.CsType} {Name}({(Signature != null ? Signature.ToString() : "")})");
            }
        }