Ejemplo n.º 1
0
        private void SetRoute(ActionModel actionModel)
        {
            //判断是否需要设置路由
            if (!actionModel.IsNeedSetRoute())
            {
                return;
            }
            // 已经标注了NotPrimaryKeyAttribute
            if (actionModel.MethodInfo.GetCustomAttribute <NotPrimaryKeyAttribute>() != null)
            {
                return;
            }

            var    controllerType = actionModel.Controller.ControllerType;
            string primaryKeyName = "__primaryKey";

            (Type type, object defaultValue)grainPrimaryKey = _actionILGeneratFactory.GrainInterfaceToKeyType(controllerType);
            if (grainPrimaryKey.type == typeof(Guid))
            {
                Attribute routeAttr = new RouteAttribute(actionModel.ActionName);
                actionModel.Attributes.Add(routeAttr);
                return;
            }
            else
            {
                Attribute routeAttr = new RouteAttribute(actionModel.ActionName + "/{" + primaryKeyName + "}");
                actionModel.Attributes.Add(routeAttr);
            }

            var keyParameter = this.BuildParameterModel(actionModel, primaryKeyName, typeof(string), new List <Attribute> {
                new FromRouteAttribute()
            });

            keyParameter.Feature         = "Orleans_Primary";
            keyParameter.HasDefaultValue = true;
            keyParameter.DefaultValue    = grainPrimaryKey.defaultValue;
            actionModel.Parameters.Add(keyParameter);
        }