string get_modelAttrsJson(string typeName = "") { oModelInfo model = new oModelInfo(); Type typeModel = Type.GetType("MessageBroker." + typeName + ", MessageBroker"); if (typeModel == null) { return("{}"); } model.Name = typeModel.Name; object[] attrsModel = typeModel.GetCustomAttributes(true); foreach (var attr in attrsModel) { AttrModelInfo attrExt = attr as AttrModelInfo; if (attrExt != null) { model.Title = attrExt.Title; model.ServiceName = attrExt.ServiceName; } } PropertyInfo[] props = typeModel.GetProperties(); foreach (PropertyInfo prop in props) { object[] attrsField = prop.GetCustomAttributes(true); foreach (object attr in attrsField) { AttrFieldInfo attrExt = attr as AttrFieldInfo; if (attrExt != null) { model.Properties.Add(new oModelFielInfo(prop.Name, attrExt)); } } } string json = JsonConvert.SerializeObject(model); //cache file json string file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "schema-" + typeName + ".json"); File.WriteAllText(file, json); return(json); }
public HttpResponseMessage get_models() { string json = "{}"; string[] rounters = typeof(_API_CONST).GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy) .Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType.Name == "String") .Select(x => x.GetRawConstantValue() as string) .ToArray(); var ts = typeof(SystemController).Assembly.GetTypes() .Where(x => x.Name[0] == 'o') //.Select(x => x.Name) .ToArray(); List <oModelInfo> ls = new List <oModelInfo>() { }; foreach (var typeModel in ts) { object[] attrsModel = typeModel.GetCustomAttributes(true); foreach (var attr in attrsModel) { AttrModelInfo attrExt = attr as AttrModelInfo; if (attrExt != null) { oModelInfo model = new oModelInfo(); model.Name = typeModel.Name; model.Title = attrExt.Title; model.ServiceName = attrExt.ServiceName; ls.Add(model); } } } json = JsonConvert.SerializeObject(ls); return(new HttpResponseMessage() { Content = new StringContent(json, Encoding.UTF8, "application/json") }); }