Source/ElementSerializer.cs
(开头部分) 16KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Text;
using System.Xml;
using System.Reflection;
using System.Drawing;
using System.ComponentModel;
#if DOTNETBAR
namespace DevComponents.DotNetBar
#else
namespace DevComponents.Tree
#endif
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Method | AttributeTargets.Field)]
public class DevCoSerialize : Attribute
{
public DevCoSerialize(){}
}
/// <summary>
/// Represents class that can serialize compatible marked properties.
/// </summary>
public class ElementSerializer
{
private static string XmlImageName="image";
private static string XmlIconName="icon";
private static string XmlAttributeName="name";
// private static string XmlCollectionName="collection";
// private static string XmlTypeName="type";
// private static string XmlObjectName="object";
public static void Serialize(object element, XmlElement xmlElem)
{
PropertyInfo[] propInfo = element.GetType().GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public);
foreach (PropertyInfo prop in propInfo)
{
if (prop.GetCustomAttributes(typeof(DevCoSerialize), true).Length > 0)
{
// Check whether property needs to be serialized
object[] attributesDefaultValue=prop.GetCustomAttributes(typeof(DefaultValueAttribute), true);
if (attributesDefaultValue.Length > 0)
{
DefaultValueAttribute att=attributesDefaultValue[0] as DefaultValueAttribute;
object propertyValue = prop.GetValue(element, null);
if(propertyValue==att.Value)
continue;
if(propertyValue!=null && att.Value!=null && propertyValue.Equals(att.Value))
continue;
}
else if(element.GetType().GetMethod("ShouldSerialize" + prop.Name,BindingFlags.Default | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)!=null)
{
MethodInfo mi=element.GetType().GetMethod("ShouldSerialize" + prop.Name,BindingFlags.Default | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
object result=mi.Invoke(element,null);
if(result is bool && !((bool)result))
continue;
}
string attributeName=XmlConvert.EncodeName(prop.Name);
Type t=prop.PropertyType;
if (t.IsPrimitive || t == typeof(string) || t.IsEnum)
后面还有 308 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。