Exemplo n.º 1
0
        public void Resolve()
        {
            if (_self == null)
            {
                return;
            }
            idName = GetFullName(_self);
            var desc = ResolverHelper.GetMemberFromCache(_self.DeclaringType, t =>
            {
                return(t.Name.StartsWith("M:" + idName));
            });

            var args = _self.GetParameters();

            Args = new List <TypeModel>();
            for (int i = 0; i < args.Length; i++)
            {
                var       arg      = args[i];
                TypeModel argmodel = ModelFactory.CreateTypeModel(arg.ParameterType);
                Args.Add(argmodel);
            }
            Description           = desc?.Summary?.Trim();
            Name                  = _self.Name;
            TypeName              = _self.DeclaringType.FullName;
            ReturnArg             = ModelFactory.CreateTypeModel(_self.ReturnType);
            ReturnArg.Description = desc?.Returns?.Trim();
        }
Exemplo n.º 2
0
        public static TypeModel CreateTypeModel(Type type)
        {
            if (type == null)
            {
                return(null);
            }
            var result = type.ToTypeModel();

            if (!result.IsArray && result.IsClass)
            {
                var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                if (properties != null)
                {
                    foreach (var p in properties)
                    {
                        TypeModel model = p.PropertyType.ToTypeModel();
                        model.MemberName = p.Name;
                        var desc = ResolverHelper.GetMemberFromCache(p.DeclaringType, t =>
                        {
                            return(t.Name.StartsWith("P:" + p.DeclaringType.FullName + "." + p.Name));
                        });
                        model.Description = desc?.Summary?.Trim();
                        result.Properties.Add(model);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 从缓存中获得描述信息
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static DescriptionModel GetDescriptionFromCache(Type t)
        {
            var description = DescriptionModelCacheManager.Get(t.Assembly.FullName);

            if (description == null)
            {
                description = ResolverHelper.LoadDescription(t.Assembly);
            }

            return(description);
        }
Exemplo n.º 4
0
        public List <ServiceModel> Resolve(AttributeTargets target, Func <Type, bool> validate)
        {
            ResolverHelper.LoadDescription(_ass);
            List <ServiceModel> services = new List <ServiceModel>();

            Type[] types = null;
            try
            {
                types = _ass.GetTypes();
            }
            catch { }
            if (types == null)
            {
                return(services);
            }
            foreach (var type in types)
            {
                if (type.FullName.Equals("System") || type.FullName.StartsWith("System."))
                {
                    continue;
                }
                bool forceResolve = false;
                if (target == AttributeTargets.Class)
                {
                    if (validate != null && validate.Invoke(type))
                    {
                        forceResolve = true;
                    }
                }
                var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                foreach (var method in methods)
                {
                    if (method.Name.StartsWith("get_") || method.Name.StartsWith("set_"))
                    {
                        continue;
                    }
                    ServiceModel service = null;
                    if (forceResolve)
                    {
                        service = new ServiceModel(method);
                    }
                    else if (validate.Invoke(method.DeclaringType))
                    {
                        service = new ServiceModel(method);
                    }
                    if (service != null)
                    {
                        services.Add(service);
                    }
                }
            }
            return(services);
        }
Exemplo n.º 5
0
        public static TypeModel ToTypeModel(this Type t)
        {
            if (t == null)
            {
                return(null);
            }
            TypeModel model = TypeModelCacheManager.Get(t.FullName);

            if (model != null)
            {
                return(model);
            }
            model = t.ToTypeModelWithoutProperties();
            if (model.Properties.Count == 0)
            {
                var properties = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                if (properties != null)
                {
                    foreach (var p in properties)
                    {
                        TypeModel m = p.PropertyType.ToTypeModelWithoutProperties();
                        m.MemberName = p.Name;
                        var desc = ResolverHelper.GetMemberFromCache(p.DeclaringType, x =>
                        {
                            return(x.Name.StartsWith("P:" + p.DeclaringType.FullName + "." + p.Name));
                        });
                        m.Description = desc?.Summary?.Trim();
                        model.Properties.Add(m);
                    }
                }
            }
            if (model.IsClass)
            {
                TypeModelCacheManager.Set(t.FullName, model);
            }
            return(model);
        }