/// <summary>
        /// Creates one instance of the Relation Object from the PropertyInfo object of the reflected class
        /// </summary>
        /// <param name="propInfo"></param>
        /// <returns></returns>
        public static Relation CreateRelationObject(PropertyInfo propInfo)
        {
            Relation result = new VSPlugin.Relation();

            // get's the Relation Attribute in the class
            RelationAttribute relationAttribute = propInfo.GetCustomAttribute<RelationAttribute>();

            if (relationAttribute== null)
                return result;

            Type elementType = null;
            //we need to discover the id of the relation and if it's a collection
            if (propInfo.PropertyType.IsArray)
            {
                result.Collection = true;

                elementType = propInfo.PropertyType.GetElementType();
            }
            else if(propInfo.PropertyType.IsGenericType && propInfo.PropertyType.GetGenericTypeDefinition() == typeof(List<>))
            {
                result.Collection = true;

                elementType = propInfo.PropertyType.GetGenericArguments().Single();
            }
            else
                elementType = propInfo.PropertyType;

            result.Type = GetResourceType(elementType);
            result.Required = relationAttribute.Required;
            result.Requirement = relationAttribute.Requirement;
            result.Allocate = relationAttribute.Allocate.ToString();

            return result;
        }
Exemple #2
0
        /// <summary>
        /// Creates one instance of the Relation Object from the PropertyInfo object of the reflected class
        /// </summary>
        /// <param name="propInfo"></param>
        /// <returns></returns>
        public static Relation CreateRelationObject(PropertyInfo propInfo)
        {
            Relation result = new VSPlugin.Relation();

            // get's the Relation Attribute in the class
            RelationAttribute relationAttribute = propInfo.GetCustomAttribute <RelationAttribute>();

            if (relationAttribute == null)
            {
                return(result);
            }

            Type elementType = null;

            //we need to discover the id of the relation and if it's a collection
            if (propInfo.PropertyType.IsArray)
            {
                result.Collection = true;

                elementType = propInfo.PropertyType.GetElementType();
            }
            else if (propInfo.PropertyType.IsGenericType && propInfo.PropertyType.GetGenericTypeDefinition() == typeof(List <>))
            {
                result.Collection = true;

                elementType = propInfo.PropertyType.GetGenericArguments().Single();
            }
            else
            {
                elementType = propInfo.PropertyType;
            }

            result.Type        = GetResourceType(elementType);
            result.Required    = relationAttribute.Required;
            result.Requirement = relationAttribute.Requirement;
            result.Allocate    = relationAttribute.Allocate.ToString();

            return(result);
        }