Exemplo n.º 1
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 Structure CreateStructureObject(Type structureType)
        {
            Structure result = new VSPlugin.Structure();

            StructureAttribute structAttribute = structureType.GetCustomAttribute <StructureAttribute>();


            result.Type       = structAttribute == null ? "object" : structAttribute.Type;
            result.Properties = new Dictionary <string, StructureProperty>();
            foreach (PropertyInfo pinfo in structureType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance))
            {
                PropertyAttribute propertyAttribute = pinfo.GetCustomAttribute <PropertyAttribute>();

                string            itemsType = "";
                StructureProperty structure = new StructureProperty();
                structure.Required = propertyAttribute == null ? false : propertyAttribute.Required;
                Structure includedStructure;
                structure.Type = Utility.HandleProperty(pinfo, out itemsType, out includedStructure);
                if (!string.IsNullOrEmpty(itemsType))
                {
                    structure.Items = new ArraySchema()
                    {
                        Type = itemsType
                    };
                }
                result.Properties.Add(pinfo.Name, structure);
            }

            return(result);
        }
Exemplo n.º 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 Structure CreateStructureObject(Type structureType)
        {
            Structure result = new VSPlugin.Structure();

            StructureAttribute structAttribute = structureType.GetCustomAttribute<StructureAttribute>();


            result.Type = structAttribute == null ? "object" : structAttribute.Type;
            result.Properties = new Dictionary<string, StructureProperty>();
            foreach(PropertyInfo pinfo in structureType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance))
            {
                PropertyAttribute propertyAttribute = pinfo.GetCustomAttribute<PropertyAttribute>();

                string itemsType = "";
                StructureProperty structure = new StructureProperty();
                structure.Required = propertyAttribute == null ? false : propertyAttribute.Required;
                Structure includedStructure;
                structure.Type = Utility.HandleProperty(pinfo, out itemsType, out includedStructure);
                if (!string.IsNullOrEmpty(itemsType))
                {
                    structure.Items = new ArraySchema()
                    {
                        Type = itemsType
                    };
                }
                result.Properties.Add(pinfo.Name, structure);                
            }

            return result;
        }