Beispiel #1
0
        /// <summary>
        /// Indicates that object is IProperty that uses getter setter functions, and not native fields
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        internal static bool IsEntityFunctionProperty(IEntity entity, ICSharpCode.NRefactory.Semantics.ResolveResult scope)
        {
            var pe = entity as IProperty;

            if (pe != null)
            {
                var ce = pe.DeclaringType;
                if (ce != null && ce.Kind == TypeKind.Anonymous)
                {
                    var ce2 = scope.GetParentType();
                    if (ce2 != null && Sk.UseNativeJsons(ce2))
                    {
                        return(false);
                    }
                }
                return(!Sk.IsNativeField(pe) && !Sk.UseNativeIndexer(pe)); // && !Sk.IsNativeProperty(pe);
            }
            return(false);
        }
Beispiel #2
0
        public static string GetEntityJsName(IMethod me2)
        {
            IMethod me;

            if (me2.IsConstructor && me2.DeclaringType.Kind == TypeKind.TypeParameter)//happens when invoking new T();
            {
                me = me2;
            }
            else
            {
                me = (IMethod)me2.MemberDefinition;
            }
            var name = me.Name;

            if (name != null)
            {
                if (name == ".ctor")
                {
                    name = "ctor";
                }
                else if (name == ".cctor")
                {
                    name = "cctor";
                }
            }

            var att = me.GetMetadata <JsMethodAttribute>(true);

            if (att != null && att.Name != null)
            {
                name = att.Name;
            }
            else if (me.DeclaringType.Kind == TypeKind.Delegate && me.Name == "Invoke")
            {
                return("");
            }
            else if (me.DeclaringType.IsGenericMethodArgument()) //happens when invoking new T() in method MyMethod<T>();
            {
                name = GetEntityJsName(me.DeclaringType);
            }
            //else if (me.DeclaringType.IsGenericTypeParameter()) //happens when invoking new T() in class List<T>;
            //{
            //    name = EntityTypeRefToMember(me.DeclaringType);
            //}
            else
            {
                var owner = me.GetOwner();
                if (owner != null && owner is IProperty)
                {
                    var pe = (IProperty)owner;
                    if (pe.SymbolKind == SymbolKind.Indexer && Sk.UseNativeIndexer(pe))
                    {
                        return("");
                    }
                    name = GetEntityJsName(pe);
                    if (me.IsGetter())
                    {
                        name = "get_" + name;
                    }
                    else
                    {
                        name = "set_" + name;
                    }
                }
            }

            // 前面有地方被统一修改
            if (me.DeclaringType.FullName == "System.Enum")
            {
                if (name == "ToString" || name == "toString")
                {
                    name = "System.Enum.GetName";
                }
            }

            if (Sk.NewInterfaceImplementation)
            {
                name = SkJs.GetMethodPrefix(me) + name;
            }

            if (!Sk.UseNativeOverloads(me))
            {
                if (me.TypeParameters.IsNotNullOrEmpty())
                {
                    name += "$" + me.TypeParameters.Count;
                }
                name += SkJs.GetOverloadedMethodSuffix(me);
            }
            return(name);
        }