static AltType GetAltType(AltTypes altTypes, Type type, IntPtr declaration) { if (altTypes.ContainsKey(type)) { return(altTypes[type]); } var altType = new AltType(altTypes, type, declaration); //altTypes[type] = altType; return(altType); }
public static AltType GetAltType(AltTypes altTypes, Type type, object value) { if (altTypes.ContainsKey(type)) { return(altTypes[type]); } var ptr = GetPtr(value); IntPtr declaration = IntPtr.Zero; #if !SAFE_COPY //lock (locker) declaration = Marshal.ReadIntPtr(ptr); #endif AltType altType = new AltType(altTypes, type, declaration); return(altType); }
private AltType(AltTypes altTypes, Type type, IntPtr declaration) { Type = type; AltTypes = altTypes; Declaration = declaration; var allFields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); AllRefFields = new List <FieldInfo>(allFields.Where(f => !f.FieldType.IsValueType && f.DeclaringType == type && (INCLUDE_NONSERIALIZED || !f.IsNotSerialized))); //add fields from inherited classes var bType = type.BaseType; IntPtr baseDecl = IntPtr.Zero; if (bType != null && bType != typeof(object) && bType != typeof(ValueType)) { #if !SAFE_COPY //lock (locker) baseDecl = Marshal.ReadIntPtr(declaration, 16); #endif BaseType = GetAltType(altTypes, bType, baseDecl); AllRefFields.AddRange(BaseType.AllRefFields); } AllRefValues = new ArraysQueue <object>(AllRefFields.Count); RefFields = AllRefFields.Where(f => f.DeclaringType == type).ToArray(); #if !SAFE_COPY //lock (locker) fieldsSize = Marshal.ReadInt32(declaration, 4) - 2 * IntPtr.Size; // without sync and declaration valueFieldsSize = fieldsSize - RefFields.Length * IntPtr.Size; if (BaseType != null) { valueFieldsSize -= BaseType.fieldsSize; } if (valueFieldsSize > 0) { data = new byte[valueFieldsSize]; valueFieldsStart = IntPtr.Size + fieldsSize - valueFieldsSize; } AltTypes.Add(type, this); #else ValueFields = allFields.Where(f => f.FieldType.IsValueType && f.DeclaringType == type && !f.IsNotSerialized).ToArray(); #endif }