Exemple #1
0
        /// <summary>
        /// Attempts to set the fields value.
        /// </summary>
        /// <param name="value">new value of the field</param>
        /// <exception cref="MetadataSystemException">Field type mismatch.</exception>
        /// <exception cref="MetadataSystemException">Field not found.</exception>
        public void SetFieldValue(string fieldName, object value)
        {
            Type type = value.GetType();

            int index = Array.IndexOf <string>(indices, fieldName);

            if (index != -1)
            {
                MetadataField field = fields[index];

                if (field.TypeOfValue == type)
                {
                    field.SetValue(value);
                }
                else
                {
                    // Field type mismatch.
                    throw MetadataSystemException.TypeMismatch(name, fieldName, type, field.TypeOfValue);
                }
            }
            else
            {
                // Field not found.
                throw MetadataSystemException.FieldNotFound(name, fieldName);
            }
        }
Exemple #2
0
 /// <summary>
 /// Creates new instance of metadata object by copying the
 /// fields of another object.
 /// </summary>
 /// <param name="name">name of the new object, needs to be unique</param>
 /// <param name="other">object whose fields will be copied</param>
 /// <exception cref="MetadataSystemException">Name not unique.</exception>
 public MetadataObject(string name, MetadataObject other)
     : this(name, other.fields)
 {
     if (name == other.name)
     {
         throw MetadataSystemException.NameNotUnique(name);
     }
 }
        /// <summary>
        /// Finds object with given name.
        /// </summary>
        /// <param name="name">name of the object</param>
        /// <returns>metadata object</returns>
        /// <exception cref="MetadataSystemException">Invalid name.</exception>
        public MetadataObject GetObject(string objectsName)
        {
            int index = Array.IndexOf <string>(indices, objectsName);

            if (index != -1)
            {
                return(objects[index]);
            }

            // Invalid name.
            throw MetadataSystemException.ObjectNotFound(objectsName, name);
        }
        public MetadataObjectGroup GetGroup(string name)
        {
            int index = Array.IndexOf(indices, name);

            if (index != -1)
            {
                return(groups[index]);
            }

            // Group not found.
            throw MetadataSystemException.ObjectGroupFound(name);
        }
Exemple #5
0
        /// <summary>
        /// Attempts to read a field value from this object.
        /// </summary>
        /// <typeparam name="T">type of the field</typeparam>
        /// <param name="fieldName">name of the field</param>
        /// <returns>fields value</returns>
        /// <exception cref="MetadataSystemException">Field type mismatch.</exception>
        /// <exception cref="MetadataSystemException">Field not found.</exception>
        public T GetFieldValue <T>(string fieldName)
        {
            Type type = typeof(T);

            int index = Array.IndexOf <string>(indices, fieldName);

            if (index != -1)
            {
                MetadataField field = fields[index];

                if (field.TypeOfValue == type)
                {
                    return(field.GetValue <T>());
                }

                // Field type mismatch.
                throw MetadataSystemException.TypeMismatch(name, fieldName, type, field.TypeOfValue);
            }

            // Field not found.
            throw MetadataSystemException.FieldNotFound(name, fieldName);
        }