/// <summary> /// Given a BibTeX entry and an enumerable of fields, returns an enumerable of tuples of the field names, order indices, and values. /// </summary> /// <param name="entry"></param> /// <param name="properties"></param> /// <returns></returns> public IEnumerable <Tuple <string, int, object> > GetBibTeXFieldsWithValues(IBibTeXEntry entry, IEnumerable <PropertyInfo> properties) { foreach (var property in properties) { yield return(GetBibTeXFieldWithValue(entry, property)); } }
/// <summary> /// Given a BibTeX entry and a field, returns a tuple of the field name, order index, and value. /// </summary> /// <param name="entry"></param> /// <param name="property"></param> /// <returns></returns> public Tuple <string, int, object> GetBibTeXFieldWithValue(IBibTeXEntry entry, PropertyInfo property) { var fieldName = GetBibTeXFieldName(property); var fieldValue = property.GetValue(entry); return(new Tuple <string, int, object>(fieldName, 0, fieldValue)); }
public string SerializeBibTeXEntry(IBibTeXEntry entry) { var stringBuilder = new StringBuilder(); SerializeBibTeXEntry(stringBuilder, entry); return(stringBuilder.ToString()); }
public bool ValidateBibTeXEntry(IBibTeXEntry entry) { var fields = _attributeReader.GetBibTeXFields(entry); ValidateBibTeXFields(entry, fields); return(true); }
/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { IBibTeXEntry entriesCasted = item.As <IBibTeXEntry>(); if ((entriesCasted != null)) { this._parent.Entries.Add(entriesCasted); } }
/// <summary> /// Given a BibTeX entry, returns all of its fields and their values. /// </summary> /// <param name="entry"></param> /// <returns></returns> public IEnumerable <Tuple <string, int, object> > GetBibTeXFieldsWithValues(IBibTeXEntry entry) { var fields = GetBibTeXFields(entry); foreach (var field in fields) { yield return(GetBibTeXFieldWithValue(entry, field)); } }
/// <summary> /// Removes the given item from the collection /// </summary> /// <returns>True, if the item was removed, otherwise False</returns> /// <param name="item">The item that should be removed</param> public override bool Remove(IModelElement item) { IBibTeXEntry bibTeXEntryItem = item.As <IBibTeXEntry>(); if (((bibTeXEntryItem != null) && this._parent.Entries.Remove(bibTeXEntryItem))) { return(true); } return(false); }
public bool ValidateBibTeXRequiredField(IBibTeXEntry entry, PropertyInfo property) { var entryName = _attributeReader.GetBibTeXEntryName(entry); var fieldName = _attributeReader.GetBibTeXFieldName(property); var fieldValue = property.GetValue(entry); if (IsBibTeXFieldValueNone(fieldValue)) { throw new RequiredFieldException(entryName, fieldName); } return(true); }
public void SerializeBibTeXEntry(StringBuilder stringBuilder, IBibTeXEntry entry) { var entryName = _attributeReader.GetBibTeXEntryName(entry); var fields = _attributeReader.GetBibTeXFieldsWithValues(entry); stringBuilder.Append(BibTeXBeginEntryCharacter); stringBuilder.Append(entryName); stringBuilder.Append(BibTeXBeginFieldsCharacter); stringBuilder.Append(entry.CitationKey); SerializeBibTeXFields(stringBuilder, fields); if (FormatStyle == BibTeXFormatStyle.Readable) { stringBuilder.Append("\n"); } stringBuilder.Append(BibTeXEndFieldsCharacter); stringBuilder.Append("\n"); }
public bool ValidateBibTeXFields(IBibTeXEntry entry, IEnumerable <PropertyInfo> properties) { foreach (var property in properties) { if (_attributeReader.IsBibTeXFieldRequired(property)) { ValidateBibTeXRequiredField(entry, property); } } var groupNames = _attributeReader.GetBibTeXRequiredFieldGroupNames(properties); foreach (var groupName in groupNames) { var groupFields = _attributeReader.GetFieldsInBibTeXRequiredFieldGroup(properties, groupName); ValidateBibTeXRequiredFieldGroup(entry, groupName, groupFields); } return(true); }
public bool ValidateBibTeXRequiredFieldGroup(IBibTeXEntry entry, string groupName, IEnumerable <PropertyInfo> properties) { var entryName = _attributeReader.GetBibTeXEntryName(entry); var fieldNames = _attributeReader.GetBibTeXFieldNames(properties); var isOneFieldSet = false; foreach (var property in properties) { var fieldValue = property.GetValue(entry); if (!IsBibTeXFieldValueNone(fieldValue)) { isOneFieldSet = true; } } if (isOneFieldSet == false) { throw new RequiredFieldGroupException(entryName, groupName, fieldNames); } return(true); }
/// <summary> /// Gets the BibTeX entry name for this BibTeX entry. /// </summary> /// <param name="entry"></param> /// <returns></returns> public string GetBibTeXEntryName(IBibTeXEntry entry) { var type = GetBibTeXEntryType(entry); return(GetBibTeXEntryName(type)); }
/// <summary> /// Gets the BibTeX field names for all of the optional BibTeX fields in this entry. /// </summary> /// <param name="entry"></param> /// <returns></returns> public IEnumerable <string> GetBibTeXOptionalFieldNames(IBibTeXEntry entry) { var type = GetBibTeXEntryType(entry); return(GetBibTeXOptionalFieldNames(type)); }
/// <summary> /// Gets the C# type of the IBibTeXEntry instance, which is used for getting attribute data of the entry. /// </summary> /// <param name="entry"></param> /// <returns></returns> public Type GetBibTeXEntryType(IBibTeXEntry entry) { if (entry is BibTeXArticle) { return(typeof(BibTeXArticle)); } if (entry is BibTeXBook) { return(typeof(BibTeXBook)); } if (entry is BibTeXBooklet) { return(typeof(BibTeXBooklet)); } if (entry is BibTeXConference) { return(typeof(BibTeXConference)); } if (entry is BibTeXInBook) { return(typeof(BibTeXInBook)); } if (entry is BibTeXInCollection) { return(typeof(BibTeXInCollection)); } if (entry is BibTeXInProceedings) { return(typeof(BibTeXInProceedings)); } if (entry is BibTeXManual) { return(typeof(BibTeXManual)); } if (entry is BibTeXMastersThesis) { return(typeof(BibTeXMastersThesis)); } if (entry is BibTeXMiscellaneous) { return(typeof(BibTeXMiscellaneous)); } if (entry is BibTeXPhDThesis) { return(typeof(BibTeXPhDThesis)); } if (entry is BibTeXProceedings) { return(typeof(BibTeXProceedings)); } if (entry is BibTeXTechReport) { return(typeof(BibTeXTechReport)); } if (entry is BibTeXUnpublished) { return(typeof(BibTeXUnpublished)); } throw new UnknownBibTeXEntryException(); }
/// <summary> /// Gets the BibTeX field with the given field name. /// </summary> /// <param name="entry"></param> /// <param name="name"></param> /// <returns></returns> public PropertyInfo GetBibTeXFieldByName(IBibTeXEntry entry, string name) { var type = GetBibTeXEntryType(entry); return(GetBibTeXFieldByName(type, name)); }
/// <summary> /// Gets all of the fields in a required field group for a given BibTeX Entry. /// </summary> /// <param name="entry"></param> /// <param name="groupName"></param> /// <returns></returns> public IEnumerable <PropertyInfo> GetFieldsInBibTeXRequiredFieldGroup(IBibTeXEntry entry, string groupName) { var type = GetBibTeXEntryType(entry); return(GetFieldsInBibTeXRequiredFieldGroup(type, groupName)); }
/// <summary> /// Gets all of the required field group names for a given BibTeX Entry. /// </summary> /// <param name="entry"></param> /// <returns></returns> public IEnumerable <string> GetBibTeXRequiredFieldGroupNames(IBibTeXEntry entry) { var type = GetBibTeXEntryType(entry); return(GetBibTeXRequiredFieldGroupNames(type)); }
/// <summary> /// Gets the properties of this BibTeX entry that are required BibTeX fields. /// </summary> /// <param name="entry"></param> /// <returns></returns> public IEnumerable <PropertyInfo> GetBibTeXRequiredFields(IBibTeXEntry entry) { var type = GetBibTeXEntryType(entry); return(GetBibTeXRequiredFields(type)); }