Ejemplo n.º 1
0
        public ApiParameter CreateParameter(ApiParameterDescription parameterDescription, string relativePath)
        {
            var trueParamType = parameterDescription.ParameterDescriptor.ParameterType;

            var paramType    = GetParamType(parameterDescription, relativePath);
            var isRequired   = !parameterDescription.ParameterDescriptor.IsOptional;
            var dataType     = GetFriendlyTypeName(trueParamType);
            var allowMuliple = GetAllowMuliple(trueParamType);

            if (parameterDescription.ParameterDescriptor.ParameterType.IsEnum)
            {
                var possibleValues = new AllowableValues(trueParamType);
                return(new ApiEnumParameter()
                {
                    name = parameterDescription.Name,
                    dataType = dataType,
                    paramType = paramType.ToString(),
                    description = parameterDescription.Documentation,
                    allowMultiple = allowMuliple,
                    required = isRequired,
                    allowableValues = possibleValues
                });
            }

            return(new ApiParameter()
            {
                name = parameterDescription.Name,
                dataType = dataType,
                paramType = paramType.ToString(),
                description = parameterDescription.Documentation,
                allowMultiple = allowMuliple,
                required = isRequired
            });
        }
Ejemplo n.º 2
0
        public object CreateModel(Type type)
        {
            var properties = new Dictionary <string, object>();


            if (type.IsEnum)
            {
                var allowableVals = new AllowableValues(type);
                var itemDocs      = _docProvider.GetDocumentation(type);
                var item          = new { allowableValues = allowableVals, description = itemDocs, type = "string" };
                properties["PossibleValues"] = item;
            }
            else
            {
                foreach (var prop in type.GetProperties())
                {
                    properties[prop.Name] = GetProperty(prop);
                }
            }

            return(new ApiModel
            {
                id = type.Name,
                properties = properties,
                description = _docProvider.GetDocumentation(type)
            });
        }
Ejemplo n.º 3
0
        private object GetProperty(PropertyInfo prop)
        {
            object item;
            var    docs = _docProvider.GetDocumentation(prop);

            if (prop.PropertyType.IsArray)
            {   // Array
                item = new
                {
                    type        = prop.PropertyType.GetElementType().Name + "[]",
                    items       = new { Sref = prop.PropertyType.GetElementType().Name },
                    description = docs
                };
            }
            else if (prop.PropertyType.IsPrimitive)
            {   // Primative
                item = new
                {
                    type        = prop.PropertyType.Name,
                    description = docs
                };
            }
            else if (prop.PropertyType.IsEnum)
            {
                //"status": {
                //  "allowableValues": {
                //      "valueType": "LIST",
                //      "values": [
                //   "available",
                //   "pending",
                //   "sold"
                //],
                //      "valueType": "LIST"
                //  },
                //  "description": "pet status in the store",
                //  "type": "string"
                //}
                // Enum
                var allowableVals = new AllowableValues(prop.PropertyType);
                item = new { allowableValues = allowableVals, description = docs, type = "string" };
            }

            //else if (prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof (Nullable<>))
            else if (prop.PropertyType.IsGenericType)
            {
                var gType = prop.PropertyType.GetGenericArguments().First();
                var name  = Utils.GetCleanTypeName(gType);
                name = name.Substring(name.IndexOf(".") + 1);
                item = new { type = name + "?", description = docs };
            }
            else
            {
                item = new { type = prop.PropertyType.Name, description = docs };
            }

            return(item);
        }
Ejemplo n.º 4
0
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            int[] setIndices = AllowableValues.GetSetIndices();

            builder.Append("{");

            builder.Append(FiniteDomain[setIndices[0]]);

            for (int i = 1; i < setIndices.Length; i++)
            {
                builder.Append("," + FiniteDomain[setIndices[i]]);
            }

            builder.Append("}");

            return(builder.ToString());
        }
Ejemplo n.º 5
0
 public AppConfig(int AppConfigID) : this() // chain the default constructor to initialize field defaults
 {
     using (SqlConnection conn = DB.dbConn())
     {
         conn.Open();
         using (IDataReader rs = DB.GetRS("aspdnsf_getAppconfig " + AppConfigID.ToString(), conn))
         {
             if (rs.Read())
             {
                 m_Appconfigid   = DB.RSFieldInt(rs, "AppConfigID");
                 m_Appconfigguid = DB.RSFieldGUID2(rs, "AppConfigGUID");
                 m_Name          = DB.RSField(rs, "Name");
                 m_Description   = DB.RSField(rs, "Description");
                 m_Configvalue   = DB.RSField(rs, "ConfigValue").Trim();
                 m_Groupname     = DB.RSField(rs, "GroupName");
                 m_Superonly     = DB.RSFieldBool(rs, "SuperOnly");
                 m_Createdon     = DB.RSFieldDateTime(rs, "CreatedOn");
                 StoreId         = rs.FieldInt("StoreId");
                 _valueType      = rs.Field("ValueType");
                 AllowableValues.AddCommaDelimited(rs.Field("AllowableValues"));
             }
         }
     }
 }