Example #1
0
        private static void ProcessTypeConstraintAttribute(TypeConstraint constraints, IEnumerable <LanguageConcept> languages, PropertyInfo property)
        {
            TypeConstraintAttribute typeConstraint = property.GetCustomAttribute <TypeConstraintAttribute>();

            if (typeConstraint == null)
            {
                return;
            }
            ClassifyTypeConstraints(constraints, languages, typeConstraint.Types);
        }
Example #2
0
        private static void ProcessSimpleTypeConstraintAttribute(TypeConstraint constraints, PropertyInfo property)
        {
            SimpleTypeConstraintAttribute typeConstraint = property.GetCustomAttribute <SimpleTypeConstraintAttribute>();

            if (typeConstraint == null)
            {
                return;
            }
            foreach (Type type in SimpleTypes.DotNetTypes)
            {
                if (!constraints.DotNetTypes.Contains(type))
                {
                    constraints.DotNetTypes.Add(type);
                }
            }
        }
Example #3
0
        public static TypeConstraint GetTypeConstraints(IEnumerable <LanguageConcept> languages, PropertyInfo property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            TypeConstraint constraints = new TypeConstraint();

            ProcessTypeConstraintAttribute(constraints, languages, property);
            Type propertyType = GetPropertyType(property);

            ClassifyTypeConstraints(constraints, languages, propertyType);
            ProcessSimpleTypeConstraintAttribute(constraints, property);
            return(constraints);
        }
Example #4
0
 public static void ClassifyTypeConstraint(TypeConstraint constraints, Type type)
 {
     if (type.IsEnum)
     {
         constraints.Enumerations.Add(type);
     }
     else if (SimpleTypes.DotNetTypes.Contains(type))
     {
         constraints.DotNetTypes.Add(type);
     }
     else if (type.IsSubclassOf(typeof(DataType)))
     {
         constraints.DataTypes.Add(type);
     }
     else if (type.IsSubclassOf(typeof(SyntaxNode)))
     {
         constraints.Concepts.Add(type);
     }
 }
Example #5
0
 private static void ClassifyTypeConstraints(TypeConstraint constraints, IEnumerable <LanguageConcept> languages, params Type[] types)
 {
     foreach (Type type in types)
     {
         if (type == typeof(SyntaxNode))
         {
             continue;
         }
         if (type.IsAbstract)
         {
             foreach (Type subclass in GetSubclassesOfType(languages, type))
             {
                 ClassifyTypeConstraint(constraints, subclass);
             }
         }
         else
         {
             ClassifyTypeConstraint(constraints, type);
         }
     }
 }