Caliburn.Micro.Screen.GetViewCloseAction C# (CSharp) Method

GetViewCloseAction() private method

private GetViewCloseAction ( bool dialogResult ) : System.Action
dialogResult bool
return System.Action
        System.Action GetViewCloseAction(bool? dialogResult) {
            var conductor = Parent as IConductor;
            if(conductor != null)
                return () => conductor.CloseItem(this);

            foreach(var contextualView in Views.Values) {
                var viewType = contextualView.GetType();

                var closeMethod = viewType.GetMethod("Close");
                if(closeMethod != null)
                    return () => {
#if !SILVERLIGHT
                        if(dialogResult != null) {
                            var resultProperty = contextualView.GetType().GetProperty("DialogResult");
                            if (resultProperty != null)
                                resultProperty.SetValue(contextualView, dialogResult, null);
                        }
#endif

                        closeMethod.Invoke(contextualView, null);
                    };

                var isOpenProperty = viewType.GetProperty("IsOpen");
                if(isOpenProperty != null)
                    return () => isOpenProperty.SetValue(contextualView, false, null);
            }

            return () => {
                var ex = new NotSupportedException("TryClose requires a parent IConductor or a view with a Close method or IsOpen property.");
                Log.Error(ex);
                throw ex;
            };
        }