Exemple #1
0
        /// <summary>
        /// IDictionary 转 T
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dict"></param>
        /// <returns></returns>
        public static T ModelByIDictionary <T>(IDictionary <string, string> dict)
        {
            var t     = typeof(T);
            var model = Activator.CreateInstance(t);
            var col   = TypeDescriptor.GetProperties(model);
            var list  = new HashSet <string>();

            foreach (PropertyDescriptor item in col)
            {
                if (dict.ContainsKey(item.Name))
                {
                    list.Add(item.Name);
                }
            }
            foreach (PropertyDescriptor item in col)
            {
                if (!list.Contains(item.Name))
                {
                    continue;
                }
                var value = ObjectExtension.GetValueByType(item.PropertyType, dict[item.Name]);
                if (value != null)
                {
                    item.SetValue(model, value);
                }
            }
            return((T)model);
        }
        /// <summary>
        /// 获取Htpp请求中的IP地址
        /// </summary>
        /// <param name="httpRequest">Http请求</param>
        /// <returns></returns>
        public static string GetContextIP(this System.Web.HttpRequest httpRequest)
        {
            if (httpRequest == null || httpRequest.ServerVariables == null)
            {
                return(string.Empty);
            }

            string stream = httpRequest.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (string.IsNullOrEmpty(stream))
            {
                stream = httpRequest.ServerVariables["REMOTE_ADDR"];
            }
            if (string.IsNullOrEmpty(stream))
            {
                stream = httpRequest.UserHostAddress;
            }

            if (string.IsNullOrEmpty(stream))
            {
                return(string.Empty);
            }

            var ip = stream.Split(new[] { ',', '|', ';' }, StringSplitOptions.RemoveEmptyEntries).ElementAt(0);

            return(ObjectExtension.IsIP(ip) ? ip : string.Empty);
        }
Exemple #3
0
        /// <summary>
        /// 【服务端】=> 【客户端】将处理到得的参数,转成socket协议所要求的参数,步骤【三】
        /// </summary>
        /// <param name="currentRequest"></param>
        /// <param name="responseResult"></param>
        /// <returns></returns>
        public byte[] FromResponse(CurrentRequest currentRequest, IResponseHandlerResult responseResult)
        {
            var response = responseResult as ResponseResult;

            if (response.Body != null)
            {
                response.Body.Flush();
            }

            var request = currentRequest.Request as Request;
            var idbytes = BitConverter.GetBytes(currentRequest.Id);

            var encodinglength = BitConverter.GetBytes(request.Encoding.BodyName.Length);
            var encodingbytes  = Encoding.ASCII.GetBytes(request.Encoding.BodyName);

            var commandlength = BitConverter.GetBytes(request.CommandType.Length);
            var commandbytes  = request.Encoding.GetBytes(request.CommandType);

            var querydatas  = this.ToEncodeNameValueCollection(request.Encoding, response.Query);
            var formdatas   = this.ToEncodeNameValueCollection(request.Encoding, response.Form);
            var headerdatas = this.ToEncodeNameValueCollection(request.Encoding, response.Headers);

            var bodylength = response.Body == null?BitConverter.GetBytes(0L) : BitConverter.GetBytes(response.Body.Length);

            var bodydatas = response.Body == null ? new byte[0] : response.Body.ToArray();

            return(ObjectExtension.Combine(idbytes, encodinglength, encodingbytes, commandlength, commandbytes, querydatas, formdatas, headerdatas, bodylength, bodydatas));
        }
Exemple #4
0
        /// <summary>
        ///     卖家评价 (2019.03.31 新作用)
        /// </summary>
        /// <param name="orderRate"></param>
        public ServiceResult Rate(OrderRateInfo orderRate)
        {
            var order = Resolve <IOrderService>().GetSingle(r => r.Id == orderRate.OrderId);

            if (orderRate.Intro.IsNullOrEmpty())
            {
                return(ServiceResult.Failure("详情不能为空"));
            }

            if (order == null)
            {
                return(ServiceResult.Failure("订单不存在"));
            }

            order.OrderExtension.OrderRate.SellerRate = orderRate;
            order.Extension = ObjectExtension.ToJson(order.OrderExtension);
            var result = Resolve <IOrderService>().Update(order);

            if (result)
            {
                return(ServiceResult.Success);
            }

            return(ServiceResult.Failure("失败"));
        }
Exemple #5
0
        /// <summary>
        /// 【客户端】=>【服务端】 将当前请求参数,转成socket协议所要求的参数,步骤【一】
        /// </summary>
        /// <param name="currentRequest"></param>
        /// <returns></returns>
        public byte[] FromRequest(CurrentRequest currentRequest)
        {
            var request = currentRequest.Request as Request;

            if (request.Writer != null)
            {
                request.Writer.Flush();
            }

            var idbytes = BitConverter.GetBytes(currentRequest.Id);

            var encodinglength = BitConverter.GetBytes(request.Encoding.BodyName.Length);
            var encodingbytes  = Encoding.ASCII.GetBytes(request.Encoding.BodyName);

            var commandlength = BitConverter.GetBytes(request.CommandType.Length);
            var commandbytes  = request.Encoding.GetBytes(request.CommandType);

            var querydatas  = this.ToEncodeNameValueCollection(request.Encoding, request.Query);
            var formdatas   = this.ToEncodeNameValueCollection(request.Encoding, request.Form);
            var headerdatas = this.ToEncodeNameValueCollection(request.Encoding, request.Headers);

            var memorystream = request.Body as MemoryStream;
            var bodylength   = BitConverter.GetBytes(memorystream.Length);
            var bodydatas    = memorystream.ToArray();

            return(ObjectExtension.Combine(idbytes, encodinglength, encodingbytes, commandlength, commandbytes, querydatas, formdatas, headerdatas, bodylength, bodydatas));
        }
Exemple #6
0
        /// <summary>
        /// </summary>
        /// <param name="httpContext"></param>
        public ServiceResult Message(DefaultHttpContext httpContext)
        {
            var orderMessage = AutoMapping.SetValue <OrderMessage>(httpContext);
            var orderId      = httpContext.Request.Form["OrderId"].ConvertToLong();
            var order        = Resolve <IOrderService>().GetSingle(r => r.Id == orderId);

            if (order == null)
            {
                return(ServiceResult.Failure("订单不存在"));
            }

            if (order.OrderExtension.OrderRemark == null)
            {
                order.OrderExtension.OrderRemark = new OrderRemark();
            }

            order.OrderExtension.Message.PlatplatformMessage = orderMessage.PlatplatformMessage;
            order.Extension = ObjectExtension.ToJson(order.OrderExtension);
            var result = Resolve <IOrderService>().Update(order);

            if (result)
            {
                return(ServiceResult.Success);
            }

            return(ServiceResult.Failure("失败"));
        }
        public ApiResult Remark([FromBody] OrderRemark modelIn)
        {
            var order = Resolve <IOrderService>().GetSingle(r => r.Id == modelIn.OrderId);

            if (order == null)
            {
                return(ApiResult.Failure("订单不存在"));
            }

            if (order.OrderExtension.OrderRemark == null)
            {
                order.OrderExtension.OrderRemark = new OrderRemark();
            }

            order.OrderExtension.OrderRemark.PlatplatformRemark = modelIn.PlatplatformRemark;
            order.Extension = ObjectExtension.ToJson(order.OrderExtension);
            var result = Resolve <IOrderService>().Update(order);

            if (result)
            {
                return(ApiResult.Success("备注成功!"));
            }

            return(ApiResult.Failure("备注失败!"));
        }
        private ActionResult Details(RouteEntity entity, string category, string slug)
        {
            if (entity is Photoshop)
            {
                var data = new ProductViewData
                {
                    Menu = ObjectExtension.As <IList <MenuItemViewModel> >(_context.AbstractMenuItem.Where(x => x.RouteID == entity.ID))
                };
                this.SetTheme(entity);
                var link = entity as Photoshop;
                data.Route = ObjectExtension.As <PhotoshopViewModel.Summary>(entity);

                data.PhototechnicsViewModel = ObjectExtension.As <PhototechnicsViewModel.Details>(_context.PricePositions.Where(x => x.PhotoshopID == entity.ID && x.Phototechnics.Shortcut == slug)
                                                                                                  .Include(x => x.Phototechnics.ParameterValues).Include(x => x.Phototechnics.ParameterValues.Select(y => y.Parameter)).FirstOrDefault());
                return(View("Details", data));
            }
            if (entity is Photorent)
            {
                var data = new ProductViewData
                {
                    Menu = ObjectExtension.As <IList <MenuItemViewModel> >(_context.AbstractMenuItem.Where(x => x.RouteID == entity.ID))
                };
                this.SetTheme(entity);
                var link = entity as Photorent;
                data.Route = ObjectExtension.As <PhotorentViewModel.Details>(entity);

                data.Categorieses = ObjectExtension.As <IList <CategoryViewModel> >(_context.Categories.ToList());

                data.PhototechnicsViewModel = ObjectExtension.As <PhototechnicsViewModel.Details>(link.RentCalendars.SingleOrDefault(x => x.Phototechnics.Shortcut == slug));
                return(View("Details", data));
            }
            return(View("Details"));
        }
Exemple #9
0
 void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     Com.Aote.ObjectTools.GeneralObject go = ObjectExtension.FindResource(this, "LoginUser") as Com.Aote.ObjectTools.GeneralObject;
     Com.Aote.ObjectTools.ObjectList    ol = go.GetPropertyValue("functions") as Com.Aote.ObjectTools.ObjectList;
     //CommonList newol = new CommonList();
     foreach (Com.Aote.ObjectTools.GeneralObject item in ol)
     {
         //CommonObject co = new CommonObject();
         //co["name"] = item.GetPropertyValue("name");
         //co["icon"] = item.GetPropertyValue("icon");
         //co["childsShow"] = "Collapsed";
         item.SetPropertyValue("childsShow", "Collapsed", true);
         //CommonList newchildlist = new CommonList();
         //Com.Aote.ObjectTools.ObjectList childlist = item.GetPropertyValue("children") as Com.Aote.ObjectTools.ObjectList;
         //foreach (Com.Aote.ObjectTools.GeneralObject child in childlist)
         //{
         //CommonObject newchild = new CommonObject();
         //newchild["name"] = child.GetPropertyValue("name");
         //newchild["link"] = child.GetPropertyValue("link");
         //newchildlist.Add(newchild);
         //}
         //co["children"] = newchildlist;
         //newol.Add(co);
     }
     this.menus.ItemsSource = ol;
 }
Exemple #10
0
        //method that will perform the insert, update, and delete actions and
        //create a rollback action that will be stored in the queue of the IUnitOfWork instance.
        private async Task <TableResult> ExecuteAsync(TableOperation operation)
        {
            var rollbackAction = CreateRollbackAction(operation);
            var result         = await storageTable.ExecuteAsync(operation);

            Scope.RollbackActions.Enqueue(rollbackAction);

            // Audit Implementation
            if (operation.Entity is IAuditTracker)
            {
                // Make sure we do not use same RowKey and PartitionKey
                var auditEntity = ObjectExtension.CopyObject <T>(operation.Entity);
                auditEntity.PartitionKey = $"{auditEntity.PartitionKey}-{auditEntity.RowKey}";
                auditEntity.RowKey       = $"{DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fff")}";

                var auditOperation      = TableOperation.Insert(auditEntity);
                var auditRollbackAction = CreateRollbackAction(auditOperation, true);

                var auditTable = tableClient.GetTableReference($"{typeof(T).Name}Audit");
                await auditTable.ExecuteAsync(auditOperation);

                Scope.RollbackActions.Enqueue(auditRollbackAction);
            }

            return(result);
        }
Exemple #11
0
        public static T MapControlsToProps <T>(T model, Control rootControl)
        {
            foreach (var prop in model.GetType().GetProperties())
            {
                try
                {
                    var value = GetControlValue(rootControl, prop.Name);
                    if (value != ObjectExtension.GetDefaultTypeValue(prop.PropertyType))
                    {
                        if (prop.PropertyType == typeof(double))
                        {
                            prop.SetValue(model, double.Parse((string)value));
                        }
                        else
                        {
                            prop.SetValue(model, value);
                        }
                    }
                }
                catch (Exception)
                {
                    continue;
                }
            }

            return(model);
        }
        void Startups.ITypeProcessor.Processing(IApplicationStartup application, Type type)
        {
            if (type == null || type.IsAbstract || !type.IsClass || type.IsInterface || type.IsGenericTypeDefinition)
            {
                return;
            }

            if (!ObjectExtension.IsAssignableToType(eventType, type))
            {
                return;
            }

            /*分析当前handlerType*/
            var handlerAttributes = type.GetCustomAttributes(true);

            if (handlerAttributes == null && handlerAttributes.Length == 0)
            {
                return;
            }

            var list = new List <Attribute>(handlerAttributes.Length);

            foreach (var attr in handlerAttributes)
            {
                list.Add((Attribute)attr);
            }

            EventBehaviorStorager.Default.Add(type, list);
        }
Exemple #13
0
        public static void Revert()
        {
            foreach (var key in PatchedStorage.Keys.ToList())
            {
                var data = PatchedStorage.GetObject <CommandToPatch>(key);
                if (data.Offset > 0)
                {
                    ObjectExtension.Swap(ref data.OriginalOpCode, ref data.PatchedOpCode);
                    try {
                        PatchFile(key, data, false);
                        PatchedStorage.Remove(key);
                    } catch (PatchException e) {
                        NonfatalError.NotifyBackground("Can’t revert AC to its original state", e.Message.ToSentence());
                    } catch (Exception e) {
                        NonfatalError.NotifyBackground("Can’t revert AC to its original state", e);
                    }
                }
            }

            var ini   = new IniFile(AcPaths.GetCfgVideoFilename());
            var video = ini["VIDEO"];

            if (video.ContainsKey(@"__CM_ORIGINAL_SHADOW_MAP_SIZE"))
            {
                video.Set("SHADOW_MAP_SIZE", video.GetInt("__CM_ORIGINAL_SHADOW_MAP_SIZE", 2048));
                video.Remove(@"__CM_ORIGINAL_SHADOW_MAP_SIZE");
                ini.Save();
            }
        }
 protected virtual ActionResult View(Photomodel model)
 {
     return(View("Details", new ViewData.Model.DetailsViewData()
     {
         Item = ObjectExtension.As <PhotomodelViewModel.Details>(model)
     }));
 }
Exemple #15
0
        public void SetValueTest()
        {
            Test1 t1 = new Test1();
            Test2 t2 = new Test2();

            t1.SetValue("Name", "ccc");
            t1.SetValue("Age", 10);
            t1.SetValue("Birthday", new DateTime(1921, 7, 1));
            t2.SetValue("Name", "ddd");
            t2.SetValue("Age", 20);
            t2.SetValue("Birthday", new DateTime(1949, 10, 1));
            Assert.AreEqual("ccc", t1.Name);
            Assert.AreEqual(10, t1.Age);
            Assert.AreEqual(new DateTime(1921, 7, 1), t1.Birthday);
            Assert.AreEqual("ddd", t2.Name);
            Assert.AreEqual(20, t2.Age);
            Assert.AreEqual(new DateTime(1949, 10, 1), t2.Birthday);

            t1.T2 = t2;
            t1.SetValue("T2.Name", "eee");
            t1.SetValue("T2.Age", 30);
            t1.SetValue("T2.Birthday", new DateTime(1997, 7, 1));
            Assert.AreEqual("eee", t1.T2.Name);
            Assert.AreEqual(30, t1.T2.Age);
            Assert.AreEqual(new DateTime(1997, 7, 1), t1.T2.Birthday);

            List <string> lst = ObjectExtension.DumpCache(false, true);

            t1.SetValue("Age", "", true);
            Assert.AreEqual(0, t1.Age);
        }
Exemple #16
0
        public static void RecordEnd(string operation, Type target, Action <string> callback = null, bool handlePrefs = true)
        {
            ObjectExtension.ResetCache();
            var undo = "";
            var redo = "";

            if (Undo.snapshot.ContainsKey(target))
            {
                var changes = Undo.snapshot[target].Difference(target.GetVariables(null, ObjectExtension.staticPublicFlags));
                foreach (var item in changes)
                {
                    var scope = "&&&" + target.FullName + "###" + item.Key + "|||";
                    undo += scope + Undo.snapshot[target][item.Key];
                    redo += scope + item.Value;
                }
                Undo.snapshot.Remove(target);
            }
            if (handlePrefs)
            {
                foreach (var pref in Undo.snapshotPrefs)
                {
                    var current = Utility.GetPref(pref.Key, pref.Value);
                    var head    = "&&&" + pref.Key + "|||" + pref.Value.GetType().Name + "---";
                    undo += head + pref.Value.SerializeAuto();
                    redo += head + current.SerializeAuto();
                }
                Undo.snapshotPrefs.Clear();
            }
            undo = undo.ReplaceFirst("&&&", "").Trim();
            redo = redo.ReplaceFirst("&&&", "").Trim();
            Undo.Add(operation, undo, redo, Undo.Handle + callback);
        }
Exemple #17
0
        private byte[] ToEncodeNameValueCollection(Encoding encoding, NameValueCollection collection)
        {
            var count      = collection != null ? collection.Count : 0;
            var countbytes = BitConverter.GetBytes(count);
            var bytes      = new List <byte[]>();

            bytes.Add(countbytes);
            if (count > 0)
            {
                foreach (var key in collection.AllKeys)
                {
                    var value       = collection[key];
                    var keylength   = BitConverter.GetBytes(key.Length);
                    var keydatas    = encoding.GetBytes(key);
                    var valuelength = value == null?BitConverter.GetBytes(0) : BitConverter.GetBytes(value.Length);

                    var valuedatas = value == null?encoding.GetBytes(string.Empty) : encoding.GetBytes(value);

                    bytes.Add(keylength);
                    bytes.Add(keydatas);
                    bytes.Add(valuelength);
                    bytes.Add(valuedatas);
                }
            }

            return(ObjectExtension.Combine(bytes));
        }
Exemple #18
0
        /// <summary>
        ///     卖家评价
        /// </summary>
        /// <param name="httpContext"></param>
        public ServiceResult Rate(DefaultHttpContext httpContext)
        {
            var orderRate = AutoMapping.SetValue <OrderRateInfo>(httpContext);
            var orderId   = httpContext.Request.Form["OrderId"].ConvertToLong();
            var order     = Resolve <IOrderService>().GetSingle(r => r.Id == orderId);

            if (orderRate.Intro.IsNullOrEmpty())
            {
                return(ServiceResult.Failure("详情不能为空"));
            }

            if (order == null)
            {
                return(ServiceResult.Failure("订单不存在"));
            }

            order.OrderExtension.OrderRate.SellerRate = orderRate;
            order.Extension = ObjectExtension.ToJson(order.OrderExtension);
            var result = Resolve <IOrderService>().Update(order);

            if (result)
            {
                return(ServiceResult.Success);
            }

            return(ServiceResult.Failure("失败"));
        }
Exemple #19
0
        /// <summary>
        /// 获取消息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="exchange"></param>
        /// <param name="queue"></param>
        /// <param name="routingKey"></param>
        /// <param name="handler">消费处理</param>
        private void Pull <T>(string exchange, string queue, string routingKey, Action <T> handler) where T : class
        {
            var channel = GetModel(exchange, queue, routingKey);

            var result = channel.BasicGet(queue, false);

            if (ObjectExtension.IsNull(result))
            {
                return;
            }

            var msg = SerializeExtension.DeserializeUtf8(result.Body).FromJson <T>();

            try
            {
                handler(msg);
            }
            catch (Exception ex)
            {
                ex.GetInnestException().WriteToFile("队列接收消息", "RabbitMq");
            }
            finally
            {
                channel.BasicAck(result.DeliveryTag, false);
            }
        }
        public void ToJson_HttpContext_Type_test()
        {
            HttpContext httpContext = null;
            Type        type        = null;
            var         result      = ObjectExtension.ToJson(httpContext, type);

            Assert.NotNull(result);
        }
 protected virtual ActionResult View(Masterclass model)
 {
     return(View("Details",
                 new ViewData.Masterclass.DetailsViewData()
     {
         Item = ObjectExtension.As <MasterclassViewModel.Details>(model)
     }));
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="parameterType"></param>
 /// <param name="propertyName"></param>
 private void EnsurePropertyInfo(Type parameterType,
                                 string propertyName)
 {
     // Property
     PropertyInfo = parameterType?.GetProperty(propertyName);
     ObjectExtension.ThrowIfNull(PropertyInfo,
                                 $"The property '{propertyName}' is not found from type '{parameterType?.FullName}'.");
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="parameterType"></param>
 /// <param name="propertyName"></param>
 private void Validate(Type parameterType,
                       string propertyName)
 {
     ObjectExtension.ThrowIfNull(parameterType, "ParameterType");
     ValidateParameterType(parameterType);
     ObjectExtension.ThrowIfNull(propertyName, "PropertyName");
     EnsurePropertyInfo(parameterType, propertyName);
 }
Exemple #24
0
 public static void RecordStart(Type target, bool clearPrefRecords = true)
 {
     ObjectExtension.ResetCache();
     if (clearPrefRecords)
     {
         Undo.snapshotPrefs.Clear();
     }
     Undo.snapshot[target] = target.GetVariables(null, ObjectExtension.staticPublicFlags);
 }
Exemple #25
0
            /// <summary>
            /// 转换成转输的数组
            /// </summary>
            /// <param name="data"></param>
            /// <returns></returns>
            public byte[] To(byte[] data)
            {
                var length = data.Length;
                var s1     = BitConverter.GetBytes(length);
                var s2     = data;
                var s      = ObjectExtension.Combine(s1, s2);

                return(s);
            }
        //
        //编写测试时,还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///ThrowIfNull 的测试
        ///</summary>
        public void ThrowIfNullTestHelper <T>()
            where T : class
        {
            T      obj     = null;
            string message = string.Empty;

            ObjectExtension.ThrowIfNull <T>(obj, message);
            Assert.Inconclusive("无法验证不返回值的方法。");
        }
Exemple #27
0
        /// <summary>
        /// 是否包括了忽略的属性
        /// </summary>
        /// <returns></returns>
        protected virtual bool ContainIgoreAttribute(MemberInfo member, Attribute[] attributes)
        {
            if (attributes == null || attributes.Length == 0)
            {
                return(false);
            }

            return(ObjectExtension.GetAttribute <IgnoreDataMemberAttribute>(attributes) != null);
        }
Exemple #28
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="queryable"></param>
        /// <param name="propName"> Property.Property such as User.Name </param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public static IOrderedQueryable <T> OrderBy <T>(this IQueryable <T> queryable, string propName, SortDirection direction) where T : class
        {
            var    keySelector = ObjectExtension.BuildGetter <T>(propName);
            string methodName  = direction == SortDirection.Ascending ? "OrderBy" : "OrderByDescending";

            MethodCallExpression methodCall = Expression.Call(typeof(Queryable), methodName, new Type[] { typeof(T), (keySelector as LambdaExpression).ReturnType }, queryable.Expression, Expression.Quote(keySelector));

            return((IOrderedQueryable <T>)queryable.Provider.CreateQuery <T>(methodCall));
        }
        void Startups.ITypeProcessor.Processing(IApplicationStartup application, Type type)
        {
            if (type == null || type.IsAbstract || !type.IsClass || type.IsInterface || type.IsGenericTypeDefinition)
            {
                return;
            }

            if (!ObjectExtension.IsAssignableToType(cmdHandlerType, type))
            {
                return;
            }

            /*分析当前handlerType*/
            var handlerAttributes = type.GetCustomAttributes(true);
            var list = new List <Attribute>();

            foreach (var attr in handlerAttributes)
            {
                list.Add((Attribute)attr);
            }

            HandlerBehaviorStorager.Default.Add(type, list);

            /*分析excute方法块*/
            var methods = type.GetMethods(bindingFlags);

            foreach (var method in methods)
            {
                if (method.Name != defineEvent)
                {
                    continue;
                }

                var paras = method.GetParameters();
                if (paras.Length != 2)
                {
                    continue;
                }

                if (commandContextTye.IsAssignableFrom(paras[0].ParameterType))
                {
                    var objects = method.GetCustomAttributes(true);
                    if (objects == null)
                    {
                        return;
                    }

                    var attributes = new List <Attribute>();
                    foreach (var attr in objects)
                    {
                        attributes.Add((Attribute)attr);
                    }

                    HandlerBehaviorStorager.Default.Add(type, paras[1].ParameterType, attributes);
                }
            }
        }
Exemple #30
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumerable"></param>
        /// <param name="propName"> Property.Property such as User.Name </param>
        /// <param name="direction"></param>
        /// <returns></returns>
        public static IOrderedEnumerable <T> ThenBy <T>(this IOrderedEnumerable <T> enumerable, string propName, SortDirection direction) where T : class
        {
            LambdaExpression keySelector = ObjectExtension.BuildGetter <T>(propName);
            string           methodName  = direction == SortDirection.Ascending ? "ThenBy" : "ThenByDescending";

            MethodInfo method = typeof(Enumerable).GetMethods().Single(a => a.Name == methodName && a.IsGenericMethodDefinition && a.GetGenericArguments().Length == 2 && a.GetParameters().Length == 2)
                                .MakeGenericMethod(typeof(T), keySelector.ReturnType);

            return((IOrderedEnumerable <T>)method.Invoke(null, new object[] { enumerable, keySelector.Compile() }));
        }