private static GetSet[][] GetAccessors(RuntimeTypeHandle type) { lock (PropertyAccess) { int index = 0; GetSet[][][] collection; if (!PropertyAccess.TryGetValue(type, out collection)) { collection = new GetSet[3][][]; PropertyAccess[type] = collection; } var accessors = collection[index]; if (accessors == null) { object vanilla = GetVanilla(type); bool canGetVanilla = false; if(vanilla != null) { canGetVanilla = !vanilla.Equals(null); } var acs = new List<GetSet>(); var props = UnitySerializer.GetPropertyInfo(type) .Where(p=>p.Name != "hideFlags") .Select(p=> new { priority = ((SerializationPriorityAttribute)p.GetCustomAttributes(false).FirstOrDefault(a=>a is SerializationPriorityAttribute)) ?? new SerializationPriorityAttribute(100), info=p}) .OrderBy(p=>p.priority.Priority).Select(p=>p.info); foreach (var p in props) { var getSet = new GetSetGeneric(p); if(!canGetVanilla) { getSet.Vanilla = null; } else { getSet.Vanilla = getSet.Get(vanilla); } acs.Add(getSet); } accessors = new GetSet[4][]; accessors[0] = acs.Where(a=>!a.IsStatic).ToArray(); accessors[2] = acs.ToArray(); acs.Clear(); var fields = UnitySerializer.GetFieldInfo(type) .Where(f=>f.Name != "hideFlags") .Select(p=> new { priority = ((SerializationPriorityAttribute)p.GetCustomAttributes(false).FirstOrDefault(a=>a is SerializationPriorityAttribute)) ?? new SerializationPriorityAttribute(100), info=p}) .OrderBy(p=>p.priority.Priority).Select(p=>p.info); foreach (var f in fields) { var getSet = new GetSetGeneric(f); if(!canGetVanilla) { getSet.Vanilla = null; } else { getSet.Vanilla = getSet.Get(vanilla); } acs.Add(getSet); } accessors[1] = acs.Where(a=>!a.IsStatic).ToArray(); accessors[3] = acs.ToArray(); collection[index] = accessors; } return accessors; } }
private static GetSet[][] GetAccessors(Type type) { lock (PropertyAccess) { var index = (UnitySerializer.IsChecksum ? 1 : 0) + (UnitySerializer.IsChecksum && UnitySerializer.IgnoreIds ? 1 : 0); GetSet[][][] collection; if (!PropertyAccess.TryGetValue(type, out collection)) { collection = new GetSet[3][][]; PropertyAccess[type] = collection; } var accessors = collection[index]; if (accessors == null) { object vanilla = GetVanilla(type); bool canGetVanilla = false; if (vanilla != null) { canGetVanilla = !vanilla.Equals(null); } var acs = new List <GetSet>(); var props = UnitySerializer.GetPropertyInfo(type) .Where(p => p.Name != "hideFlags") .Select(p => new { priority = ((SerializationPriorityAttribute)p.GetCustomAttributes(false).FirstOrDefault(a => a is SerializationPriorityAttribute)) ?? new SerializationPriorityAttribute(100), info = p }) .OrderBy(p => p.priority.Priority).Select(p => p.info); foreach (var p in props) { var getSet = new GetSetGeneric(p); if (!canGetVanilla) { getSet.Vanilla = null; } else { getSet.Vanilla = getSet.Get(vanilla); } acs.Add(getSet); } accessors = new GetSet[4][]; accessors[0] = acs.Where(a => !a.IsStatic).ToArray(); accessors[2] = acs.ToArray(); acs.Clear(); var fields = UnitySerializer.GetFieldInfo(type) .Where(f => f.Name != "hideFlags") .Select(p => new { priority = ((SerializationPriorityAttribute)p.GetCustomAttributes(false).FirstOrDefault(a => a is SerializationPriorityAttribute)) ?? new SerializationPriorityAttribute(100), info = p }) .OrderBy(p => p.priority.Priority).Select(p => p.info); foreach (var f in fields) { var getSet = new GetSetGeneric(f); if (!canGetVanilla) { getSet.Vanilla = null; } else { getSet.Vanilla = getSet.Get(vanilla); } acs.Add(getSet); } accessors[1] = acs.Where(a => !a.IsStatic).ToArray(); accessors[3] = acs.ToArray(); collection[index] = accessors; } return(accessors); } }