Exemple #1
0
        private static string GetParameterBindingAttribute(IHasStereotypes stereotypeable)
        {
            const string parameterBinding   = "Parameter Binding";
            const string propertyType       = "Type";
            const string propertyCustomType = "Custom Type";
            const string customValue        = "Custom";

            if (!stereotypeable.HasStereotype(parameterBinding))
            {
                return(string.Empty);
            }

            var attributeName = stereotypeable.GetStereotypeProperty <string>(parameterBinding, propertyType);

            if (!string.Equals(attributeName, customValue, StringComparison.OrdinalIgnoreCase))
            {
                return($"[{attributeName}]");
            }

            var customAttributeValue = stereotypeable.GetStereotypeProperty <string>(parameterBinding, propertyCustomType);

            if (string.IsNullOrWhiteSpace(customAttributeValue))
            {
                throw new Exception("Parameter Binding was set to custom but no Custom attribute type was specified");
            }

            return($"[{customAttributeValue}]");
        }
Exemple #2
0
        internal static IEnumerable <string> GetXmlDocLines(this IHasStereotypes hasStereotypes)
        {
            var text = hasStereotypes.GetStereotypeProperty <string>("XmlDoc", "Content");

            return(string.IsNullOrWhiteSpace(text)
                ? new string[0]
                : text
                   .Replace("\r\n", "\r")
                   .Replace("\n", "\r")
                   .Split('\r'));
        }
 public static T GetStereotypeProperty <T>(this IHasStereotypes model, string stereotypeName, string propertyName, T defaultIfNotFound = default(T))
 {
     try
     {
         return(model.GetStereotype(stereotypeName).GetProperty(propertyName, defaultIfNotFound));
     }
     catch (Exception e)
     {
         throw new Exception($"Failed to get stereotype property for element [{model}]", e);
     }
 }
        /// <summary>
        /// Lookup only one stereotype with a given name. If more than one is found with the same name, it fails.
        /// </summary>
        public static IStereotype GetStereotype(this IHasStereotypes model, string stereotypeName)
        {
            var stereotypes = model.Stereotypes.Where(x => x.Name == stereotypeName).ToArray();

            if (stereotypes.Length > 1)
            {
                throw new Exception(model is IMetadataModel metadataModel
                    ? $"More than one stereotype found with the name '{stereotypeName}' on element with ID {metadataModel.Id}"
                    : $"More than one stereotype found with the name '{stereotypeName}'");
            }

            return(stereotypes.SingleOrDefault());
        }
Exemple #5
0
 public static T GetPropertyValue <T>(this IHasStereotypes model, string stereotypeName, string propertyName, T defaultIfNotFound = default(T))
 {
     return(model.GetStereotypeProperty(stereotypeName, propertyName, defaultIfNotFound));
 }
Exemple #6
0
 public static bool HasStereotype(this IHasStereotypes model, string stereotypeName)
 {
     return(model.Stereotypes.Any(x => x.Name == stereotypeName));
 }
Exemple #7
0
 public static IStereotype GetStereotype(this IHasStereotypes model, string stereotypeName)
 {
     return(model.Stereotypes.FirstOrDefault(x => x.Name == stereotypeName));
 }
 /// <summary>
 /// Look up multiple stereotypes by the same name.
 /// </summary>
 public static IReadOnlyCollection <IStereotype> GetStereotypes(this IHasStereotypes model, string stereotypeName)
 {
     return(model.Stereotypes.Where(p => p.Name == stereotypeName).ToArray());
 }