Exemple #1
0
        // Token: 0x06000062 RID: 98 RVA: 0x00004348 File Offset: 0x00002548
        public void SetStateType(Type stateType)
        {
            this.serializedType.stateType = stateType;
            stateType = this.serializedType.stateType;
            if (stateType == null)
            {
                return;
            }
            IEnumerable <FieldInfo> first  = stateType.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy).Where(new Func <FieldInfo, bool>(EntityStateManager.StateInfo.FieldHasSerializeAttribute));
            IEnumerable <FieldInfo> second = (from fieldInfo in stateType.GetFields(BindingFlags.Static | BindingFlags.Public)
                                              where fieldInfo.DeclaringType == stateType
                                              select fieldInfo).Where(new Func <FieldInfo, bool>(EntityStateManager.StateInfo.FieldLacksNonSerializedAttribute));
            List <FieldInfo> list = first.Concat(second).ToList <FieldInfo>();
            Dictionary <FieldInfo, EntityStateManager.StateInfo.Field> dictionary = new Dictionary <FieldInfo, EntityStateManager.StateInfo.Field>();

            using (List <FieldInfo> .Enumerator enumerator = list.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    FieldInfo fieldInfo = enumerator.Current;
                    EntityStateManager.StateInfo.Field field = this.stateFieldList.Find((EntityStateManager.StateInfo.Field item) => item.GetFieldName() == fieldInfo.Name);
                    if (field == null)
                    {
                        Debug.LogFormat("Could not find field {0}.{1}. Initializing new field.", new object[]
                        {
                            stateType.Name,
                            fieldInfo.Name
                        });
                        field = new EntityStateManager.StateInfo.Field(fieldInfo.Name);
                    }
                    dictionary[fieldInfo] = field;
                }
            }
            this.stateFieldList.Clear();
            foreach (FieldInfo fieldInfo2 in list)
            {
                EntityStateManager.StateInfo.Field field2 = dictionary[fieldInfo2];
                field2.owner = this;
                field2.SetFieldInfo(fieldInfo2);
                this.stateFieldList.Add(field2);
            }
        }
Exemple #2
0
        // Token: 0x06000065 RID: 101 RVA: 0x000045BC File Offset: 0x000027BC
        public Action <EntityState> GenerateInstanceFieldInitializerDelegate()
        {
            Type stateType = this.serializedType.stateType;

            if (stateType == null)
            {
                return(null);
            }
            List <EntityStateManager.StateInfo.FieldValuePair> list = new List <EntityStateManager.StateInfo.FieldValuePair>();

            for (int i = 0; i < this.stateFieldList.Count; i++)
            {
                EntityStateManager.StateInfo.Field          field          = this.stateFieldList[i];
                EntityStateManager.StateInfo.FieldValuePair fieldValuePair = new EntityStateManager.StateInfo.FieldValuePair
                {
                    fieldInfo = stateType.GetField(field.GetFieldName(), BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy),
                    value     = field.valueAsSystemObject
                };
                if (!(fieldValuePair.fieldInfo == null))
                {
                    list.Add(fieldValuePair);
                }
            }
            EntityStateManager.StateInfo.FieldValuePair[] fieldValuePairs = list.ToArray();
            if (fieldValuePairs.Length == 0)
            {
                return(null);
            }
            return(delegate(EntityState entityState)
            {
                for (int j = 0; j < fieldValuePairs.Length; j++)
                {
                    EntityStateManager.StateInfo.FieldValuePair fieldValuePair2 = fieldValuePairs[j];
                    fieldValuePair2.fieldInfo.SetValue(entityState, fieldValuePair2.value);
                }
            });
        }