Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does XML convert the internal code of the machine into information that is easy for people to understand

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

本篇内容介绍了"XML怎么将机器内码转换为人们容易理解的信息"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

转换对象如下:

/**////

///翻译类,将内部码翻译成容易理解的中文

///

///

///根据配置文件中的信息,将系统内部码(错误码、成功码)翻译成中文(或人容易理解的语言)。

///

publicstaticclassTranslation

...{

privatestaticSystem.IO.FileSystemWatcherwatcher;

privatestaticXmlDocumentcontent;

privatestaticstringconfigFile;

privatestaticobjectlocker=newobject();

/**////

///加载配置文件

///

///

publicstaticvoidConfigure(stringconfigFile)

...{

LoadFile(configFile);

if(watcher!=null)

...{

watcher.Dispose();

}

watcher=newFileSystemWatcher(Path.GetDirectoryName(configFile),Path.GetFileName(configFile));

watcher.Changed =newFileSystemEventHandler(watcher_Changed);

}

/**////

///加载默认配置文件

///

publicstaticvoidConfigure()

...{

if(System.Web.HttpContext.Current!=null)

...{

Configure(System.Web.HttpContext.Current.Server.MapPath("~/translation.config"));

}

else

...{

Configure(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase "/" "translation.config");

}

}

/**////

///加载文件内容

///

///

privatestaticvoidLoadFile(stringconfigFile)

...{

lock(locker)

...{

XmlDocumentdoc=newXmlDocument();

doc.Load(configFile);

content=doc;

Translation.configFile=configFile;

}

}

/**////

///当文件变更时,从新加载文件

///

///

///

privatestaticvoidwatcher_Changed(objectsender,FileSystemEventArgse)

...{

LoadFile(configFile);

}

/**////

///获取Enum的解释,如果Enum有Flag标记,则使用逗号分隔各个解释

///

///

///

publicstaticstringGetEnumDescription(EnumenumValue)

...{

returnGetEnumDescription(enumValue,",");

}

/**////

///获取Enum的解释,如果Enum有Flag标记,则使用sparator分隔各个解释

///

///

///

///

publicstaticstringGetEnumDescription(EnumenumValue,stringsparator)

...{

Typetype=enumValue.GetType();

//检查类型是否有Flags特性

object[]attrs=type.GetCustomAttributes(typeof(FlagsAttribute),false);

if(attrs.Length>0)

...{

StringBuilderbuilder=newStringBuilder();

Arrayarr=Enum.GetValues(type);

foreach(Enumenuinarr)//循环获取每一个值的解释

...{

if((Convert.ToUInt64(enumValue)&Convert.ToUInt64(enu))==Convert.ToUInt64(enu))//判断是否有这个值

...{

builder.Append(GetEnumDes(type,enu.ToString()));

builder.Append(sparator);

}

}

if(builder.Length!=0)//拿掉最后的分隔符

builder.Remove(builder.Length-sparator.Length,sparator.Length);

returnbuilder.ToString();

}

else

...{

returnGetEnumDes(type,enumValue.ToString());

}

}

/**////

///获取某一Enum类型值的解释

///

///

///

///

privatestaticstringGetEnumDes(Typetype,stringvalue)

...{

stringxquery="/translation/enum/" type.FullName "/" value;

XmlNodenode=content.SelectSingleNode(xquery);

if(node!=null)

returnnode.InnerText;

else

returnvalue;

}

/**////

///翻译指定值

///

///

///

publicstaticstringGetValueDescription(objectobj)

...{

returnGetValueDescription("default",obj);

}

/**////

///在指定组中翻译指定值

///

///

///

///

publicstaticstringGetValueDescription(stringgroup,objectobj)

...{

if(obj==null)

return"null";

stringxquery="/translation/description[@group='" group "']/add[@key='" obj.ToString() "']/@value";

XmlNodenode=content.SelectSingleNode(xquery);

if(node==null)

returnobj.ToString();

else

returnnode.Value;

}

}

"XML怎么将机器内码转换为人们容易理解的信息"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report