예제 #1
0
        private void SSDeclarationField(ExternalType type, ExternalMember field, string codeNamespace,
                                        bool isStaticClass, bool isSerializable, bool preserveMemberCase)
        {
            string fieldName = field.Name;

            var scriptNameAttr = field.Attributes.FirstOrDefault(x =>
                                                                 x.Type == "System.Runtime.CompilerServices.ScriptNameAttribute");

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

            if (isStaticClass && field.IsStatic)
            {
                cw.Indented("let ");
                sb.Append(fieldName);
            }
            else if (field.IsStatic)
            {
                cw.Indented("static ");
                sb.Append(fieldName);
            }
            else
            {
                cw.Indented(fieldName);
            }

            sb.Append(": ");
            SSTypeNameToTS(field.Type, codeNamespace);
            sb.AppendLine(";");
        }
        private void SSDeclarationField(ExternalType type, ExternalMember field, string codeNamespace,
            bool isStaticClass, bool isSerializable, bool preserveMemberCase)
        {
            string fieldName = field.Name;

            var scriptNameAttr = field.Attributes.FirstOrDefault(x =>
                x.Type == "System.Runtime.CompilerServices.ScriptNameAttribute");

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

            if (isStaticClass && field.IsStatic)
            {
                cw.Indented("let ");
                sb.Append(fieldName);
            }
            else if (field.IsStatic)
            {
                cw.Indented("static ");
                sb.Append(fieldName);
            }
            else
            {
                cw.Indented(fieldName);
            }

            sb.Append(": ");
            SSTypeNameToTS(field.Type, codeNamespace);
            sb.AppendLine(";");
        }