public void GetsNames() { Assert.AreEqual("MockLogger", WithName.TypeName(typeof(MockLogger))); Assert.AreEqual("List`1", WithName.TypeName(typeof(List <>))); Assert.IsNull(WithName.Default(typeof(MockLogger))); Assert.IsNull(WithName.Default(typeof(List <>))); }
private static void Example_02() { new UserRepository() .Find(WithName.New("Виктор")) .ToList() .ForEach(Console.WriteLine); Console.WriteLine(); new UserRepository() .Find(WithName.New("Виктор").Not()) .ToList() .ForEach(Console.WriteLine); Console.WriteLine(); new UserRepository() .Find(new WithName("Виктор")) .ToList() .ForEach(Console.WriteLine); Console.WriteLine(); new UserRepository() .Find(!WithName.New("Виктор")) .ToList() .ForEach(Console.WriteLine); }
/// <summary>Registers the type mappings with the Unity container.</summary> /// <param name="container">The unity container to configure.</param> /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks> public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. // container.LoadConfiguration(); // TODO: Register your types here // container.RegisterType<IProductRepository, ProductRepository>(); // Add Extension container.AddNewExtension <ResolverUnityExtension>(); container.AddNewExtension <DataUnityExtension>(); // TODO: Register your types here container.RegisterTypes(AllClasses.FromLoadedAssemblies().Where(c => (c.Namespace.StartsWith("CrossCutting") || c.Namespace.StartsWith("SMS.Repository") || c.Namespace.StartsWith("SMS.Services") ) && !c.Namespace.StartsWith("StoreManagementSystem.Controllers") && !c.Namespace.StartsWith("SMS.Repository.Context")), WithMappings.FromAllInterfacesInSameAssembly, type => { if (type.Name.StartsWith("Mock")) { return("Mock"); } return(WithName.Default(type)); }, WithLifetime.ContainerControlled ); }
public void Test_1() { var users = Users.AsQueryable() .Where(new Administrators()) .ToList(); Assert.Single(users); Assert.Equal(1, users.Single().Id); Assert.Equal(18, users.Single().Age); users = Users.AsQueryable() .Where(Administrators.New()) .ToList(); Assert.Single(users); Assert.Equal(1, users.Single().Id); Assert.Equal(18, users.Single().Age); users = Users.AsQueryable() .Where(WithName.New("Виктор")) .ToList(); Assert.Equal(2, users.Count); Assert.Equal(27, users.First().Age); Assert.Equal(18, users.Last().Age); }
public MainWindow() { InitializeComponent(); firstUnity.RegisterInstance(typeof(IProductFactory), new ShoeProductFactory()); var section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); section.Configure(secondUnity); thirdUnity.RegisterTypes( AllClasses.FromLoadedAssemblies() .Where(x => x.IsPublic && x.GetInterfaces().Any() && !x.IsAbstract && x.IsClass), WithMappings.FromAllInterfacesInSameAssembly, type => (thirdUnity.Registrations .Select(x => x.RegisteredType) .Any(r => type.GetInterfaces().Contains(r)))?WithName.TypeName(type):WithName.Default(type), WithLifetime.ContainerControlled); forthUnity.RegisterInstance(typeof(IProductFactory), new JacketProductFactory(), WithLifetime.ExternallyControlled(typeof(IProductFactory))); }
public static void All(IUnityContainer c) { if (c == null) { return; } if (Container == null) { Container = c; } List <Assembly> list = AppDomain.CurrentDomain.GetAssemblies().ToList(); foreach (Assembly assembly in list) { IEnumerable <Type> types = from type in GetLoadableTypes(assembly) where Attribute.IsDefined(type, typeof(ImplementAttribute)) select type; foreach (Type to in types) { ImplementAttribute custom = to.GetCustomAttributes <ImplementAttribute>().SingleOrDefault(); if (custom != null) { Container.RegisterType(custom.FromType, to, WithName.Default(to), WithLifetime.ContainerControlled(to)); } } } }
private static void Example_03() { new UserRepository() .Find(WithName.New("Виктор") & Administrators.New()) .ToList() .ForEach(Console.WriteLine); Console.WriteLine(); new UserRepository() .Find(WithName.New("Виктор").And(new Administrators())) .ToList() .ForEach(Console.WriteLine); }
private static void Example_04() { new UserRepository() .Find(WithName.New("Денис") | Administrators.New()) .ToList() .ForEach(Console.WriteLine); Console.WriteLine(); new UserRepository() .Find(WithName.New("Денис").Or(new Administrators())) .ToList() .ForEach(Console.WriteLine); }
public override int GetHashCode() { int hash = 1; if (DocId != 0) { hash ^= DocId.GetHashCode(); } if (WithName != false) { hash ^= WithName.GetHashCode(); } hash ^= codes_.GetHashCode(); return(hash); }
public void Test_3() { var users = Users.AsQueryable() .Where(Administrators.New() | WithName.New("Виктор")) .ToList(); Assert.Equal(2, users.Count); Assert.Equal(27, users.First().Age); Assert.Equal(18, users.Last().Age); users = Users.AsQueryable() .Where(Administrators.New().Or(WithName.New("Алексей")).Not()) .ToList(); Assert.Equal(7, users.Count); }
public void Test_2() { var users = Users.AsQueryable() .Where(Administrators.New() & WithName.New("Виктор")) .ToList(); Assert.Single(users); Assert.Equal(1, users.Single().Id); Assert.Equal(18, users.Single().Age); users = Users.AsQueryable() .Where(Administrators.New().And(WithName.New("Алексей"))) .ToList(); Assert.Empty(users); }
private FatFileLocation ChangeDirectory(string[] path, int pointer) { uint CurrentCluster = RootCluster; var Compare = new WithName(null); FatFileLocation location = null; while (pointer < path.Length) { Compare.Name = path[pointer]; location = FindEntry(Compare, CurrentCluster); if (location == null) { return(null); } CurrentCluster = location.FirstCluster; pointer++; } return(location); }
public override Func <Type, string> GetName() { return(type => unity.Registrations.Select(x => x.RegisteredType).Any(r => r.GetInterfaces().Contains(r)) ? WithName.TypeName(type) : WithName.Default(type)); }
public static string AttributeNameOrDefault(Type type) { return(UnityNamedInstance.AttributeName(type) ?? WithName.Default(type)); }
public override Func <Type, String> GetName() { return(t => WithName.Default(t)); }
private static string SelectNameToRegister(Type type) { var attributes = type.GetCustomAttributes(false); return(WithName.Default(type)); }