示例#1
0
        protected virtual string GetOverloadName(IMember definition, bool skipInterfaceName = false, string prefix = null, bool withoutTypeParams = false, bool isObjectLiteral = false, bool excludeTypeOnly = false)
        {
            IMember interfaceMember = null;

            if (definition.IsExplicitInterfaceImplementation)
            {
                interfaceMember = definition.ImplementedInterfaceMembers.First();
            }
            else if (definition.DeclaringTypeDefinition != null && definition.DeclaringTypeDefinition.Kind == TypeKind.Interface)
            {
                interfaceMember = definition;
            }

            if (interfaceMember != null && !skipInterfaceName && !this.Emitter.Validator.IsObjectLiteral(interfaceMember.DeclaringTypeDefinition))
            {
                return(OverloadsCollection.GetInterfaceMemberName(this.Emitter, interfaceMember, null, prefix, withoutTypeParams, this.IsSetter, excludeTypeOnly));
            }

            string name = isObjectLiteral ? this.Emitter.GetLiteralEntityName(definition) : this.Emitter.GetEntityName(definition);

            if (name.StartsWith("." + JS.Funcs.CONSTRUCTOR))
            {
                name = JS.Funcs.CONSTRUCTOR;
            }

            var attr = Helpers.GetInheritedAttribute(definition, "H5.NameAttribute");

            var iProperty = definition as IProperty;

            if (attr == null && iProperty != null && !IsField)
            {
                var acceessor = this.IsSetter ? iProperty.Setter : iProperty.Getter;

                if (acceessor != null)
                {
                    attr = Helpers.GetInheritedAttribute(acceessor, "H5.NameAttribute");

                    if (attr != null)
                    {
                        name = this.Emitter.GetEntityName(acceessor);
                    }
                }
            }

            if (attr != null)
            {
                if (!(iProperty != null || definition is IEvent))
                {
                    prefix = null;
                }
            }

            if (attr != null && definition.ImplementedInterfaceMembers.Count > 0)
            {
                if (this.Members.Where(member => member.ImplementedInterfaceMembers.Count > 0)
                    .Any(member => definition.ImplementedInterfaceMembers.Any(implementedInterfaceMember => member.ImplementedInterfaceMembers.Any(m => m.DeclaringTypeDefinition == implementedInterfaceMember.DeclaringTypeDefinition))))
                {
                    attr = null;
                }
            }

            bool skipSuffix = false;

            if (definition.DeclaringTypeDefinition != null &&
                this.Emitter.Validator.IsExternalType(definition.DeclaringTypeDefinition))
            {
                if (definition.DeclaringTypeDefinition.Kind == TypeKind.Interface)
                {
                    skipSuffix = definition.DeclaringTypeDefinition.ParentAssembly.AssemblyName != CS.NS.H5;
                }
                else
                {
                    skipSuffix = true;
                }
            }

            if (attr != null || skipSuffix)
            {
                return(prefix != null ? prefix + name : name);
            }

            var isCtor = definition is IMethod iDefinition && iDefinition.IsConstructor;

            if (isCtor)
            {
                name = JS.Funcs.CONSTRUCTOR;
            }

            var index = this.GetIndex(definition);

            if (index > 0)
            {
                if (isCtor)
                {
                    name = JS.Vars.D + name + index;
                }
                else
                {
                    name += Helpers.PrefixDollar(index);
                    name  = Helpers.ReplaceFirstDollar(name);
                }
            }

            return(prefix != null ? prefix + name : name);
        }