public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(DependencyProperty.UnsetValue);
            }

            var type         = value.GetType();
            var stringFormat = parameter as string;

            if (IsNumeric(type))
            {
                if (stringFormat == null)
                {
                    return(value.ToString());
                }
                var formattible = (IFormattable)value;
                // Gets a NumberFormatInfo associated with the en-US culture.
                NumberFormatInfo nfi;
                if (GroupSeperator == null)
                {
                    nfi = culture.NumberFormat;
                }
                else
                {
                    nfi = ((CultureInfo)culture.Clone()).NumberFormat;
                    nfi.NumberGroupSeparator = GroupSeperator;
                }
                return(formattible.ToString(stringFormat, nfi));
            }
            return(DependencyProperty.UnsetValue);
        }
Example #2
0
        /// <summary>
        ///     Преобразование региональных настроек к корпоративному формату
        /// </summary>
        /// <param name="ci">региональные настройки, подлежащие преобразованию</param>
        /// <returns>преобразованные региональные настройки</returns>
        public static CultureInfo ToCorporateCulture(CultureInfo ci)
        {
            var corporate = (CultureInfo)ci.Clone();

            corporate.NumberFormat.NumberNegativePattern =
                GetNumberNegativePattern(ConfigurationManager.AppSettings["Culture.Number.NegativePattern"]);
            corporate.NumberFormat.NumberDecimalSeparator =
                ConfigurationManager.AppSettings["Culture.Number.DecimalSeparator"];
            corporate.NumberFormat.NumberGroupSeparator =
                ConfigurationManager.AppSettings["Culture.Number.GroupSeparator"];
            //corporate.NumberFormat.NumberGroupSizes = ConfigurationManager.AppSettings["Culture.Number.GroupSizes"]);
            corporate.NumberFormat.NumberDecimalDigits =
                int.Parse(ConfigurationManager.AppSettings["Culture.Number.Decimals"]);

            corporate.NumberFormat.PercentNegativePattern =
                GetPercentNegativePattern(ConfigurationManager.AppSettings["Culture.Percent.NegativePattern"]);
            corporate.NumberFormat.PercentPositivePattern =
                GetPercentPositivePattern(ConfigurationManager.AppSettings["Culture.Percent.PositivePattern"]);
            corporate.NumberFormat.PercentDecimalSeparator =
                ConfigurationManager.AppSettings["Culture.Percent.DecimalSeparator"];
            corporate.NumberFormat.PercentGroupSeparator =
                ConfigurationManager.AppSettings["Culture.Percent.GroupSeparator"];
            //corporate.NumberFormat.PercentGroupSizes = ConfigurationManager.AppSettings["Culture.Percent.GroupSizes.ToArray<int>(new char[] { ',' }, s => Int32.Parse(s))"];
            corporate.NumberFormat.PercentDecimalDigits =
                int.Parse(ConfigurationManager.AppSettings["Culture.Percent.Decimals"]);
            corporate.NumberFormat.PercentSymbol = ConfigurationManager.AppSettings["Culture.Percent.Symbol"];

            corporate.NumberFormat.CurrencyNegativePattern =
                GetCurrencyNegativePattern(ConfigurationManager.AppSettings["Culture.Currency.NegativePattern"]);
            corporate.NumberFormat.CurrencyPositivePattern =
                GetCurrencyPositivePattern(ConfigurationManager.AppSettings["Culture.Currency.PositivePattern"]);
            corporate.NumberFormat.CurrencyDecimalSeparator =
                ConfigurationManager.AppSettings["Culture.Currency.DecimalSeparator"];
            corporate.NumberFormat.CurrencyGroupSeparator =
                ConfigurationManager.AppSettings["Culture.Currency.GroupSeparator"];
            //corporate.NumberFormat.CurrencyGroupSizes = ConfigurationManager.AppSettings["Culture.Currency.GroupSizes.ToArray<int>(new char[] { ',' }, s => Int32.Parse(s))"];
            corporate.NumberFormat.CurrencyDecimalDigits =
                int.Parse(ConfigurationManager.AppSettings["Culture.Currency.Decimals"]);
            corporate.NumberFormat.CurrencySymbol = ConfigurationManager.AppSettings["Culture.Currency.Symbol"];

            corporate.DateTimeFormat.DateSeparator =
                ConfigurationManager.AppSettings["Culture.DateTime.DatePartsSeparator"];
            corporate.DateTimeFormat.TimeSeparator =
                ConfigurationManager.AppSettings["Culture.DateTime.TimePartsSeparator"];
            corporate.DateTimeFormat.AMDesignator = ConfigurationManager.AppSettings["Culture.DateTime.AM"];
            corporate.DateTimeFormat.PMDesignator = ConfigurationManager.AppSettings["Culture.DateTime.PM"];

            corporate.DateTimeFormat.ShortDatePattern =
                ConfigurationManager.AppSettings["Culture.DateTime.ShortDatePattern"];
            corporate.DateTimeFormat.LongDatePattern =
                ConfigurationManager.AppSettings["Culture.DateTime.LongDatePattern"];
            corporate.DateTimeFormat.ShortTimePattern =
                ConfigurationManager.AppSettings["Culture.DateTime.ShortTimePattern"];
            corporate.DateTimeFormat.LongTimePattern =
                ConfigurationManager.AppSettings["Culture.DateTime.LongTimePattern"];
            corporate.DateTimeFormat.FullDateTimePattern =
                ConfigurationManager.AppSettings["Culture.DateTime.FullDateTimePattern"];

            return(corporate);
        }
Example #3
0
        public override DependencyItem Clone()
        {
            DependencyItem item = new DependencyItem(this);

            if (_name != null)
            {
                item._name = String.Copy(_name);
            }
            if (_path != null)
            {
                item._path = _path.Clone();
            }
            if (_strongName != null)
            {
                item._strongName = String.Copy(_strongName);
            }
            if (_redirectPublicKeyToken != null)
            {
                item._redirectPublicKeyToken = String.Copy(_redirectPublicKeyToken);
            }
            if (_redirectVersion != null)
            {
                item._redirectVersion = (Version)_redirectVersion.Clone();
            }
            if (_redirectCulture != null)
            {
                item._redirectCulture = (CultureInfo)_redirectCulture.Clone();
            }

            return(item);
        }
Example #4
0
        /// <summary>
        /// Returns a CultureInfo object based on the one provided and with the formatting information taken from this
        /// Currency object.
        /// </summary>
        /// <param name="baseCulture">The culture to start from.</param>
        /// <returns>The culture with the correct formatting for this currency.</returns>
        public CultureInfo GetCulture(CultureInfo baseCulture)
        {
            CultureInfo clone = (CultureInfo)baseCulture.Clone();

            clone.NumberFormat.CurrencyDecimalDigits = DecimalDigits;
            clone.NumberFormat.CurrencySymbol        = Symbol;
            return(clone);
        }
Example #5
0
        public static IEnumerable<object[]> Equals_TestData()
        {
            CultureInfo frFRCulture = new CultureInfo("fr-FR");
            yield return new object[] { frFRCulture, frFRCulture.Clone(), true };
            yield return new object[] { frFRCulture, frFRCulture, true };
            yield return new object[] { new CultureInfo("en"), new CultureInfo("en"), true };
            yield return new object[] { new CultureInfo("en-US"), new CultureInfo("en-US"), true };
            yield return new object[] { CultureInfo.InvariantCulture, CultureInfo.InvariantCulture, true };
            yield return new object[] { CultureInfo.InvariantCulture, new CultureInfo(""), true };

            yield return new object[] { new CultureInfo("en"), new CultureInfo("en-US"), false };
            yield return new object[] { new CultureInfo("en-US"), new CultureInfo("fr-FR"), false };
            yield return new object[] { new CultureInfo("en-US"), null, false };
        }
    public bool PosTest2()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest2: Call Clone method on a instance created from several cultures");

        try
        {
            DateTimeFormatInfo expected = new CultureInfo("en-us").DateTimeFormat;
            retVal = VerificationHelper(expected, expected.Clone(), "002.1") && retVal;
            
            expected = new CultureInfo("fr-FR").DateTimeFormat;
            retVal = VerificationHelper(expected, expected.Clone(), "002.2") && retVal;
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.0", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1: Other CultureInfo comes from Clone method is the same CultureInfo as the original");
        try
        {

            CultureInfo myCultureInfo = new CultureInfo("fr-FR");
            CultureInfo myClone = myCultureInfo.Clone() as CultureInfo;
            if (!myClone.Equals(myCultureInfo))
            {
                TestLibrary.TestFramework.LogError("001", "Other CultureInfo comes from Clone method should be the same CultureInfo as the original.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
Example #8
0
    // Returns true if the expected result is right
    // Returns false if the expected result is wrong
    public bool PosTest1()
    {
        bool retVal = true;

        TestLibrary.TestFramework.BeginScenario("PosTest1:CultureTypes.SpecificCultures");
        try
        {

            CultureInfo myCultureInfo = new CultureInfo("fr-FR");
            CultureInfo myClone = myCultureInfo.Clone() as CultureInfo;
            if (!myClone.Equals(myCultureInfo))
            {
                TestLibrary.TestFramework.LogError("001", "Should return true.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
            retVal = false;
        }
        return retVal;
    }
	public void MakeRows() {
		float totalscreenwidth = RectTransformExtensions.GetWidth(breakdowntable.GetComponent<RectTransform>());
		float preferredwidth1 = totalscreenwidth * 0.20F;
		float preferredwidth2 = totalscreenwidth * 0.20F;
		float preferredwidth3 = totalscreenwidth * 0.20F;
		float preferredwidth4 = totalscreenwidth * 0.20F;
        float preferredwidth5 = totalscreenwidth * 0.20F;

		var children = new List<GameObject>();
		foreach (Transform child in breakdowntable.transform) children.Add(child.gameObject);
		children.ForEach(child => Destroy(child));

		GameObject firstrow = Instantiate (rowski);
		firstrow.transform.parent = breakdowntable.transform;
		GameObject firstcol = Instantiate (colski);
		firstcol.GetComponent<Text> ().text = "Name";
		firstcol.transform.parent = firstrow.transform;
        GameObject firstseccol = Instantiate(colski);
        firstseccol.GetComponent<Text>().text = "Campaign Region";
        firstseccol.transform.parent = firstrow.transform;
        GameObject secondcol = Instantiate (colski);
		secondcol.GetComponent<Text> ().text = "Campaign Type";
		secondcol.transform.parent = firstrow.transform;
		
        GameObject thirdcol = Instantiate (colski);
		thirdcol.GetComponent<Text> ().text = "Votes Earned";
		thirdcol.transform.parent = firstrow.transform;
		GameObject fourthcol = Instantiate (colski);
		fourthcol.GetComponent<Text> ().text = "Money Spent";
		fourthcol.transform.parent = firstrow.transform;

		firstcol.GetComponent<LayoutElement>().preferredWidth = preferredwidth1;
        firstseccol.GetComponent<LayoutElement>().preferredWidth = preferredwidth5;
        secondcol.GetComponent<LayoutElement>().preferredWidth = preferredwidth2;
		thirdcol.GetComponent<LayoutElement>().preferredWidth = preferredwidth3;
		fourthcol.GetComponent<LayoutElement>().preferredWidth = preferredwidth4;



		foreach(KeyValuePair<string, Region> entry in popup.GetComponent<PopupScript>().regions)
		{
			List<Campaign> curcamps = new List<Campaign> ();
			curcamps = popup.GetComponent<PopupScript> ().activecampaigns [entry.Key];
			foreach (Campaign camp in curcamps) {
				if (camp != null) {
					firstrow = Instantiate (rowski);
					firstrow.transform.parent = breakdowntable.transform;
					firstcol = Instantiate (colski);
					firstcol.GetComponent<Text> ().text = camp.name;
					firstcol.transform.parent = firstrow.transform;
                    firstseccol = Instantiate(colski);
                    firstseccol.GetComponent<Text>().text = camp.region;
                    firstseccol.transform.parent = firstrow.transform;
					secondcol = Instantiate (colski);
					secondcol.GetComponent<Text> ().text = camp.type;
					secondcol.transform.parent = firstrow.transform;
					thirdcol = Instantiate (colski);
					Debug.Log ("votesMINUS1" + camp.costovertimecamp [camp.votesovertimecamp.Count - 1]);
					Debug.Log ("votesMINUS2" + camp.costovertimecamp [camp.votesovertimecamp.Count - 2]);
					thirdcol.GetComponent<Text> ().text = String.Format("{0:n0}", camp.votesovertimecamp[camp.votesovertimecamp.Count-1] - camp.votesovertimecamp[camp.votesovertimecamp.Count-2]);
					thirdcol.transform.parent = firstrow.transform;
					fourthcol = Instantiate (colski);

					var original = new CultureInfo("en-us");
					var modified = (CultureInfo) original.Clone();
					modified.NumberFormat.CurrencyNegativePattern = 1; 
					float costdiff = camp.costovertimecamp [camp.costovertimecamp.Count - 1] - camp.costovertimecamp [camp.costovertimecamp.Count - 2];
//					string moneystring = costdiff.ToString(modified, "{0:}", );
//	 				if (costdiff < 0)
//						moneystring = moneystring.Substring(1);
					String cst = String.Format(modified, "{0:C2}", costdiff);
					if (cst [0] == '-') {
						cst = cst.Substring (1);
					}
					fourthcol.GetComponent<Text> ().text = cst;
					fourthcol.transform.parent = firstrow.transform;


					firstcol.GetComponent<LayoutElement>().preferredWidth = preferredwidth1;
                    firstseccol.GetComponent<LayoutElement>().preferredWidth = preferredwidth5;
					secondcol.GetComponent<LayoutElement>().preferredWidth = preferredwidth2;
					thirdcol.GetComponent<LayoutElement>().preferredWidth = preferredwidth3;
					fourthcol.GetComponent<LayoutElement>().preferredWidth = preferredwidth4;
					// do something with entry.Value or entry.Key
				}


			}
		}


	}
Example #10
0
 public void Clone(CultureInfo culture)
 {
     CultureInfo clone = (CultureInfo)culture.Clone();
     Assert.Equal(culture, clone);
     Assert.NotSame(clone, culture);
 }