public static IEnumerable <Project> GetProjects(string solutionFile, string configurationName, string platformName) { var projects = new List <Project>(); var solutionParser = SolutionParserType.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic).First().Invoke(null); using (var streamReader = new StreamReader(solutionFile)) { SolutionReaderPropertyInfo.SetValue(solutionParser, streamReader, null); ParseSolutionMethodInfo.Invoke(solutionParser, null); var solutionDirectory = Path.GetDirectoryName(solutionFile); var array = (Array)ProjectsPropertyInfo.GetValue(solutionParser, null); for (int i = 0; i < array.Length; i++) { var projectInSolution = array.GetValue(i); if (!ObjectHelper.AreEqual(ProjectTypePropertyInfo.GetValue(projectInSolution), KnownToBeMsBuildFormat)) { continue; } var relativePath = (string)RelativePathPropertyInfo.GetValue(projectInSolution); var projectFile = Path.Combine(solutionDirectory, relativePath); var project = LoadProject(projectFile, configurationName, platformName, solutionDirectory); if (project != null) { projects.Add(project); } } } return(projects); }
private async Task ApplyConfigurationInternalAsync(bool force = false) { var value = ConfigurationService.GetRoamingValue(Key, DefaultValue); if (!force && ObjectHelper.AreEqual(value, _lastKnownValue)) { return; } _lastKnownValue = value; try { await ApplyConfigurationAsync(value); } catch (Exception ex) { Log.Error(ex, $"Failed to apply configuration value for '{Key}'"); throw; } var status = GetStatus(value); if (!string.IsNullOrWhiteSpace(status)) { Log.Info(status); } }
/// <summary> /// Called when a property has changed. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.ComponentModel.PropertyChangedEventArgs"/> instance containing the event data.</param> /// <remarks> /// This method must be public because the <see cref="IWeakEventListener"/> is used. /// </remarks> public void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { var modelBase = sender as ModelBase; if (modelBase != null) { if ((string.CompareOrdinal(e.PropertyName, "INotifyDataErrorInfo.HasErrors") == 0) || (string.CompareOrdinal(e.PropertyName, "INotifyDataWarningInfo.HasWarnings") == 0) || (string.CompareOrdinal(e.PropertyName, "IsDirty") == 0)) { return; } } if (ShouldPropertyBeIgnored(sender, e.PropertyName)) { return; } var oldValue = _previousPropertyValues[e.PropertyName]; var newValue = PropertyHelper.GetPropertyValue(sender, e.PropertyName, false); // CTL-719: ignore duplicate properties if (ObjectHelper.AreEqual(oldValue, newValue)) { return; } _previousPropertyValues[e.PropertyName] = newValue; MementoService.Add(new PropertyChangeUndo(sender, e.PropertyName, oldValue, newValue, Tag)); }
public static IEnumerable <Project> GetProjects(string solutionFile, string configurationName, string platformName) { var projects = new List <Project>(); var solutionParser = ((object)Impromptu.InvokeConstructor(SolutionParserType)).ActLike <ISolutionParser>(); using (var streamReader = new StreamReader(solutionFile)) { solutionParser.SolutionReader = streamReader; solutionParser.ParseSolution(); var solutionDirectory = Path.GetDirectoryName(solutionFile); var projectsInSolution = solutionParser.Projects.AllActLike <IProjectInSolution>(); foreach (var projectInSolution in projectsInSolution) { var isKnownToBeMsBuildFormat = ObjectHelper.AreEqual(projectInSolution.ProjectType, KnownToBeMsBuildFormat); var isSelectedForBuild = ProjectIsSelectedForBuild(projectInSolution, configurationName, platformName); if (!isKnownToBeMsBuildFormat || !isSelectedForBuild) { continue; } var relativePath = projectInSolution.RelativePath; var projectFile = Path.Combine(solutionDirectory, relativePath); var project = LoadProject(projectFile, configurationName, platformName, solutionDirectory); if (project != null) { projects.Add(project); } } } return(projects); }
public string GetTagName(IValidationResult validationResult) { var tagName = ExtractTagName(validationResult); List <IValidationResult> results; if (!_cache.TryGetValue(tagName, out results)) { results = new List <IValidationResult>(); _cache.Add(tagName, results); } var exists = (from result in results where result.Message.EqualsIgnoreCase(validationResult.Message) && result.ValidationResultType == validationResult.ValidationResultType && ObjectHelper.AreEqual(result.Tag, validationResult.Tag) select result).Any(); if (!exists) { results.Add(validationResult); } return(tagName); }
public override bool Equals([AllowNull] IFieldValidationResult x, [AllowNull] IFieldValidationResult y) { if (x is null && y is null) { return(true); } if (x is null || y is null) { return(false); } if (x.PropertyName != y.PropertyName) { return(false); } if (x.Message != y.Message) { return(false); } if (!ObjectHelper.AreEqual(x.Tag, y.Tag)) { return(false); } return(true); }
public void WorksWithData() { LogManager.AddDebugListener(); var log = new Log(typeof(int)); LogMessageEventArgs eventArgs = null; log.LogMessage += (sender, e) => eventArgs = e; var threadId = ThreadHelper.GetCurrentThreadId(); log.InfoWithData("log message", new LogData { { "ThreadId", threadId } }); Assert.IsNotNull(eventArgs); Assert.AreEqual(log, eventArgs.Log); Assert.AreEqual(LogEvent.Info, eventArgs.LogEvent); Assert.AreEqual("log message", eventArgs.Message); var logData = eventArgs.LogData; Assert.IsNotNull(logData); Assert.IsTrue(ObjectHelper.AreEqual(logData["ThreadId"], threadId)); }
private TableViewColumn GetColumnByTitle(string title) { Argument.IsNotNullOrWhitespace("title", title); return((from column in Columns where ObjectHelper.AreEqual(column.Title, title) select column).FirstOrDefault()); }
public void ReturnsFalseForOneNullValue() { object obj1 = 5; object obj2 = null; Assert.IsFalse(ObjectHelper.AreEqual(obj1, obj2)); Assert.IsFalse(ObjectHelper.AreEqual(obj2, obj1)); }
public void ReturnsTrueForTwoDbNullValues() { object obj1 = DBNull.Value; object obj2 = DBNull.Value; Assert.IsTrue(ObjectHelper.AreEqual(obj1, obj2)); Assert.IsTrue(ObjectHelper.AreEqual(obj2, obj1)); }
public void ReturnsTrueForBoxedEqualIntegers() { object obj1 = 5; object obj2 = 5; Assert.IsTrue(ObjectHelper.AreEqual(obj1, obj2)); Assert.IsTrue(ObjectHelper.AreEqual(obj2, obj1)); }
public void ReturnsFalseForBoxedDifferentIntegers() { object obj1 = 5; object obj2 = 6; Assert.IsFalse(ObjectHelper.AreEqual(obj1, obj2)); Assert.IsFalse(ObjectHelper.AreEqual(obj2, obj1)); }
public void ReturnsTrueForTwoNullValues() { object obj1 = null; object obj2 = null; Assert.IsTrue(ObjectHelper.AreEqual(obj1, obj2)); Assert.IsTrue(ObjectHelper.AreEqual(obj2, obj1)); }
/// <typeparam name="T"></typeparam> /// <param name="registrationConventionHandler">The registration convention handler.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">The <paramref name="registrationConventionHandler"/> is <c>null</c>.</exception> public static IRegistrationConventionHandler IncludeType <T>(this IRegistrationConventionHandler registrationConventionHandler) where T : class { Argument.IsNotNull("registrationConventionHandler", registrationConventionHandler); registrationConventionHandler.IncludeTypesWhere(type => ObjectHelper.AreEqual(type, typeof(T))); return(registrationConventionHandler); }
/// <summary> /// Excludes the assembly. /// </summary> /// <typeparam name="TAssembly">The type of the assembly.</typeparam> /// <param name="registrationConventionHandler">The registration convention handler.</param> /// <returns></returns> /// <exception cref="System.ArgumentNullException">The <paramref name="registrationConventionHandler"/> is <c>null</c>.</exception> public static IRegistrationConventionHandler ExcludeAssembly <TAssembly>(this IRegistrationConventionHandler registrationConventionHandler) where TAssembly : Assembly { Argument.IsNotNull("registrationConventionHandler", registrationConventionHandler); registrationConventionHandler.ExcludeAssembliesWhere(assembly => ObjectHelper.AreEqual(assembly.GetType(), typeof(TAssembly))); return(registrationConventionHandler); }
protected override void ValidateBusinessRules(List <IBusinessRuleValidationResult> validationResults) { if (!string.IsNullOrWhiteSpace(XAxis) && !string.IsNullOrWhiteSpace(YAxis)) { if (ObjectHelper.AreEqual(XAxis, YAxis)) { validationResults.Add(BusinessRuleValidationResult.CreateError("X and Y axis cannot be the same")); } } }
/// <summary> /// Gets the first or default instance of the specified view model. /// </summary> /// <param name="viewModelType">Type of the view mode.</param> /// <returns> /// The <see cref="IViewModel"/> or <c>null</c> if the view model is not registered. /// </returns> /// <exception cref="System.ArgumentException">The <paramref name="viewModelType"/> is not of type <see cref="IViewModel"/>.</exception> public IViewModel GetFirstOrDefaultInstance(Type viewModelType) { Argument.IsOfType("viewModelType", viewModelType, typeof(IViewModel)); return(_managedViewModelsLock.PerformRead(() => { return GetAllViewModels(_managedViewModels) .FirstOrDefault(viewModel => ObjectHelper.AreEqual(viewModel.GetType(), viewModelType)); })); }
/// <summary> /// Resolves the type from a known container. /// </summary> /// <param name="serviceType">Type of the service.</param> /// <param name="tag">The tag to register the service with. The default value is <c>null</c>.</param> /// <returns>An instance of the type registered on the service.</returns> /// <exception cref="ArgumentNullException">The <paramref name="serviceType"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException">The type is not found in any container.</exception> private object ResolveTypeFromKnownContainer(Type serviceType, object tag) { Argument.IsNotNull("serviceType", serviceType); lock (_syncObject) { // First check if we are the container var serviceInfo = new ServiceInfo(serviceType, tag); var registeredTypeInfo = _registeredTypes[serviceInfo]; if (ObjectHelper.AreEqual(registeredTypeInfo.OriginalContainer, this)) { object instance = CreateServiceInstance(registeredTypeInfo.ImplementingType); if (instance != null) { if (IsTypeRegisteredAsSingleton(serviceType, tag)) { RegisterInstance(serviceType, instance, tag, this); } } return(instance); } // Get the type from the original container, it might be a specific instance foreach (var externalContainerKeyValuePair in _externalContainers) { if (ObjectHelper.AreEqual(externalContainerKeyValuePair.Value, registeredTypeInfo.OriginalContainer)) { var registrationInfo = externalContainerKeyValuePair.Value.GetRegistrationInfo(externalContainerKeyValuePair.Key, serviceType); object instance = externalContainerKeyValuePair.Value.ResolveType(externalContainerKeyValuePair.Key, serviceType); if (registrationInfo.RegistrationType == RegistrationType.Singleton) { RegisterInstance(serviceType, instance, tag, externalContainerKeyValuePair.Value); } else { // Note: we cannot register a transient because we don't know the implementing type } return(instance); } } } var error = string.Format("The type '{0}' is registered, so why weren't we able to retrieve it?", serviceType.FullName); Log.Error(error); throw new ArgumentOutOfRangeException(error); }
/// <summary> /// Sets the property value. /// </summary> /// <param name="propertyName">Name of the property.</param> /// <param name="value">The value.</param> /// <exception cref="ArgumentException">The <paramref name="propertyName" /> is <c>null</c> or whitespace.</exception> public void SetPropertyValue(string propertyName, object value) { Argument.IsNotNullOrWhitespace("propertyName", propertyName); lock (_lockObject) { if (!_properties.ContainsKey(propertyName) || !ObjectHelper.AreEqual(_properties[propertyName], value)) { _properties[propertyName] = value; RaisePropertyChanged(propertyName); } } }
/// <summary> /// Checks whether a collection is the same as another collection. /// </summary> /// <param name="listA">The list A.</param> /// <param name="listB">The list B.</param> /// <returns> /// True if the two collections contain all the same items in the same order. /// </returns> public static bool IsEqualTo(IEnumerable listA, IEnumerable listB) { if (ReferenceEquals(listA, listB)) { return(true); } if (listA == listB) { return(true); } if ((listA == null) || (listB == null)) { return(false); } var enumeratorA = listA.GetEnumerator(); var enumeratorB = listB.GetEnumerator(); var enumAHasValue = enumeratorA.MoveNext(); var enumBHasValue = enumeratorB.MoveNext(); while (enumAHasValue && enumBHasValue) { var currentA = enumeratorA.Current; var currentB = enumeratorB.Current; if (currentA == currentB) { enumAHasValue = enumeratorA.MoveNext(); enumBHasValue = enumeratorB.MoveNext(); continue; } if (!ObjectHelper.AreEqual(currentA, currentB)) { return(false); } enumAHasValue = enumeratorA.MoveNext(); enumBHasValue = enumeratorB.MoveNext(); } // If we get here, and both enumerables don't have any value left, they are equal return(!(enumAHasValue || enumBHasValue)); }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var filterScheme = values[0] as FilterScheme; var selectedFilterScheme = values[1] as FilterScheme; var visibility = Visibility.Collapsed; if (filterScheme is null) { return(visibility); } if (ObjectHelper.AreEqual(selectedFilterScheme, filterScheme)) { visibility = Visibility.Visible; } return(visibility); }
private async Task ApplyConfigurationAsync(bool force = false) { var value = ConfigurationService.GetValue(Key, DefaultValue); if (!force && ObjectHelper.AreEqual(value, _lastKnownValue)) { return; } _lastKnownValue = value; await ApplyConfigurationAsync(value); var status = GetStatus(value); if (!string.IsNullOrWhiteSpace(status)) { Log.Info(status); } }
/// <summary> /// Initializes a new instance of the <see cref="ContentPage" /> class. /// </summary> /// <param name="viewModel">The view model</param> public ContentPage(IViewModel viewModel) { _userControlLogic = new UserControlLogic(this, null, viewModel); _userControlLogic.TargetViewPropertyChanged += (sender, e) => { OnPropertyChanged(e.PropertyName); }; _userControlLogic.ViewModelClosedAsync += OnViewModelClosedAsync; _userControlLogic.ViewModelChanged += (sender, args) => { if (!ObjectHelper.AreEqual(BindingContext, _userControlLogic.ViewModel)) { BindingContext = _userControlLogic.ViewModel; } }; _userControlLogic.ViewModelPropertyChanged += (sender, e) => { OnViewModelPropertyChanged(e); ViewModelPropertyChanged?.Invoke(this, e); }; Loaded += (sender, e) => { // _viewLoaded?.Invoke(this); // OnLoaded(e); }; Unloaded += (sender, e) => { // _viewUnloaded?.Invoke(this); // OnUnloaded(e); }; DataContextChanged += OnDataContextChanged; }
/// <summary> /// Gets the first or default instance of the specified view type. /// </summary> /// <param name="viewType">Type of the view.</param> /// <returns> /// The <see cref="IViewModel" /> or <c>null</c> if the view model is not registered. /// </returns> /// <exception cref="System.ArgumentException">The <paramref name="viewType"/> is not of type <see cref="IView"/>.</exception> public IView GetFirstOrDefaultInstance(Type viewType) { Argument.IsOfType("viewType", viewType, typeof(IView)); return(ActiveViews.FirstOrDefault(view => ObjectHelper.AreEqual(view.GetType(), viewType))); }
/// <summary> /// Gets the first or default instance of the specified view model. /// </summary> /// <param name="viewModelType">Type of the view mode.</param> /// <returns> /// The <see cref="IViewModel"/> or <c>null</c> if the view model is not registered. /// </returns> /// <exception cref="ArgumentNullException">The <paramref name="viewModelType"/> is <c>null</c>.</exception> public IViewModel GetFirstOrDefaultInstance(Type viewModelType) { Argument.IsNotNull("viewModeType", viewModelType); return(ActiveViewModels.FirstOrDefault(row => ObjectHelper.AreEqual(row.GetType(), viewModelType))); }
/// <summary> /// Compares the <paramref name="firstTag"/> with the <paramref name="secondTag"/>. /// <para/> /// This method is introduced because a string comparison fails when using ==. /// </summary> /// <param name="firstTag">The first tag.</param> /// <param name="secondTag">The second tag.</param> /// <returns> /// <c>true</c> if the tags are equal; otherwise <c>false</c>. /// </returns> /// <remarks> /// When both tags are <c>null</c>, the tags are considered equal. /// </remarks> public static bool AreTagsEqual(object firstTag, object secondTag) { return(ObjectHelper.AreEqual(firstTag, secondTag)); }