当前位置: 首页>>代码示例>>C#>>正文


C# list.Add方法代码示例

本文整理汇总了C#中list.Add方法的典型用法代码示例。如果您正苦于以下问题:C# list.Add方法的具体用法?C# list.Add怎么用?C# list.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在list的用法示例。


在下文中一共展示了list.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToString

            /// <summary>
            /// 字符串
            /// </summary>
            /// <returns>字符串</returns>
            public override string ToString()
            {
                if (toString == null)
                {
                    list<string>.unsafer errorString = new list<string>(2).Unsafer;
                    if (Message != null) errorString.Add("附加信息 : " + Message);
                    if (StackFrame != null) errorString.Add("堆栈帧信息 : " + StackFrame.toString());
                    if (StackTrace != null) errorString.Add("堆栈信息 : " + StackTrace.ToString());
                    if (Exception != null) errorString.Add("异常信息 : " + Exception.ToString());
                    if (Type != exceptionType.None) errorString.Add("异常类型 : " + Type.ToString());
                    toString = errorString[0] + @"
" + errorString[1];
                }
                return toString;
            }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:19,代码来源:log.cs

示例2: ReplaceChild

 /// <summary>
 /// 替换子节点
 /// </summary>
 /// <param name="oldNode">待替换的子节点</param>
 /// <param name="newNode">新的子节点</param>
 /// <returns>是否存在待替换的子节点</returns>
 public bool ReplaceChild(htmlNode oldNode, htmlNode newNode)
 {
     bool isReplace = false;
     if (oldNode != null && newNode != null)
     {
         int oldIndex = this[oldNode];
         if (oldIndex != -1)
         {
             if (newNode.TagName == string.Empty)
             {
                 oldNode.Parent = null;
                 if (newNode.children == null) children.RemoveAt(oldIndex);
                 else
                 {
                     foreach (htmlNode value in newNode.children) value.Parent = this;
                     if (newNode.children.Count == 1) children[oldIndex] = newNode.children[0];
                     else if (oldIndex == children.Count - 1)
                     {
                         children.RemoveAt(oldIndex);
                         children.Add(newNode.children);
                     }
                     else
                     {
                         list<htmlNode>.unsafer values = new list<htmlNode>(children.Count + newNode.children.Count).Unsafer;
                         int newIndex = 0;
                         while (newIndex != oldIndex) values.Add(children[newIndex++]);
                         values.List.Add(newNode.children);
                         for (oldIndex = children.Count; ++newIndex != oldIndex; values.Add(children[newIndex])) ;
                         children = values.List;
                     }
                 }
                 newNode.children = null;
                 isReplace = true;
             }
             else if (!newNode.IsNode(this))
             {
                 int newIndex = this[newNode];
                 if (newIndex == -1)
                 {
                     if (newNode.Parent != null) newNode.Parent.RemoveChild(newNode);
                     newNode.Parent = this;
                     children[oldIndex] = newNode;
                     oldNode.Parent = null;
                 }
                 else
                 {
                     children[oldIndex] = newNode;
                     oldNode.Parent = null;
                     children.RemoveAt(newIndex);
                 }
                 isReplace = true;
             }
         }
     }
     return isReplace;
 }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:62,代码来源:htmlNode.cs

示例3: getNodesByTagName

 /// <summary>
 /// 根据节点名称获取子孙节点集合
 /// </summary>
 /// <param name="tagName">节点名称</param>
 /// <returns>匹配的子孙节点集合</returns>
 public list<htmlNode> getNodesByTagName(string tagName)
 {
     list<htmlNode> values = new list<htmlNode>();
     foreach (htmlNode value in Nodes)
     {
         if (value.TagName == tagName) values.Add(value);
     }
     return values;
 }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:14,代码来源:htmlNode.cs

示例4: removeChilds

 /// <summary>
 /// 删除匹配的子节点
 /// </summary>
 /// <param name="isRemove">删除子节点匹配器</param>
 private void removeChilds(func<htmlNode, bool> isRemove)
 {
     if (children != null)
     {
         int count = children.Count;
         while (--count >= 0 && !isRemove(children[count])) ;
         if (count >= 0)
         {
             list<htmlNode>.unsafer values = new list<htmlNode>(children.Count).Unsafer;
             int index = 0;
             for (; index != count; ++index)
             {
                 if (!isRemove(children[index])) values.Add(children[index]);
             }
             for (count = children.Count; ++index != count; values.Add(children[index])) ;
             children = values.List;
         }
     }
 }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:23,代码来源:htmlNode.cs

示例5: split

 /// <summary>
 /// 分割字符串
 /// </summary>
 /// <param name="value">原字符串</param>
 /// <param name="startIndex">起始位置</param>
 /// <param name="length">分割字符串长度</param>
 /// <param name="split">分割符</param>
 /// <returns>字符子串集合</returns>
 public unsafe static list<subString> split(this string value, int startIndex, int length, char split)
 {
     array.range range = new array.range(value.length(), startIndex, length);
     if (range.GetCount != length) fastCSharp.log.Default.Throw(log.exceptionType.IndexOutOfRange);
     list<subString> values = new list<subString>();
     if (value != null)
     {
         fixed (char* valueFixed = value)
         {
             char* last = valueFixed + range.SkipCount, end = last + range.GetCount;
             for (char* start = last; start != end; )
             {
                 if (*start == split)
                 {
                     values.Add(new subString(value, (int)(last - valueFixed), (int)(start - last)));
                     last = ++start;
                 }
                 else ++start;
             }
             values.Add(new subString(value, (int)(last - valueFixed), (int)(end - last)));
         }
     }
     return values;
 }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:32,代码来源:string.cs

示例6: constantConverter

 /// <summary>
 /// 常量转换
 /// </summary>
 protected constantConverter()
 {
     list<keyValue<hashCode<Type>, func<object, string>>> values = new list<keyValue<hashCode<Type>, func<object, string>>>();
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(bool), convertConstantBoolTo01));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(bool?), convertConstantBoolNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(byte), convertConstantByte));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(byte?), convertConstantByteNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(sbyte), convertConstantSByte));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(sbyte?), convertConstantSByteNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(short), convertConstantShort));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(short?), convertConstantShortNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(ushort), convertConstantUShort));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(ushort?), convertConstantUShortNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(int), convertConstantInt));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(int?), convertConstantIntNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(uint), convertConstantUInt));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(uint?), convertConstantUIntNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(long), convertConstantLong));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(long?), convertConstantLongNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(ulong), convertConstantULong));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(ulong?), convertConstantULongNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(float), convertConstantFloat));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(float?), convertConstantFloatNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(double), convertConstantDouble));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(double?), convertConstantDoubleNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(decimal), convertConstantDecimal));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(decimal?), convertConstantDecimalNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(DateTime), convertConstantDateTimeMillisecond));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(DateTime?), convertConstantDateTimeMillisecondNullable));
     values.Add(new keyValue<hashCode<Type>, func<object, string>>(typeof(string), null));
     converters = new staticDictionary<hashCode<Type>, func<object, string>>(values);
 }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:35,代码来源:constantConverter.cs

示例7: filterChild

 /// <summary>
 /// 子节点筛选
 /// </summary>
 /// <param name="path">筛选器</param>
 /// <param name="value">筛选节点集合</param>
 /// <returns>匹配的HTML节点集合</returns>
 private static keyValue<list<htmlNode>, bool> filterChild(filter path, keyValue<list<htmlNode>, bool> value)
 {
     if (path.index < 0)
     {
         if (path.indexs == null)
         {
             if (path.values == null)
             {
                 if (path.value != null)
                 {
                     string tagName = path.value;
                     list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer;
                     foreach (htmlNode nodes in value.Key)
                     {
                         if (nodes.children.count() > 0)
                         {
                             foreach (htmlNode node in nodes.children)
                             {
                                 if (node.TagName == tagName) newValues.Add(node);
                             }
                         }
                     }
                     return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1);
                 }
                 else
                 {
                     int index = 0;
                     foreach (htmlNode nodes in value.Key) if (nodes.children != null) index += nodes.children.Count;
                     if (index != 0)
                     {
                         htmlNode[] newValues = new htmlNode[index];
                         index = 0;
                         foreach (htmlNode nodes in value.Key)
                         {
                             if (nodes.children != null)
                             {
                                 nodes.children.CopyTo(newValues, index);
                                 index += nodes.children.Count;
                             }
                         }
                         return new keyValue<list<htmlNode>, bool>(new list<htmlNode>(newValues, true), value.Value && newValues.Length != 1);
                     }
                     return new keyValue<list<htmlNode>, bool>(null, false);
                 }
             }
             else
             {
                 staticHashSet<string> tagNames = path.values;
                 list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer;
                 foreach (htmlNode nodes in value.Key)
                 {
                     if (nodes.children.count() != 0)
                     {
                         foreach (htmlNode node in nodes.children)
                         {
                             if (tagNames.Contains(node.TagName)) newValues.Add(node);
                         }
                     }
                 }
                 return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1);
             }
         }
         else
         {
             list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer;
             if (path.value != null)
             {
                 string tagName = path.value;
                 staticHashSet<int> indexs = path.indexs;
                 foreach (htmlNode nodes in value.Key)
                 {
                     if (nodes.children.count() != 0)
                     {
                         int index = 0;
                         foreach (htmlNode node in nodes.children)
                         {
                             if (node.TagName == tagName)
                             {
                                 if (indexs.Contains(index)) newValues.Add(node);
                                 ++index;
                             }
                         }
                     }
                 }
             }
             else
             {
                 int[] indexs = path.indexs.GetList().ToArray();
                 foreach (htmlNode nodes in value.Key)
                 {
                     int count = nodes.children.count();
                     if (count > 0)
                     {
                         list<htmlNode> children = nodes.children;
//.........这里部分代码省略.........
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:101,代码来源:htmlNode.cs

示例8: Get

 /// <summary>
 /// 根据筛选路径值匹配HTML节点集合
 /// </summary>
 /// <param name="path">筛选路径</param>
 /// <param name="node">筛选节点</param>
 /// <returns>匹配的HTML节点集合</returns>
 public static list<htmlNode> Get(string path, htmlNode node)
 {
     if (path != null && path.Length != 0)
     {
         list<htmlNode> nodes = new list<htmlNode>();
         nodes.Add(node);
         return get(path).get(new keyValue<list<htmlNode>, bool>(nodes, false));
     }
     return null;
 }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:16,代码来源:htmlNode.cs

示例9: code

        /// <summary>
        /// 生成代码
        /// </summary>
        /// <param name="fileName">模板文件名</param>
        /// <returns>代码</returns>
        private static list<string> code(string fileName)
        {
            string code = File.ReadAllText(fileName);
            int index = code.IndexOf(@"*/

", StringComparison.Ordinal);
            if (index != -1)
            {
                int startIndex = index += 4;
                Dictionary<string, replace> keys = new Dictionary<string, replace>();
                replace replace;
                foreach (string keyValue in code.Substring(0, index).Split(new string[] { "/*" }, StringSplitOptions.None).sub(1))
                {
                    if ((index = keyValue.IndexOf(':')) != -1 && keyValue.EndsWith(@"*/
", StringComparison.Ordinal))
                    {
                        keys[keyValue.Substring(0, index)] = replace = new replace
                        {
                            values = new subString(keyValue, ++index, keyValue.Length - index - 4).Split(';').getArray(value => value.Split(','))
                        };
                        replace.indexs = new list<int>[replace.values[0].Count];
                        for (index = 0; index != replace.indexs.Length; replace.indexs[index++] = new list<int>()) ;
                    }
                    else error.Add("自定义数据错误 : " + keyValue);
                }
                list<string> codeList = new list<string>();
                for (code = code.Substring(startIndex), startIndex = 0, index = code.IndexOf("/*", StringComparison.Ordinal); index != -1; index = code.IndexOf("/*", startIndex))
                {
                    codeList.Add(code.Substring(startIndex, index - startIndex));
                    if ((startIndex = code.IndexOf("*/", index, StringComparison.Ordinal) + 2) != 1 && startIndex != index + 4)
                    {
                        string name = code.Substring(index, startIndex - index);
                        if ((index = code.IndexOf(name, startIndex, StringComparison.Ordinal)) != -1)
                        {
                            startIndex = index + name.Length;
                            name = name.Substring(2, name.Length - 4);
                            if (name[name.Length - 1] == ']')
                            {
                                int arrayIndex = name.LastIndexOf('[') + 1;
                                if (arrayIndex == 0 || !int.TryParse(name.Substring(arrayIndex, name.Length - arrayIndex - 1), out index))
                                {
                                    error.Add("自定义名称索引错误 : " + name);
                                    index = 0;
                                }
                                else name = name.Substring(0, arrayIndex - 1);
                            }
                            else index = 0;
                            if (keys.TryGetValue(name, out replace))
                            {
                                replace.indexs[index].Add(codeList.Count);
                                codeList.Add(string.Empty);
                            }
                            else error.Add("自定义名称不匹配 : " + name);
                        }
                        else error.Add("自定义名称不匹配 : " + name);
                    }
                    else
                    {
                        error.Add("自定义名称错误 : " + code.Substring(index));
                        startIndex = code.Length;
                    }
                }
                codeList.Add(code.Substring(startIndex));
                string[] codes = codeList.ToArray();
                list<string> values = new list<string>();
                replace[] replaces = keys.Values.getArray();
                do
                {
                    index = replaces.Length;
                    while (--index >= 0 && ++replaces[index].index == replaces[index].values.Length) ;
                    if (index == -1) break;
                    while (++index != replaces.Length) replaces[index].index = 0;
                    for (index = replaces.Length; --index >= 0; )
                    {
                        replace = replaces[index];
                        list<subString> replaceCode = replace.values[replace.index];
                        for (startIndex = replace.indexs.Length; --startIndex >= 0; )
                        {
                            foreach (int codeIndex in replace.indexs[startIndex]) codes[codeIndex] = replaceCode[startIndex];
                        }
                    }
                    values.Add(string.Concat(codes));
                }
                while (true);
                return values;
            }
            else error.Add("自定义文件错误 : " + fileName);
            return null;
        }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:94,代码来源:simpleTemplate.cs

示例10: filterClass

 /// <summary>
 /// class样式筛选
 /// </summary>
 /// <param name="path">筛选器</param>
 /// <param name="value">筛选节点集合</param>
 /// <returns>匹配的HTML节点集合</returns>
 private static keyValue<list<htmlNode>, bool> filterClass(filter path, keyValue<list<htmlNode>, bool> value)
 {
     list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer;
     if (path.values == null)
     {
         string name = path.value;
         foreach (htmlNode node in value.Key)
         {
             string className = node["class"];
             if (className != null && className.Split(' ').indexOf(name) != -1) newValues.Add(node);
         }
     }
     else
     {
         staticHashSet<string> names = path.values;
         foreach (htmlNode node in value.Key)
         {
             string className = node["class"];
             if (className != null)
             {
                 foreach(string name in className.Split(' '))
                 {
                     if (names.Contains(name))
                     {
                         newValues.Add(node);
                         break;
                     }
                 }
             }
         }
     }
     return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1);
 }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:39,代码来源:htmlNode.cs

示例11: MergeDomainCookie

 /// <summary>
 /// 合并同域cookie(用于处理跨域BUG)
 /// </summary>
 /// <param name="address">URI地址</param>
 /// <param name="responseHeaderCookie">HTTP头cookie信息</param>
 /// <param name="replaceCookie">需要替换的cookie</param>
 public void MergeDomainCookie(Uri address, string responseHeaderCookie, string replaceCookie)
 {
     if (address != null)
     {
         int index;
         string name;
         Cookie newCookie;
         CookieCollection cookies = new CookieCollection();
         Dictionary<string, Cookie> replaceCookies = null;
         if (responseHeaderCookie != null && responseHeaderCookie.Length != 0)
         {
             replaceCookies = new Dictionary<string, Cookie>();
             DateTime expires;
             string value, domain, path, expiresString;
             string lastCookie = null;
             list<string> newCookies = new list<string>();
             foreach (string cookie in responseHeaderCookie.Split(','))
             {
                 if (lastCookie == null)
                 {
                     string lowerCookie = cookie.ToLower();
                     index = lowerCookie.IndexOf("; expires=", StringComparison.Ordinal);
                     if (index == -1) index = lowerCookie.IndexOf(";expires=", StringComparison.Ordinal);
                     if (index == -1 || cookie.IndexOf(';', index + 10) != -1) newCookies.Add(cookie);
                     else lastCookie = cookie;
                 }
                 else
                 {
                     newCookies.Add(lastCookie + "," + cookie);
                     lastCookie = null;
                 }
             }
             Dictionary<string, string> cookieInfo = new Dictionary<string, string>();
             foreach (string cookie in newCookies)
             {
                 newCookie = null;
                 foreach (subString values in cookie.Split(';'))
                 {
                     if ((index = values.IndexOf('=')) != 0)
                     {
                         if ((index = values.IndexOf('=')) == -1)
                         {
                             name = values.Trim();
                             value = string.Empty;
                         }
                         else
                         {
                             name = values.Substring(0, index).Trim();
                             value = values.Substring(index + 1);
                         }
                         if (newCookie == null) newCookie = new Cookie(web.cookie.FormatCookieName(name), web.cookie.FormatCookieValue(value));
                         else cookieInfo[name.toLower()] = value;
                     }
                 }
                 if (cookieInfo.TryGetValue("expires", out expiresString)
                     && DateTime.TryParse(expiresString, out expires))
                 {
                     newCookie.Expires = expires;
                 }
                 if (cookieInfo.TryGetValue("path", out path)) newCookie.Path = path;
                 replaceCookies[newCookie.Name] = newCookie;
                 newCookie = new Cookie(newCookie.Name, newCookie.Value, newCookie.Path);
                 if (cookieInfo.TryGetValue("domain", out domain)) newCookie.Domain = domain;
                 Cookies.Add(address, newCookie);
                 cookieInfo.Clear();
             }
         }
         if (replaceCookie != null && replaceCookie.Length != 0)
         {
             if (replaceCookies == null) replaceCookies = new Dictionary<string, Cookie>();
             foreach (subString cookie in replaceCookie.Split(';'))
             {
                 if ((index = cookie.IndexOf('=')) != 0)
                 {
                     if (index == -1)
                     {
                         name = web.cookie.FormatCookieName(cookie.Trim());
                         newCookie = new Cookie(name, string.Empty);
                     }
                     else
                     {
                         name = web.cookie.FormatCookieName(cookie.Substring(0, index).Trim());
                         newCookie = new Cookie(name, web.cookie.FormatCookieValue(cookie.Substring(index + 1)));
                     }
                     if (replaceCookies.ContainsKey(name)) replaceCookies[name].Value = newCookie.Value;
                     else replaceCookies.Add(name, newCookie);
                 }
             }
         }
         bool isCookie;
         foreach (Cookie cookie in Cookies.GetCookies(address))
         {
             if (isCookie = replaceCookies != null && replaceCookies.ContainsKey(cookie.Name))
             {
//.........这里部分代码省略.........
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:101,代码来源:webClient.cs

示例12: splitIntNoCheck

 /// <summary>
 /// 分割字符串并返回数值集合(不检查数字合法性)
 /// </summary>
 /// <param name="ints">原字符串</param>
 /// <param name="split">分割符</param>
 /// <returns>数值集合</returns>
 public unsafe static list<int> splitIntNoCheck(this string ints, char split)
 {
     list<int> values = new list<int>();
     if (ints != null && ints.Length != 0)
     {
         fixed (char* intPoint = ints)
         {
             int intValue = 0;
             for (char* next = intPoint, end = intPoint + ints.Length; next != end; ++next)
             {
                 if (*next == split)
                 {
                     values.Add(intValue);
                     intValue = 0;
                 }
                 else
                 {
                     intValue *= 10;
                     intValue += *next;
                     intValue -= '0';
                 }
             }
             values.Add(intValue);
         }
     }
     return values;
 }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:33,代码来源:string.cs

示例13: Html

 /// <summary>
 /// 生成HTML
 /// </summary>
 /// <param name="isTag">是否包含当前标签</param>
 /// <returns>HTML</returns>
 public string Html(bool isTag)
 {
     if (TagName != null)
     {
         if (web.html.NonanalyticTagNames.Contains(TagName))
         {
             if (isTag && TagName.Length != 1)
             {
                 using (charStream strings = new charStream())
                 {
                     tagHtml(strings);
                     strings.Write(nodeText.Html);
                     tagRound(strings);
                     return strings.ToString();
                 }
             }
         }
         else
         {
             using (charStream strings = new charStream())
             {
                 if (isTag) tagHtml(strings);
                 if (children.count() != 0)
                 {
                     htmlNode node;
                     list<nodeIndex> values = new list<nodeIndex>();
                     nodeIndex index = new nodeIndex { Values = children };
                     while (true)
                     {
                         if (index.Values == null)
                         {
                             if (values.Count == 0) break;
                             {
                                 index = values.Pop();
                                 index.Values[index.Index].tagRound(strings);
                                 if (++index.Index == index.Values.Count)
                                 {
                                     index.Values = null;
                                     continue;
                                 }
                             }
                         }
                         node = index.Values[index.Index];
                         string nodeTagName = node.TagName;
                         bool isNonanalyticTagNames = nodeTagName != null && web.html.NonanalyticTagNames.Contains(nodeTagName);
                         if (node.children.count() == 0 || nodeTagName == null || isNonanalyticTagNames)
                         {
                             if (nodeTagName != null && nodeTagName.Length != 1) node.tagHtml(strings);
                             strings.Write(node.nodeText.Html);
                             if (nodeTagName != null && nodeTagName.Length != 1) node.tagRound(strings);
                             if (++index.Index == index.Values.Count) index.Values = null;
                         }
                         else
                         {
                             node.tagHtml(strings);
                             values.Add(index);
                             index.Values = node.children;
                             index.Index = 0;
                         }
                     }
                 }
                 if (isTag) tagRound(strings);
                 return strings.ToString();
             }
         }
     }
     return nodeText.Html;
 }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:73,代码来源:htmlNode.cs

示例14: filterValue

 /// <summary>
 /// 属性值筛选
 /// </summary>
 /// <param name="path">筛选器</param>
 /// <param name="value">筛选节点集合</param>
 /// <returns>匹配的HTML节点集合</returns>
 private static keyValue<list<htmlNode>, bool> filterValue(filter path, keyValue<list<htmlNode>, bool> value)
 {
     string name = path.name;
     list<htmlNode>.unsafer newValues = new list<htmlNode>(value.Key.Count).Unsafer;
     if (path.values == null && path.value == null)
     {
         foreach (htmlNode node in value.Key)
         {
             if (node.attributes != null && node.attributes.ContainsKey(name)) newValues.Add(node);
         }
     }
     else
     {
         if (path.values == null)
         {
             string nameValue = path.value;
             foreach (htmlNode node in value.Key)
             {
                 if (node[name] == nameValue) newValues.Add(node);
             }
         }
         else
         {
             staticHashSet<string> values = path.values;
             foreach (htmlNode node in value.Key)
             {
                 if (values.Contains(node[name])) newValues.Add(node);
             }
         }
     }
     return new keyValue<list<htmlNode>, bool>(newValues.List.Count != 0 ? newValues.List : null, value.Value && newValues.List.Count > 1);
 }
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:38,代码来源:htmlNode.cs

示例15: create

        /// <summary>
        /// 解析HTML节点
        /// </summary>
        /// <param name="html"></param>
        private void create(string html)
        {
            int length = html.Length;
            children = new list<htmlNode>();
            if (length < 2)
            {
                children.Add(new htmlNode { nodeText = new htmlText { FormatHtml = html }, Parent = this });
            }
            else
            {
                int nextIndex, nodeCount;
                htmlNode nextNode;
                fixed (char* htmlFixed = html + "<")
                {
                    fixedMap spaceFixedMap = new fixedMap(spaceMap.Map);
                    fixedMap spaceSplitFixedMap = new fixedMap(spaceSplitMap);
                    fixedMap tagNameFixedMap = new fixedMap(tagNameMap);
                    fixedMap tagNameSplitFixedMap = new fixedMap(tagNameSplitMap);
                    fixedMap attributeSplitFixedMap = new fixedMap(attributeSplitMap);
                    fixedMap attributeNameSplitFixedMap = new fixedMap(attributeNameSplitMap);
                    int startIndex, tagNameLength;
                    string name, htmlValue;
                    char* startChar = htmlFixed, currentChar = htmlFixed, endChar = htmlFixed + length, scriptChar;
                    char splitChar;
                    while (currentChar != endChar)
                    {
                        for (*endChar = '<'; *currentChar != '<'; ++currentChar) ;
                        if (currentChar != endChar)
                        {
                            if ((*++currentChar & 0xff80) == 0)
                            {
                                if (tagNameFixedMap.Get(*currentChar))
                                {
                                    while ((*startChar & 0xffc0) == 0 && spaceFixedMap.Get(*startChar)) ++startChar;
                                    if (startChar != currentChar - 1)
                                    {
                                        for (scriptChar = currentChar - 2; (*scriptChar & 0xffc0) == 0 && spaceFixedMap.Get(*scriptChar); --scriptChar) ;
                                        children.Add(new htmlNode { nodeText = new htmlText { FormatHtml = html.Substring((int)(startChar - htmlFixed), (int)(scriptChar - startChar) + 1) } });
                                    }
                                    if (*currentChar == '/')
                                    {
                                        #region 标签回合
                                        startChar = currentChar - 1;
                                        if (++currentChar != endChar)
                                        {
                                            while ((*currentChar & 0xffc0) == 0 && spaceFixedMap.Get(*currentChar)) ++currentChar;
                                            if (currentChar != endChar)
                                            {
                                                if ((uint)((*currentChar | 0x20) - 'a') <= 26)
                                                {
                                                    for (*endChar = '>'; (*currentChar & 0xffc0) != 0 || !tagNameSplitFixedMap.Get(*currentChar); ++currentChar) ;
                                                    TagName = html.Substring((int)((startChar += 2) - htmlFixed), (int)(currentChar - startChar)).toLower();
                                                    for (startIndex = children.Count - 1; startIndex >= 0 && (children[startIndex].nodeText.FormatHtml != null || children[startIndex].TagName != TagName); --startIndex) ;
                                                    if (startIndex != -1)
                                                    {
                                                        for (nextIndex = children.Count - 1; nextIndex != startIndex; --nextIndex)
                                                        {
                                                            nextNode = children[nextIndex];
                                                            if (nextNode.nodeText.FormatHtml == null)
                                                            {
                                                                if (web.html.MustRoundTagNames.Contains(nextNode.TagName) && (nodeCount = (children.Count - nextIndex - 1)) != 0)
                                                                {
                                                                    nextNode.children = new list<htmlNode>(children.GetSub(nextIndex + 1, nodeCount), true);
                                                                    children.RemoveRange(nextIndex + 1, nodeCount);
                                                                    foreach (htmlNode value in nextNode.children) value.Parent = nextNode;
                                                                }
                                                            }
                                                            else if (nextNode.nodeText.FormatHtml.Length == 0) nextNode.nodeText.FormatHtml = null;
                                                        }
                                                        nextNode = children[startIndex];
                                                        if ((nodeCount = children.Count - ++startIndex) != 0)
                                                        {
                                                            nextNode.children = new list<htmlNode>(children.GetSub(startIndex, nodeCount), true);
                                                            children.RemoveRange(startIndex, nodeCount);
                                                            foreach (htmlNode value in nextNode.children) value.Parent = nextNode;
                                                        }
                                                        nextNode.nodeText.FormatHtml = string.Empty;//已回合标识
                                                    }
                                                    while (*currentChar != '>') ++currentChar;
                                                    if (currentChar != endChar) ++currentChar;
                                                }
                                                else
                                                {
                                                    for (*endChar = '>'; *currentChar != '>'; ++currentChar) ;
                                                    if (currentChar != endChar) ++currentChar;
                                                    htmlValue = html.Substring((int)(startChar - htmlFixed), (int)(currentChar - startChar));
                                                    children.Add(new htmlNode { TagName = "/", nodeText = new htmlText { FormatHtml = htmlValue, FormatText = htmlValue } });
                                                }
                                                startChar = currentChar;
                                            }
                                        }
                                        #endregion
                                    }
                                    else if (*currentChar != '!')
                                    {
                                        #region 标签开始
//.........这里部分代码省略.........
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:101,代码来源:htmlNode.cs


注:本文中的list.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。