/// <summary> /// 创建字段信息 /// </summary> private void buildFields() { foreach (FieldInfo field in baseType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)) { if ((fieldType = field.FieldType).IsPrimitive || fieldType.IsPointer || fieldType.IsEnum) { type.Type.Size += getMemorySize(fieldType); } else if (fieldType.IsValueType) { valueType = buildValueType(fieldType); if (valueType.Fields == null) { type.Type.Size += valueType.Type.Size; } else { type.Add(field); } } else { type.Add(field); if (!fieldType.IsValueType) { type.Type.Size = fastCSharp.pub.MemoryBytes; } } } }
/// <summary> /// 创建值类型 /// </summary> /// <param name="type"></param> private typeInfo buildValueType(Type type) { typeInfo valueType; if (!types.TryGetValue(type, out valueType)) { valueType = new typeInfo { Type = new type { FullName = type.fullName() } }; foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if ((fieldType = field.FieldType).IsPrimitive || fieldType.IsPointer || fieldType.IsEnum) { valueType.Type.Size += getMemorySize(fieldType); } else if (fieldType.IsValueType) { valueType = buildValueType(fieldType); if (valueType.Fields == null) { valueType.Type.Size += valueType.Type.Size; } else { valueType.Add(field); } } else { valueType.Add(field); if (!fieldType.IsValueType) { valueType.Type.Size = fastCSharp.pub.MemoryBytes; } } } } return(valueType); }