/// <summary> /// Gets the attribute that has a given special role in the dataset. /// </summary> /// <param name="role">The attribute role. A non-standard role is expected.</param> /// <returns> /// Attribute instance, or null if no attribute in the dataset /// has the specified role. /// </returns> /// <exception cref="ArgumentException">Invalid role specified.</exception> public ObjectAttribute GetAttribute(AttributeRole role) { Assert.ArgumentNotNull(role, nameof(role)); ObjectAttribute attribute; return(AttributesByRole.TryGetValue(role, out attribute) ? attribute : null); }
public static string GetName([NotNull] AttributeRole role) { string name; if (!_roleNames.TryGetValue(role.Id, out name)) { // get all public static fields FieldInfo[] fieldInfos = role.GetType().GetFields(BindingFlags.Public | BindingFlags.Static); // make sure all roles of the passed type are in the list foreach (FieldInfo fieldInfo in fieldInfos) { var attributeRole = fieldInfo.GetValue(role) as AttributeRole; if (attributeRole == null) { continue; } // the field is an AttributeRole, make sure it is in the dictionary string existingName; if (!_roleNames.TryGetValue(attributeRole.Id, out existingName)) { // don't use add to avoid threading issues _roleNames[attributeRole.Id] = string.Format( "{0}.{1}", attributeRole.GetType().Name, fieldInfo.Name); } } // try again after adding all _roleNames.TryGetValue(role.Id, out name); } return(string.IsNullOrEmpty(name) ? string.Format("{0} id={1}", role.GetType().Name, role.Id) : name); }
private static void Add([NotNull] AttributeRole role) { _roles.Add(role.Id, role); }
private static string GetDefaultTypeName([NotNull] AttributeRole role) { Assert.ArgumentNotNull(role, nameof(role)); return(AttributeRole.GetName(role)); }
public ObjectAttributeType([NotNull] string name, AttributeRole role) : base(name) { _attributeRole = role; }
public ObjectAttributeType(AttributeRole role) : base(GetDefaultTypeName(role)) { _attributeRole = role; }