Esempio n. 1
0
        /// <summary>
        /// Validates the object and returns the appropriate attributes contained within it.
        /// Throws if an invalid jdt attribute is found.
        /// </summary>
        /// <param name="transformObject">The object to validade</param>
        /// <returns>A dictionary with the JToken attributes of each valid attribute.
        /// An empty dictionary is returned if no valid properties are found</returns>
        internal Dictionary <JdtAttributes, JToken> ValidateAndReturnAttributes(JObject transformObject)
        {
            if (transformObject == null)
            {
                throw new ArgumentNullException(nameof(transformObject));
            }

            Dictionary <JdtAttributes, JToken> attributes = new Dictionary <JdtAttributes, JToken>();

            // First, we look through all of the properties that have JDT syntax
            foreach (JProperty property in transformObject.GetJdtProperties())
            {
                JdtAttributes attribute = this.validAttributes.GetByName(property.Name);
                if (attribute == JdtAttributes.None)
                {
                    // TO DO: Specify the transformation in the error
                    // If the attribute is not supported in this transformation, throw
                    throw JdtException.FromLineInfo(string.Format(Resources.ErrorMessage_InvalidAttribute, property.Name), ErrorLocation.Transform, property);
                }
                else
                {
                    // If it is a valid JDT attribute, add its value to the dictionary
                    attributes.Add(attribute, property.Value);
                }
            }

            // If the object has attributes, it should not have any other properties in it
            if (attributes.Count > 0 && attributes.Count != transformObject.Properties().Count())
            {
                throw JdtException.FromLineInfo(Resources.ErrorMessage_InvalidAttributes, ErrorLocation.Transform, transformObject);
            }

            return(attributes);
        }
Esempio n. 2
0
        /// <summary>
        /// Get the full name of an attribute, with the JDT prefix
        /// </summary>
        /// <param name="attribute">The attribute</param>
        /// <returns>A string with the full name of the requested attribute</returns>
        internal static string FullName(this JdtAttributes attribute)
        {
            if (attribute == JdtAttributes.None)
            {
                return(JdtUtilities.JdtSyntaxPrefix);
            }

            return(JdtUtilities.JdtSyntaxPrefix + Enum.GetName(typeof(JdtAttributes), attribute).ToLower());
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the description (name) of the attribute
        /// </summary>
        /// <param name="attribute">The attribute</param>
        /// <returns>The name of the attribute</returns>
        internal static string GetDescription(this JdtAttributes attribute)
        {
            var type        = attribute.GetType();
            var typeInfo    = type.GetTypeInfo();
            var name        = Enum.GetName(type, attribute);
            var description = typeInfo.GetField(name)
                              .GetCustomAttributes(false)
                              .OfType <DescriptionAttribute>()
                              .SingleOrDefault();

            if (description == null)
            {
                throw new NotImplementedException(attribute.ToString() + " does not have a corresponding name");
            }

            return(description.Description);
        }
Esempio n. 4
0
 /// <summary>
 /// Get the full name of an attribute, with the JDT prefix
 /// </summary>
 /// <param name="attribute">The attribute</param>
 /// <returns>A string with the full name of the requested attribute</returns>
 internal static string FullName(this JdtAttributes attribute)
 {
     return(JdtUtilities.JdtSyntaxPrefix + attribute.GetDescription());
 }