<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SRPCommon.UserProperties;

namespace ShaderEditorApp.ViewModel.Properties
{
	static class PropertyViewModelFactory
	{
		private static bool _initialised = false;
		private static IEnumerable<IPropertyViewModelFactory> _factories;

		// Create a new view-model object for a user property.
		public static PropertyViewModel CreateViewModel(IUserProperty property)
		{
			if (!_initialised)
			{
				FindFactories();
				_initialised = true;
			}

			// Find the first factory that accepts the property.
			var factory = _factories.FirstOrDefault(x => x.SupportsProperty(property));
			if (factory != null)
			{
				return factory.CreateInstance(property);
			}

			throw new ArgumentException("Unsupported property type");
		}

		private static void FindFactories()
		{
			// Find all types that implement the factory interface.
			_factories = typeof(PropertyViewModelFactory).Assembly.GetTypes()
				.Where(type => !type.IsAbstract && type.GetInterfaces().Any(i => i == typeof(IPropertyViewModelFactory)))
				.Select(type => (IPropertyViewModelFactory)Activator.CreateInstance(type))
				.OrderBy(factory => factory.Priority)
				.ToList();
		}
	}

	// Interface for classes that create property view models.
	interface IPropertyViewModelFactory
	{
		bool SupportsProperty(IUserProperty property);
		PropertyViewModel CreateInstance(IUserProperty property);

		// Priority to allow selection order to be controlled. Lower numbers run first.
		int Priority { get; }
	}
}
<commit_msg>Minor cleanup<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using SRPCommon.UserProperties;

namespace ShaderEditorApp.ViewModel.Properties
{
	static class PropertyViewModelFactory
	{
		private static Lazy<IEnumerable<IPropertyViewModelFactory>> _factories = new Lazy<IEnumerable<IPropertyViewModelFactory>>(FindFactories);

		// Create a new view-model object for a user property.
		public static PropertyViewModel CreateViewModel(IUserProperty property)
		{
			// Find the first factory that accepts the property.
			var factory = _factories.Value.FirstOrDefault(x => x.SupportsProperty(property));
			if (factory != null)
			{
				return factory.CreateInstance(property);
			}

			throw new ArgumentException("Unsupported property type");
		}

		private static IEnumerable<IPropertyViewModelFactory> FindFactories()
		{
			// Find all types that implement the factory interface in this assembly.
			return typeof(PropertyViewModelFactory).Assembly.GetTypes()
				.Where(type => !type.IsAbstract && type.GetInterfaces().Any(i => i == typeof(IPropertyViewModelFactory)))
				.Select(type => (IPropertyViewModelFactory)Activator.CreateInstance(type))
				.OrderBy(factory => factory.Priority)
				.ToList();
		}
	}

	// Interface for classes that create property view models.
	interface IPropertyViewModelFactory
	{
		bool SupportsProperty(IUserProperty property);
		PropertyViewModel CreateInstance(IUserProperty property);

		// Priority to allow selection order to be controlled. Lower numbers run first.
		int Priority { get; }
	}
}

{'fraction_non_alphanumeric': 0.09019730660820545, 'fraction_numerical': 0.0, 'mean_word_length': 4.713774597495528, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '257076', 'n_tokens_mistral': 973, 'n_tokens_neox': 839, 'n_words': 236}