public static GetCompoundInfo ( |
||
type | ||
Résultat |
public RecordInfo(Type type) { if (!typeof(Record).IsAssignableFrom(type)) { throw new ArgumentException("Record type is not derived from Record: " + type.FullName); } var attribute = type.GetCustomAttributes(typeof(RecordAttribute), false).Cast <RecordAttribute>().FirstOrDefault();// .NET 4.5: type.GetCustomAttribute<RecordAttribute>(); if (attribute == null) { throw new ArgumentException("Record type is missing required atribute: " + type.FullName); } signature = attribute.Signature; var va = type.GetCustomAttributes(typeof(VersionAttribute), false).Cast <VersionAttribute>().FirstOrDefault();// .NET 4.5: type.GetCustomAttribute<RecordAttribute>(); if (va != null) { version = va.Version; } var da = type.GetCustomAttributes(typeof(DummyAttribute), false).Cast <DummyAttribute>().FirstOrDefault(); isDummyRecord = da != null; ctor = type.GetConstructor(paramlessTypes); compound = InfoProvider.GetCompoundInfo(type); }
public override Field CopyField() { var fldinfo = InfoProvider.GetFieldInfo(GetType()); var other = fldinfo.CreateInstance(); var compinfo = InfoProvider.GetCompoundInfo(GetType()); compinfo.Copy(this, other); return(other); }
internal void ReadRecord(RecordReader reader, bool lazyLoading) { var compinfo = InfoProvider.GetCompoundInfo(GetType()); var recinfo = InfoProvider.GetRecordInfo(GetType()); BeforeRead(reader); reader.BeginReadFields(0); HashSet <string> remainingPropertiesToLoad = lazyLoading ? new HashSet <string>(compinfo.Members.Values.Where(m => m.IsLazy).SelectMany(m => m.FieldNames)) : null; foreach (string propertyName in reader.FindFields()) { MemberInfo meminf = compinfo.FindMember(propertyName); if (meminf != null) { reader.ReadField(this, propertyName, meminf, 0); if (remainingPropertiesToLoad != null) { if (!meminf.IsListType && !meminf.IsDynamic) { remainingPropertiesToLoad.Remove(propertyName); } if (!remainingPropertiesToLoad.Any()) { // Loaded all properties that were supposed to reader.CancelFindFields(); break; } } } else if (lazyLoading || recinfo.IsDummyRecord) { // Prevent segment errors when not all properties were expected to be consumed reader.SeekEndOfSegment(); } else { Log.Warning("Unexpected record property: {0}", propertyName); } } reader.EndReadFields(0); //// Make sure list properties that were supposed to be loaded are not null //foreach (MemberInfo meminfo in members.Where(m => m.Value.IsListType && (fieldsToLoad == null || fieldsToLoad.Contains(m.Key))).Select(m => m.Value)) //{ // meminfo.EnsureListCreated(this); //} AfterRead(reader); }
public bool Equals(GenericFormRecord other) { // Compare raw flags if (RawFlags != other.RawFlags) { return(false); } var compinfo = InfoProvider.GetCompoundInfo(GetType()); return(compinfo.Equate(this, other)); }
internal override void WriteField(RecordWriter writer) { BeforeWrite(writer); var compinfo = InfoProvider.GetCompoundInfo(GetType()); foreach (var meminfo in compinfo.Members.Values.Distinct()) { writer.WriteField(this, meminfo); } AfterWrite(writer); }
internal virtual void ReadCompoundField(RecordReader reader, string fieldName, int depth) { var members = InfoProvider.GetCompoundInfo(GetType()).Members; if (!members.ContainsKey(fieldName)) { throw new InvalidProgramException("Unexpected field name while reading a compound field: " + fieldName); } var meminf = members[fieldName]; reader.ReadField(this, fieldName, meminf, depth); }
internal void OnComplete(RecordReader reader, int depth) { reader.EndReadFields(depth); // Make sure list fields that were supposed to be loaded are not null var members = InfoProvider.GetCompoundInfo(GetType()).Members; foreach (MemberInfo meminfo in members.Where(m => m.Value.IsListType).Select(m => m.Value)) { meminfo.EnsureListCreated(this); } AfterRead(reader); }
public GenericFormRecord CopyRecord() { var recinfo = InfoProvider.GetRecordInfo(GetType()); var other = recinfo.CreateInstance(); BeforeCopy(other); // Copy raw flags and version other.RawFlags = RawFlags; other.Version = Version; var compinfo = InfoProvider.GetCompoundInfo(GetType()); compinfo.Copy(this, other); AfterCopy(other); return(other); }
public Compound() { // Initialize fields that should not be null var members = InfoProvider.GetCompoundInfo(GetType()).Members; foreach (var meminfo in members.Values.Distinct().Where(m => m.Initialize)) { if (meminfo.IsListType) { // Instantiate list field meminfo.EnsureListCreated(this); } else if (!meminfo.IsPrimitiveType) { // Instantiate complex fields var fieldinfo = InfoProvider.GetFieldInfo(meminfo.FieldType); meminfo.SetValue(this, fieldinfo.CreateInstance()); } } }
public override IEnumerable <uint> GetReferencedFormIds() { var compinfo = InfoProvider.GetCompoundInfo(GetType()); return(compinfo.GetReferencedFormIds(this)); }
public override bool Equals(Field other) { var compinfo = InfoProvider.GetCompoundInfo(GetType()); return(compinfo.Equate(this, other)); }