private void PopulateFieldsImpl(Mode mode) { if (_fields != null) { return; } ThrowOnInitialized(); if (mode == Mode.Auto) { mode = 0; if (_constructor != null) { mode |= Mode.Constructor; } else if (FieldType.GetFields(TypeUtils.AllInstanceMembers).Any(fi => fi.IsInitOnly)) { mode |= Mode.NonPublic | Mode.Constructor; } else { mode |= Mode.NonPublic | Mode.Fields; } } IEnumerable <MemberInfo> members; if ((mode & Mode.Fields) == 0 && (mode & Mode.Properties) == 0) { mode |= Mode.Fields | Mode.Properties; } BindingFlags flags = BindingFlags.Instance | BindingFlags.Public; if ((mode & Mode.NonPublic) != 0) { flags |= BindingFlags.NonPublic; } if ((mode & Mode.Constructor) != 0) { if (_constructor == null) { _constructor = ChooseCtor(); } members = _constructor.GetParameters() .Select(i => FindMatchingMember(i, flags, mode)); } else { members = (mode & Mode.Fields) != 0 ? FieldType.GetFields(flags).Where(i => !i.IsInitOnly) : Enumerable.Empty <MemberInfo>(); if ((mode & Mode.Properties) != 0) { members = members.Concat(FieldType.GetProperties(flags).Where(i => i.CanWrite)); } } IList <SubFieldInfo> fields = new List <SubFieldInfo>(); foreach (MemberInfo mi in members) { bool isField = mi.MemberType == MemberTypes.Field; var mType = mi.PropOrFieldType(); string name = StateName + "." + mi.Name; if (isField && mType.IsNested) { object[] ca = mi.GetCustomAttributes(typeof(FixedBufferAttribute), false); if (ca.Length > 0) { // ((FixedBufferAttribute)ca[0]).Length; throw new NotImplementedException("Fixed arrays are not supported at this time"); } } BaseField fld = StateStore.CreateField(mType, name, true); fields.Add(new SubFieldInfo(mi, fld)); } _fields = fields; }