Ejemplo n.º 1
0
        private static void AddObjectProperties(Type t, string parentName, List <object> parameterSignatures, dynamic doc)
        {
            var publicProperties = t.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (PropertyInfo property in publicProperties)
            {
                if (!string.IsNullOrWhiteSpace(parentName))
                {
                    parentName += ".";
                }
                if (property.PropertyType.Namespace != "System")
                {
                    AddObjectProperties(property.PropertyType, parentName + property.Name, parameterSignatures, doc);
                }
                else
                {
                    dynamic opParam = new ExpandoObject();

                    opParam.name        = parentName + property.Name;
                    opParam.@in         = "query";
                    opParam.required    = property.GetCustomAttributes().Any(attr => attr is RequiredAttribute);
                    opParam.description = GetPropertyDescription(property);
                    SetParameterType(property.PropertyType, opParam, doc.definitions);
                    // x-ms-summary is title
                    if (property.GetCustomAttributes().Any(attr => attr is SummaryAttribute))
                    {
                        SummaryAttribute             summary           = (SummaryAttribute)property.GetCustomAttributes().First(attr => attr is SummaryAttribute);
                        IDictionary <string, object> expandoDictionary = opParam;
                        expandoDictionary["x-ms-summary"] = summary.Summary;
                    }
                    if (property.GetCustomAttributes().Any(attr => attr is VisibilityAttribute))
                    {
                        VisibilityAttribute          visibility        = (VisibilityAttribute)property.GetCustomAttributes().First(attr => attr is VisibilityAttribute);
                        IDictionary <string, object> expandoDictionary = opParam;
                        expandoDictionary["x-ms-visibility"] = visibility.Visibility.GetType()
                                                               .GetMember(visibility.Visibility.ToString())
                                                               .First()
                                                               .GetCustomAttribute <DisplayAttribute>()
                                                               .GetName();
                    }
                    if (property.GetCustomAttributes().Any(attr => attr is StaticValuesAttribute))
                    {
                        StaticValuesAttribute list = (StaticValuesAttribute)property.GetCustomAttributes().First(attr => attr is StaticValuesAttribute);
                        opParam.@enum = list.StaticValues;
                    }
                    parameterSignatures.Add(opParam);
                }
            }
        }
Ejemplo n.º 2
0
        private static dynamic GetObjectSchemaDefinition(IDictionary <string, object> definitions, Type parameterType)
        {
            dynamic objDef = new ExpandoObject();

            objDef.type       = "object";
            objDef.properties = new ExpandoObject();
            var           publicProperties   = parameterType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            List <string> requiredProperties = new List <string>();

            foreach (PropertyInfo property in publicProperties)
            {
                if (property.GetCustomAttributes().Any(attr => attr is RequiredAttribute))
                {
                    requiredProperties.Add(property.Name);
                }
                dynamic propDef = new ExpandoObject();
                propDef.description = GetPropertyDescription(property);
                SetParameterType(property.PropertyType, propDef, definitions);
                IDictionary <string, object> expandoDictionary1 = propDef;
                expandoDictionary1["x-ms-summary"] = property.Name;
                if (property.GetCustomAttributes().Any(attr => attr is VisibilityAttribute))
                {
                    VisibilityAttribute          visibility        = (VisibilityAttribute)property.GetCustomAttributes().First(attr => attr is VisibilityAttribute);
                    IDictionary <string, object> expandoDictionary = propDef;
                    expandoDictionary["x-ms-visibility"] = visibility.Visibility.GetType()
                                                           .GetMember(visibility.Visibility.ToString())
                                                           .First()
                                                           .GetCustomAttribute <DisplayAttribute>()
                                                           .GetName();
                }
                AddToExpando(objDef.properties, property.Name, propDef);
            }
            if (requiredProperties.Count > 0)
            {
                objDef.required = requiredProperties;
            }
            return(objDef);
        }