Equals() публичный Метод

public Equals ( object value ) : bool
value object
Результат bool
Пример #1
0
        public void TestDiffCultureTextInfo()
        {
            TextInfo textInfoFrance = new CultureInfo("fr-FR").TextInfo;
            TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;

            Assert.False(textInfoFrance.Equals((object)textInfoUS));
        }
Пример #2
0
 public void TestIntObject()
 {
     TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;
     int i = TestLibrary.Generator.GetInt32(-55);
     object intObject = i as object;
     Assert.False(textInfoUS.Equals(intObject));
 }
Пример #3
0
        public void TestStringObject()
        {
            TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;
            String str = TestLibrary.Generator.GetString(-55, false, _MINI_STRING_LENGTH, _MAX_STRING_LENGTH);
            object strObject = str as object;

            Assert.False(textInfoUS.Equals(strObject));
        }
 private static bool CulturesEqual(CultureInfo refCI, CultureInfo defCI)
 {
     bool flag = defCI.Equals(CultureInfo.InvariantCulture);
     if ((refCI == null) || refCI.Equals(CultureInfo.InvariantCulture))
     {
         return flag;
     }
     return (!flag && defCI.Equals(refCI));
 }
        public string FindMissingProperty(PropertyToken property, CultureInfo culture)
        {
            var defaultValue = culture.Equals(_defaultCulture)
                ? property.Header ?? property.DefaultHeaderText(culture) ?? BreakUpCamelCase(property.PropertyName)
                : property.DefaultHeaderText(culture) ?? culture.Name + "_" + property.PropertyName;

            writeMissing(property.StringTokenKey, defaultValue, culture);

            return defaultValue;
        }
 private static bool Compatible(XmlLanguage lang, CultureInfo culture)
 {
     if (lang == null || lang == XmlLanguage.Empty) return true;
     var ll = lang.IetfLanguageTag.ToLowerInvariant();
     while (!culture.Equals(CultureInfo.InvariantCulture))
     {
         if (ll == culture.IetfLanguageTag.ToLowerInvariant()) return true;
         culture = culture.Parent;
     }
     return false;
 }
 public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
 {
     if (destinationType == typeof(string))
     {
         if (culture.Equals(CultureInfo.CurrentCulture))
         {
             return(ToCurrentCulture[(T)value]);
         }
         else if (culture.Equals(CultureInfo.InvariantCulture))
         {
             return(value.ToString());
         }
         var name = value.ToString();
         return(ResourceLoader.LoadString(typeof(T).Name + "_" + name, name, culture));
     }
     else
     {
         return(base.ConvertTo(context, culture, value, destinationType));
     }
 }
        public string FindMissingText(StringToken key, CultureInfo culture)
        {
            var defaultValue = culture.Name + "_" + key.Key;
            if (key.DefaultValue.IsNotEmpty() && culture.Equals(_defaultCulture))
            {
                defaultValue = key.DefaultValue;
            }

            _storage.WriteMissing(key.Key, defaultValue, culture);

            return defaultValue;
        }
        public string FindMissingText(StringToken key, CultureInfo culture)
        {
            var defaultValue = culture.Name + "_" + key.ToLocalizationKey();
            if (key.DefaultValue.IsNotEmpty() && culture.Equals(_defaultCulture))
            {
                defaultValue = key.DefaultValue;
            }

            writeMissing(key.ToLocalizationKey().ToString(), defaultValue, culture);

            return defaultValue;
        }
Пример #10
0
 public CultureInfoScope(CultureInfo cultureInfo)
 {
     if (cultureInfo != null && !cultureInfo.Equals(Thread.CurrentThread.CurrentCulture))
     {
         if (cultureInfo.IsNeutralCulture)
         {
             cultureInfo = LanguageHelper.GetSpecificCultureInfo(cultureInfo);
         }
         originalCultureInfo = Thread.CurrentThread.CurrentCulture;
         Thread.CurrentThread.CurrentCulture = cultureInfo;
     }
 }
		public Localizer GetLocalizer (CultureInfo culture)
		{
			Localizer loc = LookupLocalizer(culture);
			if (loc == null)
				lock (_localizers.SyncRoot)
				{
					loc = LookupLocalizer(culture);
					if (loc == null)
					{
						if (culture.Equals(_defaultculture))
							loc = CreateDefaultLocalizer();
						else if (culture.IsNeutralCulture || culture.Equals(CultureInfo.InvariantCulture))
							loc = CreateLocalizer(culture, _defaultculture);
						else
							loc = CreateLocalizer(culture, culture.Parent);

						CacheLocalizer(culture, loc);
					}
				}
			return loc;
		}
Пример #12
0
        private string GetCultureInfoName(CultureInfo ci)
        {
            CultureInfo en_US = new CultureInfo("en-US");

            // For "English (United States)" we'd rather just display "English"
            if (ci.Equals(en_US))
            {
                return GetCultureInfoName(ci.Parent);
            }
            else
            {
                return ci.NativeName;
            }
        }
Пример #13
0
        private CultureInfo GetClosestMatchingLanguage(CultureInfo culture)
        {
            if(culture == null || culture.Equals(CultureInfo.InvariantCulture)) {
                return null;
            }

            var cultures = _cultureProvider.GetSupportedCultures.ToList();

            var specificCulture = cultures.FirstOrDefault(c => c.IsSameCultureAs(culture));
            var neutralCulture = cultures.FirstOrDefault(c => c.IsSameLanguageAs(culture));
            var fallBackCulture = culture.IsSameLanguageAs(FallbackCulture) ? FallbackCulture : null;

            return specificCulture ?? neutralCulture ?? fallBackCulture;
        }
Пример #14
0
 public void ChangeCulture(System.Globalization.CultureInfo cultureInfo)
 {
     if (null == cultureInfo)
     {
         return;
     }
     if (cultureInfo.Equals(Labels.Culture))
     {
         return;
     }
     Labels.Culture = cultureInfo;
     Thread.CurrentThread.CurrentUICulture = cultureInfo;
     Thread.CurrentThread.CurrentCulture   = cultureInfo;
     RaisePropertyChanged("Labels");
 }
 /// <summary>
 /// Returns a localizer instance based on the culture.
 /// </summary>
 internal BaseLocalizer GetLocalizerByCulture(CultureInfo ci)
 {
     if (customLocalizer != null)
         return customLocalizer;
     
     if (ci.Equals(FarsiCulture))
     {
         return fa;
     }
     
     if (ci.Equals(ArabicCulture))
     {
         return ar;
     }
     
     return en;
 }
Пример #16
0
 /// <summary>
 /// 返回与特定区域性相关的文件名。
 /// </summary>
 /// <param name="path">文件的路径。</param>
 /// <param name="fileName">文件的名称。</param>
 /// <param name="culture">要获取的文件的区域性信息。</param>
 /// <returns>与特定区域性相关的文件名,如果不存在则为 <c>null</c>。</returns>
 /// <remarks>与特定区域性相关的文件名,其形式为 path/culture.Name/fileName。</remarks>
 /// <exception cref="ArgumentNullException"><paramref name="path"/>、<paramref name="fileName"/> 或 
 /// <paramref name="culture"/> 为 <c>null</c>。</exception>
 /// <exception cref="ArgumentException"><paramref name="path"/> 或 <paramref name="fileName"/> 
 /// 中包含一个或多个无效字符。</exception>
 public static string GetCultureSpecifiedFile(string path, string fileName, CultureInfo culture)
 {
     CommonExceptions.CheckArgumentNull(path, "path");
     CommonExceptions.CheckArgumentNull(fileName, "fileName");
     CommonExceptions.CheckArgumentNull(culture, "culture");
     Contract.EndContractBlock();
     while (true)
     {
         string filePath = Path.Combine(path, culture.Name, fileName);
         if (File.Exists(filePath))
         {
             return filePath;
         }
         if (culture.Equals(CultureInfo.InvariantCulture))
         {
             break;
         }
         culture = culture.Parent;
     }
     return null;
 }
        public static bool TryGetSatteliteAssembly(this Assembly assembly, CultureInfo culture,
            out Assembly satteliteAssembly)
        {
            Contract.Requires(assembly != null);
            Contract.Requires(culture != null);

            if (culture.Equals(CultureInfo.InvariantCulture))
            {
                satteliteAssembly = assembly;
                return true;
            }
            try
            {
                satteliteAssembly = assembly.GetSatelliteAssembly(culture);
            }
            catch
            {
                satteliteAssembly = null;
                return false;
            }
            return true;
        }
Пример #18
0
        protected override System.Resources.ResourceSet InternalGetResourceSet(System.Globalization.CultureInfo culture, bool createIfNotExists, bool tryParents)
        {
            if (Path == null && FileFormat == null)
            {
                return(null);
            }
            if (culture == null || culture.Equals(CultureInfo.InvariantCulture))
            {
                return(null);
            }

            System.Resources.ResourceSet rs = null;
            Hashtable resourceSets          = this.ResourceSets;

            if (!TryFetchResourceSet(resourceSets, culture, out rs))
            {
                Stream resourceFullPath = this.GetAssemblyResource(culture);

                if (resourceFullPath == null)
                {
                    if (tryParents)
                    {
                        CultureInfo parent = culture.Parent;
                        rs = this.InternalGetResourceSet(parent, createIfNotExists, tryParents);
                        AddResourceSet(resourceSets, culture, ref rs);
                        return(rs);
                    }
                }
                else
                {
                    rs = this.CreateResourceSet(resourceFullPath);
                    AddResourceSet(resourceSets, culture, ref rs);
                    return(rs);
                }
            }

            return(rs);
        }
Пример #19
0
        protected new virtual System.Resources.ResourceSet InternalGetResourceSet(System.Globalization.CultureInfo culture, bool createIfNotExists, bool tryParents)
        {
            if (path == null && fileformat == null)
            {
                return(null);
            }
            if (culture == null || culture.Equals(CultureInfo.InvariantCulture))
            {
                return(null);
            }

            System.Resources.ResourceSet rs = null;
            Hashtable resourceSets          = this.ResourceSets;

            if (!TryFetchResourceSet(resourceSets, culture, out rs))
            {
                string resourceFileName = this.FindResourceFile(culture);
                if (resourceFileName == null)
                {
                    if (tryParents)
                    {
                        CultureInfo parent = culture.Parent;
                        rs = this.InternalGetResourceSet(parent, createIfNotExists, tryParents);
                        AddResourceSet(resourceSets, culture, ref rs);
                        return(rs);
                    }
                }
                else
                {
                    rs = this.CreateResourceSet(resourceFileName);
                    AddResourceSet(resourceSets, culture, ref rs);
                    return(rs);
                }
            }

            return(rs);
        }
		private string GetFileName(CultureInfo culture) {
			
            StringBuilder sb = new StringBuilder();
            sb.Append(base.BaseNameField);

            if (!culture.Equals(CultureInfo.InvariantCulture)) {
                sb.Append('.');
                sb.Append(culture.Name);
            }

            sb.Append(".resx");
            string fileName = sb.ToString();

			if (this._path != null) {
				string fullFileName = Path.Combine(this._path, fileName);
				if (File.Exists(fullFileName)) {
					return fullFileName;
				}
			} else if (File.Exists(fileName)) {
				return fileName;
			}

			return null;
		}
Пример #21
0
        private static void HandleSwitchElement(XElement element)
        {
            XElement defaultElement = element.Element(((XNamespace)LocalizationXmlConstants.XmlNamespace) + "default");
            Verify.IsNotNull(defaultElement, "Missing element named 'default' at {0}", element);


            XElement newValueParent = defaultElement;

            CultureInfo currentCultureInfo = LocalizationScopeManager.CurrentLocalizationScope;
            foreach (XElement whenElement in element.Elements(((XNamespace)LocalizationXmlConstants.XmlNamespace) + "when"))
            {
                XAttribute cultureAttribute = whenElement.Attribute("culture");
                Verify.IsNotNull(cultureAttribute, "Missing attriubte named 'culture' at {0}", whenElement);

                CultureInfo cultureInfo = new CultureInfo(cultureAttribute.Value);
                if (cultureInfo.Equals(currentCultureInfo))
                {
                    newValueParent = whenElement;
                    break;
                }
            }

            element.ReplaceWith(newValueParent.Nodes());
        }
Пример #22
0
        public override ResourceSet GetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
        {
            var baseCulture = culture;

            DBResourceSet databaseResourceSet;

            while (true)
            {
                if (ResourceSetsTable.Contains(culture.Name) && ResourceSetsTable[culture.Name] != null)
                {
                    databaseResourceSet = (DBResourceSet)ResourceSetsTable[culture.Name];
                }
                else
                {
                    databaseResourceSet = new DBResourceSet(_fileName, culture);
                    ResourceSetsTable.Add(culture.Name, databaseResourceSet);
                }

                if (databaseResourceSet.TableCount != 0)
                    break;

                if (culture.Equals(CultureInfo.InvariantCulture))
                    return _resManager.GetResourceSet(baseCulture, createIfNotExists, tryParents);

                culture = culture.Parent;
            }

            if (0 < updateSeconds && DateTime.UtcNow > _updateDate.AddSeconds(2))
            {
                GetResource.UpdateDBRS(databaseResourceSet, _fileName, culture.Name, _updateDate);
                _updateDate = DateTime.UtcNow;
            }

            return databaseResourceSet;

        }
Пример #23
0
 public void TestSameCultureInfo()
 {
     CultureInfo myCultureInfo = new CultureInfo("en-US");
     Assert.True(myCultureInfo.Equals(myCultureInfo));
 }
Пример #24
0
        public void TestNullReference()
        {
            TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;

            Assert.False(textInfoUS.Equals(null));
        }
Пример #25
0
 private static void ValidateCulture(CultureInfo culture)
 {
     if (culture == null)
         throw new ArgumentNullException("culture");
     if (culture.IsNeutralCulture || culture.Equals(CultureInfo.InvariantCulture))
         throw new ArgumentException("Specific Culture Required", "culture");
 }
Пример #26
0
		[Test] // bug #77347
		public void CloneNeutral ()
		{
			CultureInfo culture = new CultureInfo ("en");
			CultureInfo cultureClone = culture.Clone () as CultureInfo;
			Assert.IsTrue (culture.Equals (cultureClone));
		}
Пример #27
0
		public void ChineseSimplifiedDontEqual ()
		{
			CultureInfo zh1 = new CultureInfo ("zh-Hans");
			CultureInfo zh2 = new CultureInfo ("zh-CHS");

			Assert.IsFalse (zh1.Equals (zh2), "#1");
			Assert.IsFalse (zh2.Equals (zh1), "#2");
		}
Пример #28
0
 public void TestUnequal()
 {
     CultureInfo myCultureInfo = new CultureInfo("en-US");
     CultureInfo myCultureInfo1 = new CultureInfo("fr-FR");
     Assert.False(myCultureInfo1.Equals(myCultureInfo));
 }
Пример #29
0
 public void TestEqualCultureIdentifier()
 {
     CultureInfo myCultureInfo = new CultureInfo("en-US");
     CultureInfo myCultureInfo1 = new CultureInfo("en-US");
     Assert.True(myCultureInfo1.Equals(myCultureInfo));
 }
Пример #30
0
 public void TestNull()
 {
     CultureInfo myCultureInfo = new CultureInfo("en-US");
     Assert.False(myCultureInfo.Equals(null));
 }
Пример #31
0
 public void TestEqualNameAndCultureIdentifier()
 {
     CultureInfo myCultureInfo = new CultureInfo("en");
     CultureInfo myCultureInfo1 = new CultureInfo("en-US");
     Assert.False(myCultureInfo1.Equals(myCultureInfo));
 }
Пример #32
0
 public void TestEqualCultureName()
 {
     CultureInfo myCultureInfo = new CultureInfo("en");
     CultureInfo myCultureInfo1 = new CultureInfo("en");
     Assert.True(myCultureInfo1.Equals(myCultureInfo));
 }
Пример #33
0
        private static bool DialectEquals(CultureInfo defaultLanguage, GherkinDialect dialect)
        {
            if (!defaultLanguage.IsNeutralCulture)
                defaultLanguage = defaultLanguage.Parent;

            var dialectCulture = dialect.CultureInfo;
            if (!dialectCulture.IsNeutralCulture)
                dialectCulture = dialectCulture.Parent;

            return defaultLanguage.Equals(dialectCulture);
        }
Пример #34
0
 public void TestDiffTypeObject()
 {
     TextInfo textInfoUS = new CultureInfo("en-US").TextInfo;
     object obj = (object)(new MyClass());
     Assert.False(textInfoUS.Equals(obj));
 }