public virtual void Dispose()
 {
     foreach (var pool in _viewObjectPoolDict.Values)
     {
         pool.Dispose();
     }
     _viewObjectPoolDict.Clear();
     UseCreator = null;
 }
            public IViewObject PopOrCreate(IViewInstanceCreator creator, ModelViewBinder.BindInfo bindInfo)
            {
                var viewObj = Pop() as IViewObject;

                if (viewObj == null)
                {
                    viewObj = creator.CreateViewObj(bindInfo, true);
                }
                viewObj.OnUnbinded.Add(OnViewObjectUnbinded);
                return(viewObj);
            }
示例#3
0
        /// <summary>
        /// ModelViewBinder.BindInfoの検証を行う
        ///
        /// 指定したModelとbindInfoが持つIViewObjectとIModelViewParamBinderが使用可能かどうかを検証します。
        /// </summary>
        /// <param name="model"></param>
        /// <param name="bindInfo"></param>
        /// <param name="viewInstanceCreator"></param>
        /// <seealso cref="AvailableModelAttribute"/>
        /// <seealso cref="AvailableModelViewParamBinderAttribute"/>
        public static bool ValidateBindInfo(Model model, ModelViewBinder.BindInfo bindInfo, IViewInstanceCreator viewInstanceCreator)
        {
            if (!DoEnabled)
            {
                return(true);
            }
            bool isValid = true;

            System.Type viewType = null;
            try
            {
                viewType = viewInstanceCreator.GetViewObjType(bindInfo);
                if (viewType == null)
                {
                    Logger.LogWarning(LogPriority, () =>
                                      $"!!Validate!! InstanceKey('{bindInfo.InstanceKey}') in BindInfo don't get IViewObject..."
                                      );
                    isValid = false;
                }
                else
                {
                    var availableModelTypes = viewType.GetCustomAttributes(false)
                                              .OfType <AvailableModelAttribute>()
                                              .SelectMany(_a => _a.AvailableModels)
                                              .Distinct();
                    if (availableModelTypes.Any())
                    {
                        if (!availableModelTypes.Any(_t => model.GetType().IsSameOrInheritedType(_t)))
                        {
                            Logger.LogWarning(LogPriority, () =>
                                              $"!!Validate!! '{viewType}' is not available Model('{model}')..."
                                              );
                            isValid = false;
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                Logger.LogWarning(LogPriority, () =>
                                  $"!!Validate!! InstanceKey('{bindInfo.InstanceKey}') in BindInfo don't get IViewObject..." +
                                  $"{System.Environment.NewLine }---{System.Environment.NewLine}{e}{System.Environment.NewLine}---"
                                  );
                return(false);
            }


            try
            {
                var paramBinderType = viewInstanceCreator.GetParamBinderType(bindInfo);
                if (paramBinderType == null)
                {
                    Logger.LogWarning(LogPriority, () =>
                                      $"!!Validate!! BinderKey('{bindInfo.BinderKey}') in BindInfo don't get IModelViewParamBinder..."
                                      );
                    isValid = false;
                }
                else
                {
                    var availableParamBinders = viewType.GetCustomAttributes(false)
                                                .OfType <AvailableModelViewParamBinderAttribute>()
                                                .SelectMany(_a => _a.AvailableParamBinders)
                                                .Distinct();
                    if (availableParamBinders.Any())
                    {
                        if (!availableParamBinders.Any(_t => paramBinderType.IsSameOrInheritedType(_t)))
                        {
                            Logger.LogWarning(LogPriority, () =>
                                              $"!!Validate!! '{viewType}' is not available ParamBinder('{paramBinderType}')..."
                                              );
                            isValid = false;
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                Logger.LogWarning(LogPriority, () =>
                                  $"!!Validate!! BinderKey('{bindInfo.BinderKey}') in BindInfo don't get IModelViewParamBinder..." +
                                  $"{System.Environment.NewLine}---{System.Environment.NewLine}{e}{System.Environment.NewLine}---"
                                  );
                return(false);
            }
            return(isValid);
        }
 public ViewInstanceCreatorObjectPool(IViewInstanceCreator creator)
 {
     Assert.IsNotNull(creator);
     UseCreator = creator;
 }