Exemple #1
0
        static string GetEntityJsName(this ITypeDefinition ce, bool shortName)
        {
            var jta = ce.GetJsTypeAttribute();

            if (shortName)
            {
                if (jta != null && jta.Name != null)
                {
                    if (jta.Name.Contains('.'))
                    {
                        return(jta.Name.Substring(jta.Name.LastIndexOf('.') + 1));
                    }
                    else
                    {
                        return(jta.Name);
                    }
                }
                var name = ce.Name;
                if (ce.TypeParameters.IsNotNullOrEmpty() && !Sk.IgnoreTypeArguments(ce))
                {
                    name += "$" + ce.TypeParameterCount;
                }
                return(name);
            }
            else
            {
                if (jta != null && jta.Name != null)
                {
                    return(jta.Name);
                }
                var name = ce.FullName;
                if (ce.ParentAssembly != null)
                {
                    var atts = ce.ParentAssembly.GetMetadatas <JsNamespaceAttribute>().Where(t => t.Namespace.IsNotNullOrEmpty() && t.JsNamespace != null).OrderByDescending(t => t.Namespace.Length).ToList();
                    if (atts.Count > 0)
                    {
                        foreach (var att in atts)
                        {
                            if (name.StartsWith(att.Namespace))
                            {
                                if (att.JsNamespace.IsNullOrEmpty())
                                {
                                    name = name.ReplaceFirst(att.Namespace + ".", "");
                                }
                                else
                                {
                                    name = name.ReplaceFirst(att.Namespace, att.JsNamespace);
                                }
                                break;
                            }
                        }
                    }
                }
                if (ce.TypeParameters.IsNotNullOrEmpty() && !Sk.IgnoreTypeArguments(ce))
                {
                    name += "$" + ce.TypeParameterCount;
                }
                return(name);
            }
        }
Exemple #2
0
        public static string GetEntityJsName(IType ceref)
        {
            if (ceref is ITypeDefinition)
            {
                return(GetEntityJsName((ITypeDefinition)ceref));
            }
            var includeGenericArgs = !Sk.IgnoreTypeArguments(ceref.GetEntityType());

            return(ceref.GetEntityJsName(false, includeGenericArgs));
        }
Exemple #3
0
        static string GetEntityJsName(this IType ceref, bool shortName)
        {
            if (ceref is ITypeDefinition)
            {
                return(GetEntityJsName((ITypeDefinition)ceref, shortName));
            }

            var ce = ceref.GetEntityType();
            var includeGenericArgs = false;

            if (ce != null)
            {
                includeGenericArgs = !Sk.IgnoreTypeArguments(ceref.GetEntityType());
            }
            return(ceref.GetEntityJsName(shortName, includeGenericArgs));
        }
Exemple #4
0
        static string GetEntityJsNameV2(this IType type, bool shortName)
        {
            //if (type.Kind == TypeKind.Anonymous)
            //    return "Object";
            var ce = type.GetDefinition();

            var r  = type.ToTypeReference();
            var pr = r as ParameterizedTypeReference;

            var jta = ce.GetJsTypeAttribute();

            if (shortName)
            {
                if (jta != null && jta.Name != null)
                {
                    if (jta.Name.Contains('.'))
                    {
                        return(jta.Name.Substring(jta.Name.LastIndexOf('.') + 1));
                    }
                    else
                    {
                        return(jta.Name);
                    }
                }
                var name = ce.Name;
                if (ce.TypeParameters.IsNotNullOrEmpty() && !Sk.IgnoreTypeArguments(ce))
                {
                    if (pr == null || !UseFullParameterizedName(pr, type))
                    {
                        name += "$" + ce.TypeParameterCount;
                    }
                    else
                    {
                        name += pr.TypeArguments.StringConcat((p) =>
                        {
                            var p2 = p as ICSharpCode.NRefactory.TypeSystem.Implementation.GetClassTypeReference;
                            return(p2.FullTypeName.Name);
                        }, "$" + ce.TypeParameterCount + "$", "$", "");
                    }
                }
                return(name);
            }
            else
            {
                if (jta != null && jta.Name != null)
                {
                    return(jta.Name);
                }
                var name = ce.FullName;
                if (ce.ParentAssembly != null)
                {
                    var atts = ce.ParentAssembly.GetMetadatas <JsNamespaceAttribute>().Where(t => t.Namespace.IsNotNullOrEmpty() && t.JsNamespace != null).OrderByDescending(t => t.Namespace.Length).ToList();
                    if (atts.Count > 0)
                    {
                        foreach (var att in atts)
                        {
                            if (name.StartsWith(att.Namespace))
                            {
                                if (att.JsNamespace.IsNullOrEmpty())
                                {
                                    name = name.ReplaceFirst(att.Namespace + ".", "");
                                }
                                else
                                {
                                    name = name.ReplaceFirst(att.Namespace, att.JsNamespace);
                                }
                                break;
                            }
                        }
                    }
                }
                if (ce.TypeParameters.IsNotNullOrEmpty() && !Sk.IgnoreTypeArguments(ce))
                {
                    name += "$" + ce.TypeParameterCount;
                }
                return(name);
            }
        }