public SelectOperation <TDataType> Alias(string tableColumn, Expression <Func <TDataType, object> > alias) { var aliasName = PropertyHelper.GetProperty(alias).Name; _builder.AliasSelectColumn(tableColumn, aliasName); return(this); }
public void Cache_At_Least_Doubles_Performance() { var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 10000; i++) { Resources.Name.First.Split(Config.SEPARATOR); } sw.Stop(); var uncachedElapsed = sw.ElapsedMilliseconds; sw.Reset(); sw.Start(); for (int i = 0; i < 10000; i++) { ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); } sw.Stop(); var cachedElapsed = sw.ElapsedMilliseconds; Assert.That(uncachedElapsed, Is.GreaterThan(2 * cachedElapsed)); }
public SelectOperation <TDataType> OrEquals(Expression <Func <TDataType, object> > field, object value) { var column = PropertyHelper.GetProperty(field).Name; _builder.Or(column, value); return(this); }
/// <summary> /// Generates an Italian Fiscal Code /// </summary> /// <param name="lastName">Last name of the holder</param> /// <param name="firstName">First name of the holder</param> /// <param name="birthday">Birthday of the holder</param> /// <param name="validChecksum"> /// Indicates whether the generated Fiscal Code has a valid checksum or not /// </param> /// <returns>The generated Fiscal Code</returns> /// <remarks>Description of the Fiscal Code standard is at https://en.wikipedia.org/wiki/Italian_fiscal_code_card</remarks> public static string FiscalCode(string lastName, string firstName, DateTime birthday, bool validChecksum = true) { char[] monthChars = { 'A', 'B', 'C', 'D', 'E', 'H', 'L', 'M', 'P', 'R', 'S', 'T' }; if (string.IsNullOrWhiteSpace(lastName)) { lastName = Name.Last(); } if (string.IsNullOrWhiteSpace(firstName)) { firstName = Name.First(); } var male = RandomNumber.Next(2) == 0; // even probability to be male or female var sb = new StringBuilder(); sb.Append(GetFiscalCodeSqueezedName(lastName, false)); sb.Append(GetFiscalCodeSqueezedName(firstName, true)); sb.Append((birthday.Year % 100).ToString("00", CultureInfo.InvariantCulture)); sb.Append(monthChars[birthday.Month - 1]); sb.Append((birthday.Day + (male ? 0 : 40)).ToString("00", CultureInfo.InvariantCulture)); sb.Append(ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.FiscalCode_TownCodes.Codes)).Random()); var checksum = ComputeChecksumFiscalCode(sb.ToString(), validChecksum); sb.Append(checksum); return(sb.ToString()); }
public static async Task Set_All_Properties_From_Prototype_Except_Id_DateOfBirth_EmailConfirmed() { // Arrange var userManagerStub = UserManagerTestHelper.CreateUserManagerFake(); userManagerStub.Setup(x => x.CreateAsync(It.IsAny <User>(), It.IsAny <string>())).Returns(Task.FromResult(IdentityResult.Success)); var dateTimeServiceStub = Mock.Of <IDateTime>(); var prototypeMock = new Faker <User>().Generate(); var passwordStub = string.Empty; var command = new CreateSuperAdminCommand(userManagerStub.Object, dateTimeServiceStub, prototypeMock, passwordStub); // Act var superAdmin = await command.Do(); // Assert Assert.NotNull(superAdmin); var propertiesToIgnore = new[] { PropertyHelper.GetProperty((User user) => user.Id), PropertyHelper.GetProperty((User user) => user.DateOfBirth), PropertyHelper.GetProperty((User user) => user.EmailConfirmed) }; var propertiesToVerify = typeof(User).GetProperties(BindingFlags.Instance | BindingFlags.Public).Except(propertiesToIgnore); foreach (var propertyToVerify in propertiesToVerify) { var expected = propertyToVerify.GetValue(prototypeMock); var actual = propertyToVerify.GetValue(superAdmin); Assert.Equal(expected, actual); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["PropertyIdReport"] == null || Session["YearReport"] == null) { Page.RegisterClientScriptBlock("closeIframeAdd", "<script type=\"text/javascript\" language=\"javascript\">parent.location.href = 'Login.aspx';</script>"); return; } var str = Session["YearReport"].ToString(); if (string.IsNullOrEmpty(str)) { return; } var year = Convert.ToInt32(str); var propertyId = Convert.ToInt32(Session["PropertyIdReport"]); var property = HotelDataEntryLib.Page.PropertyHelper.GetProperty(propertyId); _propertyName = property.PropertyName; _year = year.ToString(); lbProperty.Text = _propertyName; lbYear.Text = _year; var curr = PropertyHelper.GetProperty(propertyId); var currency = CurrencyHelper.GetCurrency(curr.CurrencyId); _currency = currency.CurrencyCode; }
public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type) { if (schema.properties == null) { return; } foreach (var property in schema.properties) { var attribute = PropertyHelper.GetProperty(type, property.Key) ?.GetCustomAttribute <MutabilityAttribute>(); if (attribute == null) { continue; } var mutabilities = Enum.GetValues(typeof(MutabilityFlags)) .Cast <MutabilityFlags>() .Where(f => attribute.Mutability.HasFlag(f)) .ToArray(); property.Value.vendorExtensions.Add(MutabilityKey, mutabilities); } }
public UpdateOperation <TDataType> WhereEquals(Expression <Func <TDataType, object> > field, object value) { var column = PropertyHelper.GetProperty(field).Name; _builder.WhereEquals(column, value); return(this); }
/// <summary> /// Generates a buzzword-laden catch phrase /// </summary> /// <returns>The buzzword-laden catch phrase.</returns> /// <remarks>Wordlist originates from <see href="http://www.1728.com/buzzword.htm" /></remarks> public static string CatchPhrase() { return(string.Join( " ", ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Company.Buzzwords1)).Random(), ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Company.Buzzwords2)).Random(), ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Company.Buzzwords3)).Random())); }
/// <summary> /// When a straight answer won't do, Bullshit to the rescue! /// </summary> /// <returns>Some <c>bullshit</c>.</returns> /// <remarks>Wordlist originates from <see href="http://dack.com/web/bullshit.html" /></remarks> public static string Bullshit() { return(string.Join( " ", ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Company.BS1)).Random(), ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Company.BS2)).Random(), ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Company.BS3)).Random())); }
protected override void FillTargetFactories(Cirrious.MvvmCross.Binding.Bindings.Target.Construction.IMvxTargetBindingFactoryRegistry registry) { registry.RegisterCustomBindingFactory <UISlider>( "Value", target => new MvxUISliderValueTargetBinding(target, PropertyHelper <UISlider> .GetProperty(x => x.Value))); registry.RegisterCustomBindingFactory <UISwitch>( "On", target => new MvxUISwitchOnTargetBinding(target, PropertyHelper <UISwitch> .GetProperty(x => x.On))); base.FillTargetFactories(registry); }
public static TValue GetAttributeValue <TTrackerClass, TAttribute, TValue>(this Type type, Expression <Func <TTrackerClass, long> > propSelector, Func <TAttribute, TValue> valueOf) where TAttribute : Attribute where TTrackerClass : class { var propertyInfo = PropertyHelper <TTrackerClass> .GetProperty(propSelector); var attribute = propertyInfo.GetCustomAttributes(typeof(TAttribute), true).OfType <TAttribute>().FirstOrDefault(); return(attribute != null?valueOf(attribute) : default(TValue)); }
public object this[String name] { get { return(PropertyHelper.GetProperty(name, this)); } set { PropertyHelper.SetProeprty(name, this, value); } }
// GET api/caradvert /// <summary> /// Returns sorted list of all <see cref="CarAdvertViewModel"/> data. /// </summary> /// <param name="sortby">Optional param - defines the property, depending on which, /// <see cref="CarAdvertViewModel"/> should be sorted. In case of no param value </param> /// Id property is used. /// <returns>Sorted list of all <see cref="CarAdvertViewModel"/> data</returns> public IEnumerable <CarAdvertViewModel> GetAll(string sortby = null) { // This will be used if DB connection failed List <CarAdvertViewModel> advertLst = DummyAdvertList; if (string.IsNullOrEmpty(sortby)) { sortby = "id"; } return(advertLst.OrderBy(x => _propertyHelper.GetProperty(x, sortby)).ToList());; }
protected void CurrencyLabel_DataBound(object sender, EventArgs e) { var property = string.IsNullOrEmpty(ddlCompany.SelectedValue) ? 0 : Convert.ToInt32(ddlCompany.SelectedValue); if (property != 0) { var curr = PropertyHelper.GetProperty(property); var currency = CurrencyHelper.GetCurrency(curr.CurrencyId); lbCurerncy.Text = currency.CurrencyCode; _currency = currency.CurrencyCode; } }
public SelectOperation <TDataType> Select <TDataType>(params Expression <Func <TDataType, object> > [] fields) { var columns = ""; foreach (var field in fields) { var column = PropertyHelper.GetProperty(field).Name; columns += "[" + column + "], "; } columns = columns.Remove(columns.Length - 2, 2); return(new SelectOperation <TDataType>(columns, String.Empty, _database)); }
public void TestGetSet() { var person = new Person { Id = 1, Name = "张三" }; Assert.AreEqual(person.Id, PropertyHelper <Person> .GetProperty(person, "Id")); const int newId = 2; PropertyHelper <Person> .SetProperty(person, "Id", newId); Assert.AreEqual(newId, PropertyHelper <Person> .GetProperty(person, "Id")); }
public static void SetModel <TModel>(this KeyValuePair <string, string> keyValuePair, ref TModel model) where TModel : class, new() { if (model == null) { return; } PropertyInfo propertyInfo = PropertyHelper.GetProperty <TModel>(keyValuePair.Key); if (propertyInfo != null) { EntityHelper.SetModel <TModel>(ref model, propertyInfo, keyValuePair.Value); } }
public void MultpleOptionsChainedAreAllSet() { var columnDefinitions = new Dictionary <string, ColumnDefinition>(); var columnBuilder = new ColumnConfigurationBuilder <User>(columnDefinitions); columnBuilder .Column(x => x.UserId) .WithName("Id") .WithDbType(typeof(long)) .Result(); Assert.AreEqual("Id", columnDefinitions["UserId"].DbColumnName); Assert.AreEqual(typeof(long), columnDefinitions["UserId"].DbColumnType); Assert.AreEqual(true, columnDefinitions["UserId"].ResultColumn); Assert.AreEqual(PropertyHelper <User> .GetProperty(x => x.UserId), columnDefinitions["UserId"].MemberInfo); }
private void CurrencyBinding(string selectedValue) { var property = Convert.ToInt32(selectedValue); if (property != 0) { var curr = PropertyHelper.GetProperty(property); var currency = CurrencyHelper.GetCurrency(curr.CurrencyId); lbCurerncy.Text = currency.CurrencyCode; _currency = currency.CurrencyCode; } else { lbCurerncy.Text = ""; } }
protected void ddlCompany2_SelectedIndexChanged(object sender, EventArgs e) { MonthlyDate = hiddenMonthYear.Value; Session["monthlyDate"] = MonthlyDate; if (((DropDownList)sender).SelectedValue != "") { var propertyId = Convert.ToInt32(ddlCompany2.SelectedValue); if (propertyId == 0) { displayCurrency2.Attributes["style"] = "display:none"; return; } var curr = PropertyHelper.GetProperty(propertyId); //var currency = CurrencyHelper.GetCurrency(curr.CurrencyId); //lbCurrency2.Text = currency.CurrencyCode; displayCurrency2.Attributes["style"] = ""; } }
public void Different_Methods_Of_Same_Class_Give_Not_Equal_Arrays() { // Cache miss case { var firstNames = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); var lastNames = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.Last)); Assert.IsFalse(firstNames.SequenceEqual(lastNames)); } // Cache hit case { var firstNames = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); var lastNames = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.Last)); Assert.IsFalse(firstNames.SequenceEqual(lastNames)); } }
public void Resource_And_Cache_Give_Equal_Arrays() { // Cache miss case { var firstNames = Resources.Name.First.Split(Config.SEPARATOR); var cachedFirtsNames = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); Assert.IsTrue(firstNames.SequenceEqual(cachedFirtsNames)); } // Cache hit case { var firstNames = Resources.Name.First.Split(Config.SEPARATOR); var cachedFirtsNames = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); Assert.IsTrue(firstNames.SequenceEqual(cachedFirtsNames)); } }
public void Resource_And_Cache_Give_Equal_Arrays_With_Foreign_Culture() { System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE"); // Cache miss case { var firstNames = Resources.Name.First.Split(Config.SEPARATOR); var cachedFirtsNames = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); Assert.IsTrue(firstNames.SequenceEqual(cachedFirtsNames)); } // Cache hit case { var firstNames = Resources.Name.First.Split(Config.SEPARATOR); var cachedFirtsNames = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); Assert.IsTrue(firstNames.SequenceEqual(cachedFirtsNames)); } }
protected void ddlCompany_SelectedIndexChanged(object sender, EventArgs e) { DateFrom = hiddenDateFrom.Value; DateTo = hiddenDateTo.Value; Session["dateFrom"] = DateFrom; Session["dateTo"] = DateTo; if (((DropDownList)sender).SelectedValue != "") { var propertyId = Convert.ToInt32(ddlCompany.SelectedValue); if (propertyId == 0) { displayCurrency.Attributes["style"] = "display:none"; return; } var curr = PropertyHelper.GetProperty(propertyId); //var currency = CurrencyHelper.GetCurrency(curr.CurrencyId); //lbCurerncy.Text = currency.CurrencyCode; displayCurrency.Attributes["style"] = ""; } }
public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type) { if (schema.properties == null) { return; } foreach (var property in schema.properties) { var attribute = PropertyHelper.GetProperty(type, property.Key) ?.GetCustomAttribute <ReadOnlyAttribute>(); if (attribute == null || !attribute.IsReadOnly) { continue; } property.Value.vendorExtensions.Add(ReadOnlyKey, true); } }
public void Switch_Between_Foreign_Cultures_Returns_Not_Equal_Arrays() { // Cache miss case { System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("pt-BR"); var en_US_array = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE"); var de_DE_array = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); Assert.IsFalse(en_US_array.SequenceEqual(de_DE_array)); } // Cache hit case { System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("pt-BR"); var en_US_array = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE"); var de_DE_array = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); Assert.IsFalse(en_US_array.SequenceEqual(de_DE_array)); } }
public Setting([DisallowNull] TTarget target, Expression <Func <TTarget, TProperty> > selector) { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (selector == null) { throw new ArgumentNullException(nameof(selector)); } if (PropertyHelper <TTarget> .GetProperty(selector) is not { } pr) { throw new InvalidOperationException($"The expression {selector} is not a valid property selector"); } Value = (TProperty?)pr.GetValue(target); SetValueCommand = ReactiveCommand.Create(() => pr.SetValue(target, Value)); ShowNotificationCommand = ReactiveCommand.Create(() => NotificationHelpers.Show(new RestartViewModel("To apply the new setting, Wasabi Wallet needs to be restarted"))); this.WhenAnyValue(x => x.Value) .ObserveOn(RxApp.MainThreadScheduler) .Skip(1) .Select(_ => Unit.Default) .InvokeCommand(SetValueCommand); this.WhenAnyValue(x => x.Value) .Skip(1) .Throttle(TimeSpan.FromMilliseconds(SettingsTabViewModelBase.ThrottleTime + 50)) .ObserveOn(RxApp.MainThreadScheduler) .Where(_ => SettingsTabViewModelBase.CheckIfRestartIsNeeded()) .Select(_ => Unit.Default) .InvokeCommand(ShowNotificationCommand); }
public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type) { if (schema.properties == null) { return; } foreach (var key in schema.properties.Keys.ToList()) { if (schema.properties[key].@enum == null) { continue; } var enumType = PropertyHelper.GetProperty(type, key).PropertyType; if (!this.enumSchemas.ContainsKey(enumType.FullName)) { var enumSchema = schemaRegistry.GetOrRegister(enumType); var enumDescription = new EnumDescription { Name = enumType.Name, ModelAsString = typeof(StringEnumConverter).IsAssignableFrom(enumType.GetCustomAttribute <JsonConverterAttribute>()?.ConverterType) }; enumSchema.vendorExtensions.Add(EnumKey, enumDescription); this.enumSchemas.Add(enumType.FullName, enumSchema); } schema.properties[key] = new Schema { @ref = $"#/definitions/{enumType.Name}", description = schema.properties[key].description }; } }
public void Switch_To_Unsupported_Culture_Returns_Equal_Arrays() { const string UNSUPPORTED_CULTURE_NAME = "ru-RU"; // Cache miss case { System.Threading.Thread.CurrentThread.CurrentUICulture = defaultUICulture; var array = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(UNSUPPORTED_CULTURE_NAME); var fallback_array = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); Assert.IsTrue(array.SequenceEqual(fallback_array)); } // Cache hit case { System.Threading.Thread.CurrentThread.CurrentUICulture = defaultUICulture; var array = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); System.Threading.Thread.CurrentThread.CurrentUICulture = new CultureInfo(UNSUPPORTED_CULTURE_NAME); var fallback_array = ResourceCollectionCacher.GetArray(PropertyHelper.GetProperty(() => Resources.Name.First)); Assert.IsTrue(array.SequenceEqual(fallback_array)); } }