Example #1
0
 /// <summary>Initializes a new instance of the <see cref="ConstructorDeclarationModel"/> class. </summary>
 /// <param name="constructorDeclaration">The constructor declaration. </param>
 public ConstructorDeclarationModel(IConstructorDeclaration constructorDeclaration)
     : base(null, constructorDeclaration)
 {
     if (constructorDeclaration.Initializer != null)
     {
         ThrownExceptions.Add(new ConstructorInitializerModel(this, constructorDeclaration.Initializer, this));
     }
     else
     {
         if (constructorDeclaration.DeclaredElement != null && constructorDeclaration.DeclaredElement.IsDefault)
         {
             var containingType = constructorDeclaration.DeclaredElement.GetContainingType();
             if (containingType != null)
             {
                 var baseClass = containingType.GetSuperTypes().FirstOrDefault(t => !t.IsInterfaceType());
                 if (baseClass != null)
                 {
                     var baseClassTypeElement = baseClass.GetTypeElement();
                     if (baseClassTypeElement != null)
                     {
                         IConstructor defaultBaseConstructor = baseClassTypeElement.Constructors.First(c => c.IsDefault);
                         if (defaultBaseConstructor != null)
                         {
                             ThrownExceptions.Add(new ConstructorInitializerModel(this, defaultBaseConstructor, this));
                         }
                     }
                 }
             }
         }
     }
 }
Example #2
0
        protected BaseViewModel(string urlPathSegment, IMainViewModel mainVM)
        {
            _clearNotification = () => mainVM.ClearNotification();
            _showErrorAction   = mainVM.ShowError;
            _setNotification   = mainVM.SetNotification;

            UrlPathSegment = urlPathSegment;

            ThrownExceptions.Subscribe(ErrorHandler(nameof(BaseViewModel)));
        }
Example #3
0
        public BaseViewModel([CanBeNull] IBaseViewModel parent)
        {
            context = this;
            InitValidator();
            using (SuppressChangeNotifications())
            {
                Parent = parent;
                if (Window == null && parent is BaseViewModel parentVM)
                {
                    context           = parentVM;
                    Window            = parent.Window;
                    dialogCoordinator = parentVM.dialogCoordinator;
                }

                PropertyChanged += BaseViewModel_PropertyChanged;
                ThrownExceptions.Subscribe(CommandException);
            }
        }
 public ViewModelBase()
 {
     ThrownExceptions
     .Subscribe(async ex => await Application.Current.MainPage.DisplayAlert("Error", ex.Message, "OK"))
     .DisposeWith(Disposables);
 }
Example #5
0
 protected AsyncLoaderViewModelBase()
 {
     this.RegisterFunction(this.DoLoad);
     ThrownExceptions.ObserveOnUiSafeScheduler().Subscribe(OnError);
 }
Example #6
0
        /// <summary>
        /// Initializes a method with its parent model and the XML node is represents.
        /// </summary>
        /// <param name="model">The parent model containing this method.</param>
        /// <param name="node">The XML node represented by this method.</param>
        /// <exception cref="FormatException">The name attribute has an invalid format.</exception>
        public Method(XmlDocumentationModel model, XmlNode node) : base(model, node)
        {
            // ReSharper disable once PossibleNullReferenceException
            var name = node.Attributes["name"].Value;

            if (!name.StartsWith("M:"))
            {
                throw new FormatException($"Bad method name format: {name}");
            }
            name = name.Substring(2);
            if (!name.StartsWith(Model.AssemblyName + "."))
            {
                throw new FormatException($"Bad method name format: {name}");
            }
            name = name.Substring(Model.AssemblyName.Length + 1);
            var parentheseIdx = name.IndexOf("(");

            if (parentheseIdx > 0)
            {
                var parametersPart = name.Substring(parentheseIdx + 1).TrimEnd(')');
                ParseParameters(parametersPart);
                name = name.Substring(0, parentheseIdx);
            }
            var parts = name.Split(new[] { "." }, StringSplitOptions.None);

            Name = parts[parts.Length - 1];
            var containingTypeName = Model.AssemblyName + "." +
                                     string.Join(".", parts.Take(parts.Length - 1));
            var containingTypeId = "T:" + containingTypeName;
            var containingType   = (Type)Model.Members[containingTypeId];

            ContainingType = containingType;
            var summary = node.SelectSingleNode("summary");

            if (summary != null)
            {
                Documentation = new Documentation(summary);
            }
            var paramNodes = node.SelectNodes("param");

            if (paramNodes != null)
            {
                var i = 0;
                foreach (XmlNode paramNode in paramNodes)
                {
                    if (i < Parameters.Count)
                    {
                        Parameters[i].Documentation = new Documentation(paramNode);
                        Parameters[i].Name          = paramNode.Attributes?["name"]?.Value;
                    }
                    i++;
                }
            }
            var paramTypes = node.SelectNodes("typeparam");

            if (paramTypes != null)
            {
                foreach (XmlNode paramType in paramTypes)
                {
                    TypeParameters.Add(new TypeParameter(paramType));
                }
            }
            var thrownExceptionNodes = node.SelectNodes("exception");

            if (thrownExceptionNodes != null)
            {
                foreach (XmlNode thrownExceptionNode in thrownExceptionNodes)
                {
                    ThrownExceptions.Add(new ThrownException(thrownExceptionNode));
                }
            }
        }