static PropertyTuple[] GetPropertiesWithVerify(TypeBuilder typeBuilder) { var lastIndex = -1; var list = new List <PropertyTuple>(); // getproperties contains verify. foreach (var p in DynamicObjectDescriptor.GetMembers(typeof(T), true)) { var propInfo = p.Item2; var index = p.Item1; var formatter = (IFormatter)typeof(Formatter <>).MakeGenericType(propInfo.MemberType).GetTypeInfo().GetProperty("Default").GetValue(null, Type.EmptyTypes); if (formatter == null) { throw new InvalidOperationException("Circular reference does not supported. " + typeof(T).Name + "." + propInfo.Name); } if (formatter.GetLength() == null) { if (CacheSegment.CanAccept(propInfo.MemberType)) { var fieldBuilder = typeBuilder.DefineField("<>_" + propInfo.Name, typeof(CacheSegment <>).MakeGenericType(propInfo.MemberType), FieldAttributes.Private); list.Add(new PropertyTuple { Index = index, PropertyInfo = propInfo.PropertyInfoUnsafe, IsFixedSize = false, SegmentField = fieldBuilder, IsCacheSegment = true }); } else { var fieldBuilder = typeBuilder.DefineField("<>_" + propInfo.Name, propInfo.MemberType, FieldAttributes.Private); list.Add(new PropertyTuple { Index = index, PropertyInfo = propInfo.PropertyInfoUnsafe, IsFixedSize = false, SegmentField = fieldBuilder }); } } else { list.Add(new PropertyTuple { Index = index, PropertyInfo = propInfo.PropertyInfoUnsafe, IsFixedSize = true, FixedSize = formatter.GetLength().Value }); } lastIndex = index; } return(list.OrderBy(x => x.Index).ToArray()); }
public static int SerializeCacheSegment <TTypeResolver, T>(ref byte[] targetBytes, int startOffset, int offset, int index, ref CacheSegment <TTypeResolver, T> segment) where TTypeResolver : ITypeResolver, new() { BinaryUtil.WriteInt32(ref targetBytes, startOffset + (8 + 4 * index), offset - startOffset); return(segment.Serialize(ref targetBytes, offset)); }
public static int SerializeCacheSegment <T>(ref byte[] targetBytes, int startOffset, int offset, int index, CacheSegment <T> segment) { BinaryUtil.WriteInt32(ref targetBytes, startOffset + (8 + 4 * index), offset); return(segment.Serialize(ref targetBytes, offset)); }