Esempio n. 1
0
		private IPresentable CreatePresentable(IPresentable parent, Type controllerType, PresentOptions presentOptions, PresentArgs args)
		{
			Debug.Assert(controllerType != null);
			Debug.Assert(!_disposed);

			var resultType = typeof(int);
			var attrs = (ViewControllerAttribute[])controllerType.GetCustomAttributes(typeof(ViewControllerAttribute), false);
			var presentContext = new PresentResultArgs()
			{
				Id = ++_idCounter,
				ServiceProvider = _serviceProvider,
				ControllerFactory = _controllerFactory,
				ViewFactory = _viewFactory,
				ControllerType = controllerType,
				Parent = parent,
				PresentOptions = presentOptions,
				PresentArgs = args ?? PresentArgs.Default
			};

			if (attrs != null && attrs.Length > 0)
			{
				var controllerAttr = attrs[0];

				presentContext.PresentOptions |= controllerAttr.PresentOptions;
				presentContext.Layer = controllerAttr.Layer;
				presentContext.Tag = controllerAttr.Tag;
				presentContext.PrefabPath = controllerAttr.PrefabPath;
			}

			// Types inherited from IViewControllerResult<> use specific result values.
			if (IsAssignableToGenericType(controllerType, typeof(IViewControllerResult<>), out var t))
			{
				resultType = t.GenericTypeArguments[0];
			}

			// If parent is going to be dismissed, use its parent instead.
			if ((presentOptions & PresentOptions.Child) == 0)
			{
				presentContext.Parent = null;
			}
			else if ((presentOptions & PresentOptions.DismissAll) != 0)
			{
				presentContext.Parent = null;
			}
			else if ((presentOptions & PresentOptions.DismissCurrent) != 0)
			{
				presentContext.Parent = parent?.Parent;
			}

			// Instantiate the presentable.
			// https://docs.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/how-to-examine-and-instantiate-generic-types-with-reflection
			var presentResultType = typeof(PresentResult<,>).MakeGenericType(controllerType, resultType);
			var c = (IPresentable)Activator.CreateInstance(presentResultType, this, presentContext);

			AddPresentable(c);

			return c;
		}
Esempio n. 2
0
        public PresentResult(IPresenterInternal presenter, PresentResultArgs context)
        {
            Debug.Assert(presenter != null);
            Debug.Assert(context != null);

            _presenter         = presenter;
            _id                = context.Id;
            _tag               = context.Tag;
            _layer             = context.Layer;
            _parent            = context.Parent;
            _serviceProvider   = context.ServiceProvider;
            _controllerFactory = context.ControllerFactory;
            _controllerType    = context.ControllerType;
            _presentArgs       = context.PresentArgs;
            _presentOptions    = context.PresentOptions;
            _deeplinkId        = GetDeeplinkId(_controllerType);
            _prefabPath        = string.IsNullOrEmpty(context.PrefabPath) ? GetDefaultPrefabName(_controllerType) : context.PrefabPath;
        }