/// <summary> /// Creates new instance of <see cref="SerializeFieldIDEntry"/> on basis of sent instance. /// </summary> /// <param name="entry">Entry to create new instance upon.</param> public SerializeFieldIDEntry(SerializeIDEntry entry) : this(false) // do not recreate delegates at cloning { SerializeFieldIDEntry fieldEntry = (SerializeFieldIDEntry)entry; // Copy field info. this.FieldInfo = fieldEntry.FieldInfo; this.IncludeAttribute = fieldEntry.IncludeAttribute; // Copy delegates. this.GetValue = fieldEntry.GetValue; this.SetValue = fieldEntry.SetValue; // For possible future use. this.shouldCreateGetSetDelegate = true; }
/// <summary> /// Adds entry to the collection of property/fields entries. /// </summary> /// <param name="idEntry">Entry to add.</param> public void AddIdEntry(SerializeIDEntry idEntry) { #region Initial check. if (this.idEntriesCodeMapping.ContainsKey(idEntry.IncludeAttribute.FieldIDCode)) { throw new KTSerializeAttributeException(String.Format( Properties.Resources.Error_AttributeGuidIsNotUnique, idEntry.IncludeAttribute.FieldID )); } #endregion #region Add to common entries collections. this.IdEntries.Add(idEntry); this.IdEntriesMapping.Add(idEntry.IncludeAttribute.FieldID, idEntry); this.idEntriesCodeMapping.Add(idEntry.IncludeAttribute.FieldIDCode, idEntry); #endregion }
/// <summary> /// Sets numbers of property/fields entries. /// </summary> /// <param name="storedPropertiesList">Possible collection of stored properties <see cref="GUID"/>s.</param> public void SetIdEntriesNumbers(List <Guid> storedPropertiesList) { #region Set stored numbers. if (storedPropertiesList != null) { for (int i = 0; i < storedPropertiesList.Count; i++) { this.StoredPropertiesGUIDs.Add(storedPropertiesList[i], i); } } #endregion #region Set numbers of entries. int countTo = this.IdEntries.Count; for (int i = 0; i < countTo; i++) { // Current entry. SerializeIDEntry idEntry = this.IdEntries[i]; // Try to get counter from stored info. int counter = 0; if (this.StoredPropertiesGUIDs.TryGetValue(idEntry.IncludeAttribute.FieldID, out counter)) { idEntry.EntryNumber = counter; } // Otherwise, add property info to stored properties collections. else { idEntry.EntryNumber = this.StoredPropertiesGUIDs.Count; // it's a length, thus is bigger than the biggest counter this.StoredPropertiesGUIDs.Add(idEntry.IncludeAttribute.FieldID, idEntry.EntryNumber); } // Add to mapping. this.IdEntriesIntMapping.Add(idEntry.EntryNumber, idEntry); } #endregion #region Final actions. // Reset collection with glance to entries number. this.IdEntries = this.IdEntries.OrderBy(s => s.EntryNumber).ToList(); this.IdEntriesArray = this.IdEntries.ToArray(); // Set array of mapping. if (countTo == 0) { this.IdEntriesIntMappingArray = new SerializeIDEntry[0]; } else { this.IdEntriesIntMappingArray = new SerializeIDEntry[this.IdEntriesArray[countTo - 1].EntryNumber + 1]; for (int i = 0; i < countTo; i++) { SerializeIDEntry idEntry = this.IdEntriesArray[i]; this.IdEntriesIntMappingArray[idEntry.EntryNumber] = idEntry; } } #endregion }
/// <summary> /// Creates new instance of <see cref="SerializeIDEntry"/> on basis of sent instance. /// </summary> /// <param name="entry">Entry to create new instance upon.</param> public SerializeIDEntry(SerializeIDEntry entry) : this(true) { }