public static DocXml GetAssemblyXml(string modelname)
        {
            if (string.IsNullOrWhiteSpace(modelname))
            {
                return(null);
            }
            var key = $"GetAssemblyXml_{modelname}";

            return(LocalCacheManager <DocXml> .Find(key, () =>
            {
                string xmlfile = string.Empty;
                if (modelname.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ||
                    modelname.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
                {
                    xmlfile = $"{AppDomain.CurrentDomain.BaseDirectory}\\{modelname.Substring(0, modelname.LastIndexOf('.'))}.xml";
                }
                else
                {
                    xmlfile = $"{AppDomain.CurrentDomain.BaseDirectory}\\{modelname}";
                }

                var doc = SerializerHelper.DeSerializerFile <DocXml>(xmlfile);
                if (doc != null)
                {
                    return doc;
                }
                return null;
            }));
        }
Example #2
0
        /// <summary>
        /// 取属性成员
        /// </summary>
        /// <typeparam name="A">属性</typeparam>
        /// <typeparam name="T">类</typeparam>
        /// <returns></returns>
        public static List <A> GetAllPAttr <A, T>()
        {
            string key = "GetAllPAttr_" + typeof(A).FullName + "_" + typeof(T).FullName;

            return(LocalCacheManager <List <A> > .Find(key, () =>
            {
                List <A> result = new List <A>();

                PropertyInfo[] propertyinfos = typeof(T).GetProperties();

                propertyinfos.ToList().ForEach(p =>
                {
                    object[] obs = p.GetCustomAttributes(typeof(A), true);
                    if (obs.Length > 0)
                    {
                        A attr = (A)obs[0];
                        PropertyInfo pp = attr.GetType().GetProperty("Property");
                        if (pp != null)
                        {
                            pp.SetValue(attr, p, null);
                        }

                        result.Add((A)obs[0]);
                    }
                    //else
                    //{
                    //    A attr = new A();
                    //    PropertyInfo pp = attr.GetType().GetProperty("Property");
                    //    if (pp != null)
                    //    {
                    //        pp.SetValue(attr, p, null);
                    //    }

                    //    result.Add(attr);
                    //}
                });

                return result;
            }, 10000));
        }