/// <summary> /// Gets the index of an inherited field /// </summary> /// <param name="field">The field</param> /// <returns>The field index or -1</returns> public int GetInheritedFieldIndex(DcField field) { if (!_inheritedFields.Contains(field)) { return(-1); } return(_inheritedFields.IndexOf(field)); }
public bool TryGetField(int index, out DcField field) { if (0 <= index && index <= _fieldsByIndex.Count - 1) { field = _fieldsByIndex[index]; return(true); } field = null; return(false); }
/// <summary> /// Adds a field to the <c>DcClass</c> /// </summary> /// <param name="field">The field to add</param> /// <returns>True on success, false on error</returns> public bool AddField(DcField field) { if (field.Class != null && field.Class != this) { return(false); } field.Class = this; File?.MarkInheritedFieldsStale(); if (field.Name != string.Empty) { if (field.Name == Name) { // The field is a constructor if (Constructor != null) { return(false); } // Constructor must be atomic if (!(field is DcAtomicField)) { return(false); } Constructor = field; _fieldsByName[field.Name] = field; return(true); } if (!_fieldsByName.TryAdd(field.Name, field)) { return(false); } } if ((VirtualInheritance && SortInheritanceByFile) || !IsStruct) { if (MultipleInheritance && File != null) { File.SetNewIndexNumber(field); } else { field.Number = NumInheritedFields; } _fieldsByIndex[field.Number] = field; } _fields.Add(field); return(true); }
public void SetNewIndexNumber(DcField field) { field.Number = _fieldsByIndex.Count; _fieldsByIndex.Add(field); }
/// <summary> /// Tries to get the nth inherited field. /// </summary> /// <param name="n">The inherited field index</param> /// <param name="field"></param> /// <returns>True on success, false on error</returns> public bool TryGetInheritedField(int n, out DcField field) { field = GetInheritedField(n); return(field != null); }
/// <summary> /// Tries to get a field with a given index inside the <c>DcClass</c> /// </summary> /// <param name="index">The field index</param> /// <param name="field">The field</param> /// <returns>True on success, false on error</returns> public bool TryGetFieldByIndex(int index, out DcField field) { field = GetFieldByIndex(index); return(field != null); }
/// <summary> /// Tries to get a field by name within the <c>DcClass</c> /// </summary> /// <param name="name">The name of the field</param> /// <param name="field">The field</param> /// <returns>True on success, false on error</returns> public bool TryGetFieldByName(string name, out DcField field) { field = GetFieldByName(name); return(field != null); }