Exemplo n.º 1
0
 /// <summary>
 /// 设置相同的属性
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="result"></param>
 /// <param name="baseParameter"></param>
 private static void SetSameValue <T>(T result, BaseParameter baseParameter) where T : BaseParameter
 {
     foreach (var prop in result.GetType().GetProperties())
     {
         foreach (var proptarget in baseParameter.GetType().GetProperties())
         {
             if (prop.Name == proptarget.Name)
             {
                 prop.SetValue(result, proptarget.GetValue(baseParameter));
             }
         }
     }
 }
Exemplo n.º 2
0
        public ParameterMetadata MapUp(BaseParameter model)
        {
            ParameterMetadata parameterModel = new ParameterMetadata();

            parameterModel.Name = model.Name;
            Type         type         = model.GetType();
            PropertyInfo typeProperty = type.GetProperty("Type",
                                                         BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            BaseType typeModel = (BaseType)typeProperty?.GetValue(model);

            if (typeModel != null)
            {
                parameterModel.Type = MapperType.EmitType(typeModel);
            }
            return(parameterModel);
        }
Exemplo n.º 3
0
        public static string ToUriParam(this BaseParameter obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            PropertyInfo[] propertis = obj.GetType().GetProperties();
            SortedDictionary <string, string> paramDict = new SortedDictionary <string, string>();

            foreach (var p in propertis)
            {
                var v = p.GetValue(obj, null);
                if (v == null)
                {
                    continue;
                }

                paramDict.Add(GetName(p), v.ToString());
            }

            return(paramDict.ToUriParam());
        }