private static GetSet[][] GetAccessors(RuntimeTypeHandle type)
        {
            lock (PropertyAccess)
            {
                var index = (SilverlightSerializer.IsChecksum ? 1 : 0) + (SilverlightSerializer.IsChecksum && SilverlightSerializer.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)
                {
                    var vanilla = GetVanilla(type);

                    var acs   = new List <GetSet>();
                    var props = SilverlightSerializer.GetPropertyInfo(type);
                    foreach (var p in props)
                    {
                        var gs     = typeof(GetSetGeneric <,>);
                        var tp     = gs.MakeGenericType(new Type[] { Type.GetTypeFromHandle(type), p.PropertyType });
                        var getSet = (GetSet)Activator.CreateInstance(tp, new object[] { p });
                        getSet.Vanilla = getSet.Get(vanilla);
                        acs.Add(getSet);
                    }
                    accessors    = new GetSet[2][];
                    accessors[0] = acs.ToArray();
                    acs.Clear();
                    var fields = SilverlightSerializer.GetFieldInfo(type);
                    foreach (var f in fields)
                    {
                        var gs     = typeof(GetSetGeneric <,>);
                        var tp     = gs.MakeGenericType(new Type[] { Type.GetTypeFromHandle(type), f.FieldType });
                        var getSet = (GetSet)Activator.CreateInstance(tp, new object[] { f });
                        getSet.Vanilla = getSet.Get(vanilla);
                        acs.Add(getSet);
                    }
                    accessors[1] = acs.ToArray();

                    collection[index] = accessors;
                }
                return(accessors);
            }
        }
예제 #2
0
        private static GetSet[][] GetAccessors(RuntimeTypeHandle type)
        {
            lock (PropertyAccess)
            {
                var index = (SilverlightSerializer.IsChecksum ? 1 : 0) + (SilverlightSerializer.IsChecksum && SilverlightSerializer.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)
                {
                    var vanilla = GetVanilla(type);

                    var acs = new List<GetSet>();
                    var props = SilverlightSerializer.GetPropertyInfo(type);
                    foreach (var p in props)
                    {
                        var gs = typeof (GetSetGeneric<,>);
                        var tp = gs.MakeGenericType(new Type[] { Type.GetTypeFromHandle(type), p.PropertyType });
                        var getSet = (GetSet) Activator.CreateInstance(tp, new object[] {p});
                        getSet.Vanilla = getSet.Get(vanilla);
                        acs.Add(getSet);
                    }
                    accessors = new GetSet[2][];
                    accessors[0] = acs.ToArray();
                    acs.Clear();
                    var fields = SilverlightSerializer.GetFieldInfo(type);
                    foreach (var f in fields)
                    {
                        var gs = typeof (GetSetGeneric<,>);
                        var tp = gs.MakeGenericType(new Type[] { Type.GetTypeFromHandle(type), f.FieldType });
                        var getSet = (GetSet) Activator.CreateInstance(tp, new object[] {f});
                        getSet.Vanilla = getSet.Get(vanilla);
                        acs.Add(getSet);
                    }
                    accessors[1] = acs.ToArray();

                    collection[index] = accessors;
                }
                return accessors;
            }
        }
        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;
            }
        }
예제 #4
0
        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);
            }
        }