public void UsageMethod() { ICreator[] creators = new ICreator[2]; creators[0] = new ConcreteCreator1(); creators[1] = new ConcreteCreator2(); foreach (ICreator creator in creators) { IProduct product = creator.FactoryMethod(); System.Diagnostics.Debug.WriteLine("The type created was {0}", product.GetType().Name); } }
public void Add(ICreator newPlugin) { if (newPlugin == null) return; IPlugin found = newPlugin.Create(); if (found != null) { found.Setup(); } }
public SingletonRegistration(IRegistrationContext parentContext, ICreator creator) : base(creator) { this.parentContext = parentContext; this.parentContext.Disposing += (o, e) => { var disposable = this.instance as IDisposable; if (disposable != null) disposable.Dispose(); this.instance = this.instanceExpression = null; this.ClearGenerator(); }; }
///// <summary> ///// 填充创建属性(支持日期时间为可空类型)。 ///// </summary> ///// <exception cref="ArgumentNullException"> ///// <paramref name="creation"/> is null. ///// </exception> ///// <typeparam name="TCreation">指定的创建类型。</typeparam> ///// <param name="creation">给定的 <typeparamref name="TCreation"/>。</param> ///// <param name="newCreatedTime">给定的新创建日期对象(可选)。</param> ///// <param name="newCreatedBy">给定的新创建者对象。</param> ///// <returns>返回 <typeparamref name="TCreation"/>。</returns> //public static TCreation PopulateCreation<TCreation>(this TCreation creation, // object newCreatedBy, object? newCreatedTime = null) // where TCreation : IObjectCreation //{ // if (newCreatedTime.IsNotNull()) // creation.SetObjectCreatedTime(newCreatedTime); // creation.SetObjectCreatedBy(newCreatedBy); // return creation; //} ///// <summary> ///// 异步填充创建属性(支持日期时间为可空类型)。 ///// </summary> ///// <exception cref="ArgumentNullException"> ///// <paramref name="creation"/> is null. ///// </exception> ///// <typeparam name="TCreation">指定的创建类型。</typeparam> ///// <param name="creation">给定的 <typeparamref name="TCreation"/>。</param> ///// <param name="newCreatedBy">给定的新创建者对象。</param> ///// <param name="newCreatedTime">给定的新创建日期对象(可选)。</param> ///// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param> ///// <returns>返回一个包含 <typeparamref name="TCreation"/> 的异步操作。</returns> //public static async Task<TCreation> PopulateCreationAsync<TCreation>(this TCreation creation, // object? newCreatedBy, object? newCreatedTime = null, CancellationToken cancellationToken = default) // where TCreation : IObjectCreation //{ // if (newCreatedTime.IsNotNull()) // { // await creation.SetObjectCreatedTimeAsync(newCreatedTime, cancellationToken) // .ConfigureAwaitWithoutContext(); // } // await creation.SetObjectCreatedByAsync(newCreatedBy, cancellationToken) // .ConfigureAwaitWithoutContext(); // return creation; //} #endregion #region ICreator<TCreatedBy> /// <summary> /// 获取创建者。 /// </summary> /// <typeparam name="TCreatedBy">指定的创建者类型(提供对整数、字符串、GUID 等类型的支持)。</typeparam> /// <param name="creator">给定的 <see cref="ICreator{TCreatedBy}"/>。</param> /// <param name="newCreatedByFactory">给定的新创建者工厂方法。</param> /// <returns>返回 <typeparamref name="TCreatedBy"/>(兼容标识或字符串)。</returns> public static TCreatedBy?SetCreatedBy <TCreatedBy>(this ICreator <TCreatedBy> creator, Func <TCreatedBy?, TCreatedBy?> newCreatedByFactory) where TCreatedBy : IEquatable <TCreatedBy> => creator.CreatedBy = newCreatedByFactory(creator.CreatedBy);
public EvolvablePopulation(IPopulation population, Random random, ICreator creator, List <IEvolvable> individuals) : base(creator, random, individuals) { construct(population, 0, 0, 0, null); }
public UnlimitedDynamicPool(ICreator <T> creator, T prototype, int size) : base(creator, prototype, size) { }
public UnlockedTrophyInfo(ICreator creator, ITrophy trophy) { this.Creator = creator; this.Trophy = trophy; }
public TrophyScannerContext(ICommandContext commandContext, ICreator creator, SQLiteDatabase database) { this.CommandContext = commandContext; this.Creator = creator; this.Database = database; }
private string GenerateJrName(ICreator owner, ISpecies species) { return($"{owner.Name} Jr."); }
public StringButcher(IConsole cons, DirectorySpider spider) { BcConsole = cons; Spider = spider; creator = new CmdFactory(spider); }
public HomeViewModel(ICreator creator) { m_creator = creator; }
public EditPlayerModel(IPlayerRetriever playerRetriever, IPlayerUpdater playerUpdater, ICreator <Player> playerCreator, IWebHostEnvironment env) { this.playerRetriever = playerRetriever; this.playerUpdater = playerUpdater; this.playerCreator = playerCreator; this.env = env; }
static void Main(string[] args) { Human woman1 = new Human("Borisova", "Natalia", "Aleksandrovna", new DateTime(1976, 1, 12), Genders.Female, Educations.University); Human woman2 = new Human("Borisova", "Sasha", "Aleksandrova", new DateTime(1974, 1, 12), Genders.Female, Educations.University); Human man = new Human("Dedow", "Kole", "Anatolievich", new DateTime(2000, 12, 1), Genders.Male, Educations.HighSchool); Human.SameSexMarriageEvent += (Genders gender) => Console.WriteLine("Same-sex marriage prohibited"); Human.DivorceEvent += () => Console.WriteLine("It's a pity!"); woman1.Marriage(woman2); woman1.Marriage(man); woman1.Divorce(); Human.PrintMethod consoleOutput = delegate(string message) { Console.WriteLine(message); }; woman1.GetInfo(consoleOutput); man.GetInfo(consoleOutput); Console.ReadKey(); Student businessStudent = new ITStudent("Got", "Fedu", "Dagov"); businessStudent.Plan += () => Console.WriteLine("Business in process"); businessStudent.DoBusiness(); Human first = new Human("Borisova", "Natalia", "Aleksandrovna", new DateTime(1976, 1, 12), Genders.Female, Educations.University); ITStudent prog = new ITStudent("Dedow", "Kole", "Anatolievich", Student.Universities.BSUIR, Student.Degrees.Graduate, new DateTime(2000, 12, 1), Genders.Male, Educations.HighSchool); Philologist philo = new Philologist("Tutov", "Pasha", "-"); Student stud = new ArtStudent("Fulloc", "Nasa", "-"); Student programmerAnother = new ITStudent("Ded", "Lesha", "Anatolievich", Student.Universities.BSU, Student.Degrees.Postgraduate, new DateTime(1999, 1, 16), Genders.Male, Educations.University); Human justHuman = new Philologist("Goga", "Faina", "-"); prog.SetPerformance(); prog.PassSession(); Console.WriteLine(prog); philo.SetPerformance(); philo.PassSession(); Console.WriteLine(philo); Console.WriteLine(philo.SocialSkills); stud.GetExpelled(); Console.WriteLine(stud); Console.ReadKey(); Human firstHuman = new Human("Abram", "Oleg"); Human secondHuman = new Human("Aamov", "Vitta"); Human thirdHuman = new Human("Emoloc", "Domer"); List <Human> people = new List <Human> { firstHuman, secondHuman, thirdHuman }; people.Sort(); foreach (Human hum in people) { Console.WriteLine(hum); } ICreator creator = prog; creator.CreateMasterpiece(); IRelax relaxing = stud; relaxing.DoSport(); relaxing.HaveFun(); Console.ReadKey(); }
protected abstract BasePool <GameObject> GetPool(ICreator <GameObject> creator, GameObject prototype, int size);
// Convenience... protected IRegistration CreateRegistration(IRegistrationContext registrationContext, ICreator creator) { return(this.RegistrationFactory(registrationContext, this.ServiceTypes, creator)); }
public static async Task <IUser> GetDiscordUserFromCreatorAsync(ICommandContext context, ICreator creator) { if (!creator.UserId.HasValue) { return(await GetDiscordUserFromStringAsync(context, creator.Name)); } if (context is null || context.Guild is null) { return(null); } IReadOnlyCollection <IGuildUser> users = await context.Guild.GetUsersAsync(); return(users.Where(user => user.Id == creator.UserId).FirstOrDefault()); }
public HomeController(ICreator creator) { // You will receive it here from Dependency Injection framework or just initialize _pdfCreator = creator ?? new PdfCreator(); }
public WelcomeController(ICreator creator, IAntColonyModelRepository modelRep, IAntColonyResultRepository resultRep) { _creator = creator; _antColonyModelRep = modelRep; _antColonyResultRep = resultRep; }
/// <summary> /// Creates a mapping that specifies a ICreator object. /// </summary> public IMap Map <TContract>(ICreator creator) { return(AddMap <TContract>(creator)); }
public Evolution(Random random, ICreator creator, int breedingPools, int populationPerPool) : base(null, random, new SelectMutateCrossoverPopulationCreator(null, random, creator, populationPerPool, 1), breedingPools) { Init(); }
public GetCat() { parser = new ToCatParser(); creator = new CatCreator(); }
/// <summary> /// Creates a new factory binding handler. /// </summary> /// <param name="injector">The injector to pass to factory proxies.</param> /// <param name="loggerFactory">The logger factory used to create an ILogger.</param> /// <param name="creator">The creator to pass to factory proxies.</param> internal FactoryBindingHandler(Injector injector, ILoggerFactory loggerFactory, ICreator creator) : base(injector, loggerFactory) { this.creator = creator; }
public virtual async Task <ICreator> GetCreatorAsync(ICreator creator) => await Task.FromResult(creator);
public static void ContraVariance(ICreator <Animal> creator) { creator.Create( ); }
public void RegisterAlgorithm(string algorithmName, ICreator creator) { _algorithms.Add(algorithmName, creator); }
public EvolvablePopulation(IPopulation population, Random random, ICreator creator, int populationSize) : base(creator, random, populationSize) { construct(population, 0, 0, 0, null); }
public static async Task <UserRank> GetRankAsync(this SQLiteDatabase database, ICreator creator, UserInfoQueryFlags flags = UserInfoQueryFlags.Default) { return((await database.GetRanksAsync()) .Where(x => x.User.Id == creator.UserId || ((flags.HasFlag(UserInfoQueryFlags.MatchEither) || x.User.Id == UserInfo.NullId) && x.User.Username == creator.Name)) .FirstOrDefault()); }
protected EvolvablePopulation(IPopulation parentPopulation, Random random, ICreator creator, int evolveMutations, int evolveCrossovers, int evolveFitnessEvaluations, List <double> fitnessHistory, List <IEvolvable> individuals, IEvolvable bestOfAllTime, int populationSize, long generations, long mutations, long crossovers, long fitnessEvaluations, double foodConsumedInLifetime) : base(creator, random, individuals, bestOfAllTime, populationSize, generations, mutations, crossovers, fitnessEvaluations, foodConsumedInLifetime) { construct(parentPopulation, evolveMutations, evolveCrossovers, evolveFitnessEvaluations, fitnessHistory); }
public TransientRegistration(ICreator creator) : base(creator) { }
/// <summary> /// 异步获取创建者。 /// </summary> /// <typeparam name="TCreatedBy">指定的创建者类型(提供对整数、字符串、GUID 等类型的支持)。</typeparam> /// <param name="creator">给定的 <see cref="ICreator{TCreatedBy}"/>。</param> /// <param name="newCreatedByFactory">给定的新创建者工厂方法。</param> /// <param name="cancellationToken">给定的 <see cref="CancellationToken"/>(可选)。</param> /// <returns>返回一个包含 <typeparamref name="TCreatedBy"/>(兼容标识或字符串)的异步操作。</returns> public static ValueTask <TCreatedBy?> SetCreatedByAsync <TCreatedBy>(this ICreator <TCreatedBy> creator, Func <TCreatedBy?, TCreatedBy?> newCreatedByFactory, CancellationToken cancellationToken = default) where TCreatedBy : IEquatable <TCreatedBy> => cancellationToken.RunValueTask(() => creator.CreatedBy = newCreatedByFactory(creator.CreatedBy));
public static async Task <ICreator> GetCreatorAsync(this SQLiteDatabase database, ICreator creator, UserInfoQueryFlags flags = UserInfoQueryFlags.Default) { ICreator result = null; // Note that we may have a null username or a null user ID. // At least one of them has to be non-null. if (!string.IsNullOrEmpty(creator.Name) || creator.UserId.HasValue) { // If we've been given a user ID, get all species records where that user is the owner. // If we've just been given a username, we'll go by username instead. string query; if (flags.HasFlag(UserInfoQueryFlags.MatchEither)) { query = "SELECT owner, user_id, timestamp FROM Species WHERE user_id = $user_id OR owner = $owner"; } else { if (creator.UserId.HasValue) { query = "SELECT owner, user_id, timestamp FROM Species WHERE user_id = $user_id"; } else { query = "SELECT owner, user_id, timestamp FROM Species WHERE owner = $owner COLLATE NOCASE"; } } using (SQLiteCommand cmd = new SQLiteCommand(query)) { cmd.Parameters.AddWithValue("$user_id", creator.UserId); cmd.Parameters.AddWithValue("$owner", creator.Name); IEnumerable <DataRow> rows = await database.GetRowsAsync(cmd); if (rows.Count() > 0) { ulong?userId = rows.Select(row => row.IsNull("user_id") ? null : (ulong?)row.Field <long>("user_id")) .FirstOrDefault(id => id.HasValue); string username = rows.Select(row => row.IsNull("owner") ? string.Empty : row.Field <string>("owner")) .FirstOrDefault(name => !string.IsNullOrEmpty(name)); if (userId.HasValue || !string.IsNullOrEmpty(username)) { long firstSpeciesTimestamp = rows.Select(row => (long)row.Field <decimal>("timestamp")).OrderBy(timestamp => timestamp).FirstOrDefault(); long lastSpeciesTimestamp = rows.Select(rowx => (long)rowx.Field <decimal>("timestamp")).OrderByDescending(timestamp => timestamp).FirstOrDefault(); result = new Creator(userId, username) { SpeciesCount = rows.Count(), FirstSpeciesDate = firstSpeciesTimestamp > 0 ? DateUtilities.GetDateFromTimestamp(firstSpeciesTimestamp) : default(DateTimeOffset?), LastSpeciesDate = lastSpeciesTimestamp > 0 ? DateUtilities.GetDateFromTimestamp(lastSpeciesTimestamp) : default(DateTimeOffset?) }; } } } } return(result); }
public TabPersonalSalesPerformanceViewModel(IResourceProvider text, IWindowManager window, ICreator creator) { m_creator = creator; m_window = window; DisplayName = text.GetText("PersonalSalesPerformance"); }
protected RegistrationBase(ICreator creator) { this.Creator = creator; }
// Convenience... protected IRegistration CreateRegistration(IRegistrationContext registrationContext, ICreator creator) { return this.RegistrationFactory(registrationContext, this.ServiceTypes, creator); }
public GameUpdater(ICreator <Game> gameCreator, IDeleter <Game> gameDeleter, ITeamUpdater teamUpdater) { this.gameCreator = gameCreator; this.gameDeleter = gameDeleter; this.teamUpdater = teamUpdater; }
// Public members public static async Task <Gotchi> GetGotchiOrReplyAsync(this OfcModuleBase moduleBase, ICreator creator) { Gotchi gotchi = await moduleBase.Db.GetGotchiAsync(creator); if (await moduleBase.ReplyValidateGotchiAsync(gotchi)) { return(gotchi); } return(null); }