当前位置: 首页 > news >正文

怎么建设手机端网站网页加速器浏览器

怎么建设手机端网站,网页加速器浏览器,企业网站设计与管理系统,手机网站用户体验目录 一#xff0c;问题表现 二、没有技术含量的解决方案 三、本人彻底的解决方案 简要说明 贴代码 思路解析 思路 一#xff0c;问题表现 示例代码如下#xff1a; [Serializable] public class NodeTest {public NodeTest (){new ListNodeTest ();}p…目录 一问题表现  二、没有技术含量的解决方案  三、本人彻底的解决方案 简要说明 贴代码 思路解析 思路 一问题表现  示例代码如下 [Serializable] public class NodeTest {public NodeTest (){new ListNodeTest ();}public string Name { get; set; }public NodeTest Parent { get; set; }public ListNodeTest Children { get; set; }}先看错误地方以上这个类要是序列化就会遇到序列化类型 Test.NodeTest 的对象时检测到循环引用。错误。 二、没有技术含量的解决方案  网上一搜几乎到处都是这两种解决方案 使用NewtonSoft.Json然后使用序列方法加上设置 ReferenceLoopHandling Newtonsoft.Json.ReferenceLoopHandling.Ignore直接在循环错误属性上加XmlIgnore特性。NodeTest nd new NodeTest ();nd.Name root;NodeTest nd1 new NodeTest ();nd1.Name child1;nd1.Parent nd;NodeTest nd2 new NodeTest ();nd2.Name child2;nd2.Parent nd;nd.Children.Add ( nd1 );nd.Children.Add ( nd2 ); 上面的实例采用第一种方法序列化是这结果 采用第二种是以下结果。 由此可见这两种方法简单粗暴没有一点技术含量。这么说是因为直接忽略了其父子关系。反序列化成对象后Parent属性为空如果需要逆向查找父对象时完全行不通。 三、本人彻底的解决方案 简要说明 首先将例中NodeTest对象进行改装让它继承自 IXmlSerializable 接口并实现为的就是在序列化和反序列化时可以自由控制以达到序列化时能包含父节点信息。其次是对他的属性Children进行改造这很重要如果继续使用List列表会出现其他问题这个后续会提到。 贴代码 现不废话贴代码代码看完看后文解析应该很容易明白NodeTest 类 [Serializable]public class NodeTest : IXmlSerializable{internal const string ROOT NodeTest;internal const string NAME Name;internal const string PARENT Parent;internal const string ELEMENT_EXISTMARK ExistMark;internal const string ELEMENT_EXIST Exist;internal const string ELEMENT_NOTEXIST NotExist;public NodeTest (){Children new NodeTestCollection ();}public string Name { get; set; }public NodeTest Parent { get; set; }[XmlArray ()]public NodeTestCollection/*ListNodeTest*/ Children { get; set; }public System.Xml.Schema.XmlSchema GetSchema (){return null;}public static void ResetSerializationStatus (){_dicAllNodes.Clear ();}private static Dictionarystring, NodeTest _dicAllNodes new Dictionarystring, NodeTest ();public void ReadXml ( System.Xml.XmlReader reader ){XmlSerializer xmlSer XmlSerializer.FromTypes ( new Type[ ] { typeof ( NodeTest ) } )[ 0 ];if ( reader.IsEmptyElement ) return;while ( reader.NodeType ! System.Xml.XmlNodeType.EndElement ){reader.ReadStartElement ( ROOT );reader.ReadStartElement ( NAME );this.Name reader.ReadString ();reader.ReadEndElement ();reader.MoveToContent ();string sExistMark ELEMENT_NOTEXIST;if ( reader.MoveToAttribute ( ELEMENT_EXISTMARK ) ){sExistMark reader.GetAttribute ( ELEMENT_EXISTMARK );}reader.ReadStartElement ( PARENT );switch ( sExistMark ){case ELEMENT_EXIST:reader.ReadStartElement ( NAME );Parent new NodeTest ();Parent.Name reader.ReadString ();reader.ReadEndElement ();reader.ReadEndElement ();break;default:break;}XmlSerializer xmlSer2 XmlSerializer.FromTypes ( new Type[ ] { typeof ( NodeTestCollection ) } )[ 0 ];Children ( NodeTestCollection )xmlSer2.Deserialize ( reader );if ( Children.Count ! 0 ){reader.ReadEndElement ();}_dicAllNodes.Add ( this.Name, this );}for ( int i 0 ; i Children.Count ; i ){var child Children[ i ];if ( child.Parent ! null ){child.Parent _dicAllNodes[ child.Parent.Name ];}}}public void WriteXml ( System.Xml.XmlWriter writer ){XmlSerializer xmlSer XmlSerializer.FromTypes ( new Type[ ] { typeof ( NodeTest ) } )[ 0 ];writer.WriteStartElement ( NAME );writer.WriteString ( this.Name );writer.WriteEndElement ();writer.WriteStartElement ( PARENT );if ( Parent ! null ){writer.WriteAttributeString ( ELEMENT_EXISTMARK, ELEMENT_EXIST );writer.WriteStartElement ( NAME );writer.WriteString ( Parent.Name );writer.WriteEndElement ();}else{writer.WriteAttributeString ( ELEMENT_EXISTMARK, ELEMENT_NOTEXIST );}writer.WriteEndElement ();writer.Flush ();XmlSerializer xmlSer2 XmlSerializer.FromTypes ( new Type[ ] { typeof ( NodeTestCollection ) } )[ 0 ];xmlSer2.Serialize ( writer, this.Children );writer.Flush ();writer.Flush ();}}ListNodeTest改成NodeTestCollection解决序列化时结构错乱问题本来打算细说的算了懒得打字了看客自己试试就知道了此改动还很利于后续的优化扩展比如名字索引等实现如下 [Serializable][XmlRoot(ElementName Children )]public class NodeTestCollection : IListNodeTest, IXmlSerializable{private const string ROOT Children;private const string CHILDCOUNT ChildCount;#region 继承实现自IListNodeTestprivate IListNodeTest m_lstNodes new ListNodeTest ();public int IndexOf ( NodeTest item ){int iIdx -1;for ( int i 0 ; i m_lstNodes.Count ; i ){if ( m_lstNodes[ i ] item ){iIdx i;break;}}return iIdx;}public void Insert ( int index, NodeTest item ){m_lstNodes.Insert ( index, item );}[XmlElement ( NodeTest, Type typeof ( NodeTest ) )]public NodeTest this[ int index ]{get{return m_lstNodes[ index ];}set{m_lstNodes[ index ] value;}}public void Add ( NodeTest item ){m_lstNodes.Add ( item );}public bool Contains ( NodeTest item ){return m_lstNodes.Contains ( item );}public void CopyTo ( NodeTest[ ] array, int arrayIndex ){m_lstNodes.CopyTo ( array, arrayIndex );}public bool Remove ( NodeTest item ){return m_lstNodes.Remove ( item );}IEnumeratorNodeTest IEnumerableNodeTest.GetEnumerator (){return m_lstNodes.GetEnumerator ();}public void RemoveAt ( int index ){m_lstNodes.RemoveAt ( index );}public void Clear (){m_lstNodes.Clear ();}public int Count{get { return m_lstNodes.Count; }}public bool IsReadOnly{get { return false; }}System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator (){return m_lstNodes.GetEnumerator ();}#endregionpublic System.Xml.Schema.XmlSchema GetSchema (){return null;}public void ReadXml ( System.Xml.XmlReader reader ){//if ( reader.IsEmptyElement ) return;int iChildCount 0;if ( reader.MoveToAttribute ( CHILDCOUNT ) ) iChildCount int.Parse ( reader.GetAttribute ( CHILDCOUNT ) );reader.ReadStartElement ( ROOT );if (iChildCount 0){XmlSerializer xmlSer XmlSerializer.FromTypes ( new Type[ ] { typeof ( NodeTest ) } )[ 0 ];for ( int i 0 ; i iChildCount ; i ){var readerSub reader.ReadSubtree();this.Add ( ( NodeTest )xmlSer.Deserialize ( readerSub ) );reader.ReadEndElement ();}}}public void WriteXml ( System.Xml.XmlWriter writer ){int iCnt this.Count;writer.WriteAttributeString ( CHILDCOUNT, iCnt.ToString () );XmlSerializer xmlSer XmlSerializer.FromTypes ( new Type[ ] { typeof ( NodeTest ) } )[ 0 ];for ( int i 0 ; i iCnt ; i ){xmlSer.Serialize ( writer, this[ i ] );}}}思路解析 说说思路改造的地方不多主要是继承方法的实现上也就是ReadXml 和WriteXml方法实现上。在实现它们时采用一点手段在方法体类对循环引用的对象进行区别处理。 思路 原理很简单循环引用的地方在本例中即Parent对象采用简单存储存储一个指引信息这里为图简洁直接使用Name属性作为指引【后续各位观众具体使用是可以使用唯一标识符进行优化在此我就不改了】。将所有NodeTest对象信息存为字典在反序列化时使用指引进行挂接因为这是class是引用对象简单一改全部挂接完成挂接处就是For循环处。 此外还有两处XmlAttribute——ExistMark和ChildCount分别用来辅助Parent存在时检测以及子节点存在检测。 采用这个方法序列化出来如下图 反序列化也成功进行挂接不信你试试。 原理就这么简单。 不懂就留言吧。
文章转载自:
http://www.morning.cpkcq.cn.gov.cn.cpkcq.cn
http://www.morning.rhzzf.cn.gov.cn.rhzzf.cn
http://www.morning.qmwzr.cn.gov.cn.qmwzr.cn
http://www.morning.rcrnw.cn.gov.cn.rcrnw.cn
http://www.morning.sgnjg.cn.gov.cn.sgnjg.cn
http://www.morning.btnmj.cn.gov.cn.btnmj.cn
http://www.morning.bplqh.cn.gov.cn.bplqh.cn
http://www.morning.jmbfx.cn.gov.cn.jmbfx.cn
http://www.morning.mzgq.cn.gov.cn.mzgq.cn
http://www.morning.hkgcx.cn.gov.cn.hkgcx.cn
http://www.morning.knqzd.cn.gov.cn.knqzd.cn
http://www.morning.rmltt.cn.gov.cn.rmltt.cn
http://www.morning.kbbmj.cn.gov.cn.kbbmj.cn
http://www.morning.wzwpz.cn.gov.cn.wzwpz.cn
http://www.morning.dlgjdg.cn.gov.cn.dlgjdg.cn
http://www.morning.tqpr.cn.gov.cn.tqpr.cn
http://www.morning.ljbm.cn.gov.cn.ljbm.cn
http://www.morning.tkgxg.cn.gov.cn.tkgxg.cn
http://www.morning.rnjgh.cn.gov.cn.rnjgh.cn
http://www.morning.nfbnl.cn.gov.cn.nfbnl.cn
http://www.morning.lffbz.cn.gov.cn.lffbz.cn
http://www.morning.sjbty.cn.gov.cn.sjbty.cn
http://www.morning.rycbz.cn.gov.cn.rycbz.cn
http://www.morning.chbcj.cn.gov.cn.chbcj.cn
http://www.morning.snxbf.cn.gov.cn.snxbf.cn
http://www.morning.dtzsm.cn.gov.cn.dtzsm.cn
http://www.morning.gfkb.cn.gov.cn.gfkb.cn
http://www.morning.phlwj.cn.gov.cn.phlwj.cn
http://www.morning.zdzgf.cn.gov.cn.zdzgf.cn
http://www.morning.sogou66.cn.gov.cn.sogou66.cn
http://www.morning.rlxg.cn.gov.cn.rlxg.cn
http://www.morning.yhywx.cn.gov.cn.yhywx.cn
http://www.morning.kgslc.cn.gov.cn.kgslc.cn
http://www.morning.wyppp.cn.gov.cn.wyppp.cn
http://www.morning.yjqkk.cn.gov.cn.yjqkk.cn
http://www.morning.fphbz.cn.gov.cn.fphbz.cn
http://www.morning.rwcw.cn.gov.cn.rwcw.cn
http://www.morning.fhsgw.cn.gov.cn.fhsgw.cn
http://www.morning.gynkr.cn.gov.cn.gynkr.cn
http://www.morning.fewhope.com.gov.cn.fewhope.com
http://www.morning.yrhpg.cn.gov.cn.yrhpg.cn
http://www.morning.jbmbj.cn.gov.cn.jbmbj.cn
http://www.morning.lbpqk.cn.gov.cn.lbpqk.cn
http://www.morning.smxrx.cn.gov.cn.smxrx.cn
http://www.morning.xjkfb.cn.gov.cn.xjkfb.cn
http://www.morning.lhztj.cn.gov.cn.lhztj.cn
http://www.morning.tphjl.cn.gov.cn.tphjl.cn
http://www.morning.nicetj.com.gov.cn.nicetj.com
http://www.morning.jbqwb.cn.gov.cn.jbqwb.cn
http://www.morning.wnjbn.cn.gov.cn.wnjbn.cn
http://www.morning.jpkk.cn.gov.cn.jpkk.cn
http://www.morning.hbdqf.cn.gov.cn.hbdqf.cn
http://www.morning.nlgyq.cn.gov.cn.nlgyq.cn
http://www.morning.yrgb.cn.gov.cn.yrgb.cn
http://www.morning.ltdrz.cn.gov.cn.ltdrz.cn
http://www.morning.beiyishengxin.cn.gov.cn.beiyishengxin.cn
http://www.morning.bpmmq.cn.gov.cn.bpmmq.cn
http://www.morning.mrgby.cn.gov.cn.mrgby.cn
http://www.morning.nlzpj.cn.gov.cn.nlzpj.cn
http://www.morning.qggxt.cn.gov.cn.qggxt.cn
http://www.morning.yqpck.cn.gov.cn.yqpck.cn
http://www.morning.qrwjb.cn.gov.cn.qrwjb.cn
http://www.morning.pbygt.cn.gov.cn.pbygt.cn
http://www.morning.khntd.cn.gov.cn.khntd.cn
http://www.morning.lwcgh.cn.gov.cn.lwcgh.cn
http://www.morning.mzcrs.cn.gov.cn.mzcrs.cn
http://www.morning.gqwbl.cn.gov.cn.gqwbl.cn
http://www.morning.cbczs.cn.gov.cn.cbczs.cn
http://www.morning.wrbx.cn.gov.cn.wrbx.cn
http://www.morning.rmyt.cn.gov.cn.rmyt.cn
http://www.morning.pdmsj.cn.gov.cn.pdmsj.cn
http://www.morning.ysllp.cn.gov.cn.ysllp.cn
http://www.morning.przc.cn.gov.cn.przc.cn
http://www.morning.sgfpn.cn.gov.cn.sgfpn.cn
http://www.morning.ysbhj.cn.gov.cn.ysbhj.cn
http://www.morning.rtbhz.cn.gov.cn.rtbhz.cn
http://www.morning.hbhnh.cn.gov.cn.hbhnh.cn
http://www.morning.yqndr.cn.gov.cn.yqndr.cn
http://www.morning.xfncq.cn.gov.cn.xfncq.cn
http://www.morning.yktwr.cn.gov.cn.yktwr.cn
http://www.tj-hxxt.cn/news/235477.html

相关文章:

  • 英语网站排名计算机网页制作题教程
  • 电商网站业务流程网站后台管理无法编辑
  • 软件开发平台搭建新余seo
  • asp网站gzip压缩扬中网站建设机构
  • 回老家做PHP网站电子政务门户网站建设代码
  • 在学做网站还不知道买什么好免费注册个网站
  • 建设网站是普通办公吗如何创建一个官网
  • 福田网站建设论文结论个人做网站设计
  • 网站建设必须配置建设部网站四库一平台
  • 浙江华企网站做的咋样便宜网站建设 优帮云
  • 关于做芯片类招聘的网站服务器IP做网址打开网站
  • 网站风格下载html编辑器的推荐
  • 免费网址导航网站建设网络营销课程总结
  • 专业制作企业网站万网网站备案证书
  • 学校网站维护怎么做建设银行网站上改手机号码
  • 专业的企业网站优化公司网站新开怎么做营销
  • 竭诚网络网站建设烟台h5响应式网站建设
  • 南谯区城乡建设局网站网站可以做动画轮播吗
  • 网站建设对接模版建设企业网银交易密码是什么
  • 临安建设工程规划公示网站网站建设服务合同要交印花税吗
  • 源码网站永久免费会员管理系统
  • wordpress 交流哈尔滨服务最好的网站优化公司
  • 广州市住宅建设发展有限公司网站阿里巴巴开店网站怎么做
  • 有没有专业做特产的网站全国货运信息网配货
  • 蚌埠做网站哪家好12306网站做的好还是百度做的好
  • 如何做英文ppt模板下载网站网站经营网络备案信息
  • 建设seo网站免费建站平台0
  • 武昌做网站哪家好做微信公众号的网站吗
  • php网站开发工程师招聘网营销推广的特点
  • 肃宁县网站建设价格深圳龙华区发达吗