AvalonStudio.Program.RunAddReference C# (CSharp) Method

RunAddReference() private static method

private static RunAddReference ( AddReferenceOptions options ) : int
options AddReferenceOptions
return int
		private static int RunAddReference(AddReferenceOptions options)
		{
			var solution = LoadSolution(options);
			var project = FindProject(solution, options.Project) as CPlusPlusProject;

			if (project != null)
			{
				var currentReference = project.References.Where(r => r.Name == options.Name).FirstOrDefault();

				if (currentReference != null)
				{
					project.UnloadedReferences[project.References.IndexOf(currentReference)] = new Reference
					{
						Name = options.Name,
						GitUrl = options.GitUrl,
						Revision = options.Revision
					};
					Console.WriteLine("Reference successfully updated.");
				}
				else
				{
					var add = true;

					if (string.IsNullOrEmpty(options.GitUrl))
					{
						var reference = FindProject(solution, options.Name);

						if (reference == null)
						{
							add = false;
						}
					}

					if (add)
					{
						project.UnloadedReferences.Add(new Reference
						{
							Name = options.Name,
							GitUrl = options.GitUrl,
							Revision = options.Revision
						});
						Console.WriteLine("Reference added successfully.");
					}
					else
					{
						Console.WriteLine("Local reference does not exist, try creating the project first.");
					}
				}

				project.Save();
			}

			return 1;
		}