Exemplo n.º 1
0
            /// <summary>
            /// 安装下一个类型
            /// </summary>
            protected override void nextCreate()
            {
                PathMembers.Clear();
                object    pathValue = typeof(AutoCSer.Emit.Constructor <>).MakeGenericType(Type).GetMethod("Default", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, NullValue <Type> .Array, null).Invoke(null, null);
                string    queryName = (Attribute.QueryName ?? (Type.Type.Name + "Id")), query;
                FieldInfo idField = Type.Type.GetField("Id", BindingFlags.Instance | BindingFlags.Public);

                if (idField == null || idField.FieldType != typeof(int))
                {
                    query = queryName + "=0";
                }
                else
                {
                    idField.SetValue(pathValue, 1);
                    query = queryName + "=1";
                }
                foreach (AutoCSer.CodeGenerator.Metadata.MemberIndex member in AutoCSer.CodeGenerator.Metadata.MethodIndex.GetMembers <AutoCSer.WebView.PathMemberAttribute>(Type, Attribute.MemberFilters, Attribute.IsAttribute, Attribute.IsBaseTypeAttribute))
                {
                    if (member.MemberSystemType == typeof(string))
                    {
                        string url = (string)(member.Member as PropertyInfo).GetValue(pathValue, null);
                        if (url.EndsWith(query, StringComparison.Ordinal))
                        {
                            PathMembers.Add(new PathMember {
                                Member = member, Path = url.Substring(0, url.Length - query.Length), QueryName = queryName, IsHash = false, IsIdentity = true
                            });
                        }
                        else
                        {
                            PathMembers.Add(new PathMember {
                                Member = member, Path = url
                            });
                        }
                    }
                    else if (member.MemberSystemType == typeof(AutoCSer.WebView.HashUrl))
                    {
                        AutoCSer.WebView.HashUrl url = (AutoCSer.WebView.HashUrl)(member.Member as PropertyInfo).GetValue(pathValue, null);
                        if (url.Query == query)
                        {
                            PathMembers.Add(new PathMember {
                                Member = member, Path = url.Path, QueryName = queryName, IsHash = true, IsIdentity = true
                            });
                        }
                        else if (url.Query.EndsWith(query, StringComparison.Ordinal))
                        {
                            PathMembers.Add(new PathMember {
                                Member = member, Path = url.Path, OtherQuery = url.Query.Substring(0, url.Query.Length - query.Length), QueryName = queryName, IsHash = true, IsIdentity = true
                            });
                        }
                    }
                }
                if (PathMembers.Length != 0)
                {
                    _code_.Length = 0;
                    create(false);
                    code.Add(_code_);
                }
            }
Exemplo n.º 2
0
 public void Write(AutoCSer.WebView.HashUrl url)
 {
     Encoding.WriteBytes(url.Path, Stream);
     if (!string.IsNullOrEmpty(url.Query))
     {
         Encoding.WriteUrlHash(Stream);
         Encoding.WriteBytesNotEmpty(url.Query, Stream);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 输出 URL
        /// </summary>
        /// <param name="url"></param>
        public void WriteTextArea(AutoCSer.WebView.HashUrl url)
        {
            if (!string.IsNullOrEmpty(url.Path))
            {
                fixed(char *valueFixed = url.Path) HtmlEncoder.TextArea.ToHtml(ref this, valueFixed, url.Path.Length);
            }
            if (!string.IsNullOrEmpty(url.Query))
            {
                Encoding.WriteUrlHash(Stream);

                fixed(char *valueFixed = url.Query) HtmlEncoder.TextArea.ToHtml(ref this, valueFixed, url.Query.Length);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 对象转换成JSON字符串
        /// </summary>
        /// <param name="value">#!转换URL</param>
        public void WriteWebViewJson(AutoCSer.WebView.HashUrl value)
        {
            Write('"');
            if (!string.IsNullOrEmpty(value.Path))
            {
                fixed(char *valueFixed = value.Path) WriteJson(valueFixed, value.Path.Length, ' ');
            }
            if (!string.IsNullOrEmpty(value.Query))
            {
                *(int *)GetBeforeMove(2 * sizeof(char)) = '#' + ('!' << 16);

                fixed(char *valueFixed = value.Query) WriteJson(valueFixed, value.Query.Length, ' ');
            }
            Write('"');
        }