Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 private static void Add([NotNull] AttributeRole role)
 {
     _roles.Add(role.Id, role);
 }
Exemplo n.º 4
0
        private static string GetDefaultTypeName([NotNull] AttributeRole role)
        {
            Assert.ArgumentNotNull(role, nameof(role));

            return(AttributeRole.GetName(role));
        }
Exemplo n.º 5
0
 public ObjectAttributeType([NotNull] string name, AttributeRole role)
     : base(name)
 {
     _attributeRole = role;
 }
Exemplo n.º 6
0
 public ObjectAttributeType(AttributeRole role)
     : base(GetDefaultTypeName(role))
 {
     _attributeRole = role;
 }