Exemple #1
0
        public static string GetResourceType(Type t)
        {
            ResourceBaseAttribute propertyResourceAttribute = t.GetCustomAttribute <ResourceBaseAttribute>();

            if (propertyResourceAttribute == null)
            {
                throw new Exception("Invalid relation object in class");
            }
            return(propertyResourceAttribute.Id);
        }
Exemple #2
0
        public string Generate(Type resource)
        {
            Schema schema = new Schema();

            ResourceBaseAttribute resourceAttr = resource.GetCustomAttribute <ResourceBaseAttribute>();

            if (resourceAttr == null)
            {
                return(null);
            }

            // Setting the schema master attributes
            schema.Name       = resource.Name;
            schema.ApsVersion = resourceAttr.ApsVersion;
            schema.Implements = resourceAttr.Implements;
            schema.Id         = resourceAttr.Id;

            List <PropertyInfo> properties = new List <PropertyInfo>();
            List <PropertyInfo> links      = new List <PropertyInfo>();
            List <PropertyInfo> structures = new List <PropertyInfo>();


            schema.Properties = new Dictionary <string, Property>();
            foreach (PropertyInfo property in resource.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance))
            {
                if (property.GetCustomAttribute <SDK.Attributes.RelationAttribute>() != null)
                {
                    schema.Relations.Add(property.Name, Relation.CreateRelationObject(property));
                }
            }
            schema.Operations = new Dictionary <string, Operation>();
            foreach (MemberInfo method in resource.GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance))
            {
                if (method.GetCustomAttribute <OperationAttribute>() != null)
                {
                    schema.Operations.Add(method.Name, Operation.CreateOperationObject(method));
                }
            }


            return(JsonConvert.SerializeObject(schema, Formatting.Indented));
        }
Exemple #3
0
        private void lvClasses_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.lsbDetails.Items.Clear();

            if (currentAssembly == null)
            {
                return;
            }

            if (lvClasses.SelectedItems.Count == 0)
            {
                return;
            }

            Type type = currentAssembly.GetType(lvClasses.SelectedItems[0].Text);

            Generator g = new Generator();

            txtSchema.Text = g.Generate(type);



            ResourceBaseAttribute resourceAttr = type.GetCustomAttribute <SDK.Attributes.ResourceBaseAttribute>();

            resourceAttr = type.GetCustomAttribute(typeof(ResourceBaseAttribute), false) as ResourceBaseAttribute;
            if (resourceAttr == null)
            {
                return;
            }



            this.lsbDetails.Items.Add("apsVersion: " + resourceAttr.ApsVersion);
            this.lsbDetails.Items.Add("id: " + resourceAttr.Id);
            if (resourceAttr.Implements != null)
            {
                this.lsbDetails.Items.Add("implements: " + String.Join(",", resourceAttr.Implements));
            }

            List <PropertyInfo> p = new List <PropertyInfo>();
            List <PropertyInfo> l = new List <PropertyInfo>();
            List <PropertyInfo> s = new List <PropertyInfo>();

            foreach (PropertyInfo property in type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance))
            {
                if (property.GetCustomAttribute <SDK.Attributes.LinkAttribute>() != null)
                {
                    l.Add(property);
                }
                else if (property.GetCustomAttribute <SDK.Attributes.StructureAttribute>() != null)
                {
                    s.Add(property);
                }
                else
                {
                    p.Add(property);
                }
            }
            FillListItems(p, ">P>");
            FillListItems(l, ">L>");
            FillListItems(s, ">S>");
        }