Inheritance: ExternalMember
コード例 #1
0
        protected string GetPropertyScriptName(ExternalProperty prop, bool preserveMemberCase)
        {
            var scriptNameAttr = prop.Attributes.FirstOrDefault(x =>
                                                                x.Type == "System.Runtime.CompilerServices.ScriptNameAttribute");

            if (scriptNameAttr != null)
            {
                return(scriptNameAttr.Arguments[0].Value as string);
            }
            else if (!preserveMemberCase && !prop.Attributes.Any(x =>
                                                                 x.Type == "System.Runtime.CompilerServices.PreserveCaseAttribute"))
            {
                var propField = prop.Name;
                if (propField == "ID")
                {
                    return("id");
                }
                else
                {
                    return(propField.Substring(0, 1).ToLowerInvariant()
                           + propField.Substring(1));
                }
            }
            else
            {
                return(prop.Name);
            }
        }
コード例 #2
0
        private void SSDeclarationProperty(ExternalType type, ExternalProperty prop, string codeNamespace,
                                           bool isStaticClass, bool isSerializable, bool preserveMemberCase)
        {
            if (string.IsNullOrEmpty(prop.GetMethod) &&
                string.IsNullOrEmpty(prop.SetMethod))
            {
                return;
            }

            var propName = GetPropertyScriptName(prop, preserveMemberCase);

            if (isSerializable ||
                prop.Attributes.FirstOrDefault(x =>
                                               x.Type == "System.Runtime.CompilerServices.IntrinsicPropertyAttribute") != null)
            {
                if (isStaticClass && prop.IsStatic)
                {
                    cw.Indented("let ");
                    sb.Append(propName);
                }
                else if (prop.IsStatic)
                {
                    cw.Indented("static ");
                    sb.Append(propName);
                }
                else
                {
                    cw.Indented(propName);
                }

                sb.Append(": ");
                SSTypeNameToTS(prop.Type, codeNamespace);
                sb.AppendLine(";");
            }
            else
            {
                var getMethod = type.Methods.FirstOrDefault(x => x.Name == prop.GetMethod);

                if (getMethod != null)
                {
                    getMethod.Name = "get_" + propName;
                    SSDeclarationMethodInternal(getMethod, codeNamespace, isStaticClass, preserveMemberCase);
                }

                var setMethod = type.Methods.FirstOrDefault(x => x.Name == prop.SetMethod);
                if (setMethod != null)
                {
                    setMethod.Name = "set_" + propName;
                    SSDeclarationMethodInternal(setMethod, codeNamespace, isStaticClass, preserveMemberCase);
                }
            }
        }
コード例 #3
0
        private void SSDeclarationProperty(ExternalType type, ExternalProperty prop, string codeNamespace,
            bool isStaticClass, bool isSerializable, bool preserveMemberCase)
        {
            if (string.IsNullOrEmpty(prop.GetMethod) &&
                string.IsNullOrEmpty(prop.SetMethod))
                return;

            var propName = GetPropertyScriptName(prop, preserveMemberCase);

            if (isSerializable ||
                prop.Attributes.FirstOrDefault(x => 
                    x.Type == "System.Runtime.CompilerServices.IntrinsicPropertyAttribute") != null)
            {
                if (isStaticClass && prop.IsStatic)
                {
                    cw.Indented("let ");
                    sb.Append(propName);
                }
                else if (prop.IsStatic)
                {
                    cw.Indented("static ");
                    sb.Append(propName);
                }
                else
                {
                    cw.Indented(propName);
                }

                sb.Append(": ");
                SSTypeNameToTS(prop.Type, codeNamespace);
                sb.AppendLine(";");
            }
            else
            {
                var getMethod = type.Methods.FirstOrDefault(x => x.Name == prop.GetMethod);

                if (getMethod != null)
                {
                    getMethod.Name = "get_" + propName;
                    SSDeclarationMethodInternal(getMethod, codeNamespace, isStaticClass, preserveMemberCase);
                }

                var setMethod = type.Methods.FirstOrDefault(x => x.Name == prop.SetMethod);
                if (setMethod != null)
                {
                    setMethod.Name = "set_" + propName;
                    SSDeclarationMethodInternal(setMethod, codeNamespace, isStaticClass, preserveMemberCase);
                }
            }
        }
コード例 #4
0
        protected string GetPropertyScriptName(ExternalProperty prop, bool preserveMemberCase)
        {
            var scriptNameAttr = prop.Attributes.FirstOrDefault(x =>
                x.Type == "System.Runtime.CompilerServices.ScriptNameAttribute");

            if (scriptNameAttr != null)
                return scriptNameAttr.Arguments[0].Value as string;
            else if (!preserveMemberCase && !prop.Attributes.Any(x =>
                    x.Type == "System.Runtime.CompilerServices.PreserveCaseAttribute"))
            {
                var propField = prop.Name;
                if (propField == "ID")
                    return "id";
                else
                    return propField.Substring(0, 1).ToLowerInvariant()
                        + propField.Substring(1);
            }
            else
                return prop.Name;
        }