public void Ctor_Localizable(bool localizable)
        {
            var attribute = new LocalizableAttribute(localizable);

            Assert.Equal(localizable, attribute.IsLocalizable);
            Assert.Equal(!localizable, attribute.IsDefaultAttribute());
        }
예제 #2
0
        protected virtual bool ShouldShowDialogButton()
        {
            //if the object's Localizable, show a dialog, since the text's likely to be more substantial
            LocalizableAttribute at = (LocalizableAttribute)session.Property.Attributes [typeof(LocalizableAttribute)];

            return(at != null && at.IsLocalizable);
        }
 public void Equals_Object_ReturnsExpected(LocalizableAttribute attribute, object other, bool expected)
 {
     Assert.Equal(expected, attribute.Equals(other));
     if (other is LocalizableAttribute)
     {
         Assert.Equal(expected, attribute.GetHashCode().Equals(other.GetHashCode()));
     }
 }
예제 #4
0
파일: UICommon.cs 프로젝트: ee8cajd/WeK
        /// <summary>
        ///
        /// </summary>
        /// <param name="targetCombo"></param>
        /// <param name="source"></param>
        /// <param name="resources"></param>
        public static void PopulateComboFromEnum(ComboBox targetCombo, Type source, ResourceManager resources)
        {
            FieldInfo[] EnumFields = source.GetFields(BindingFlags.Public | BindingFlags.Static);

            if (EnumFields.Length > 0)
            {
                ComboItemHelper[] ComboItemList = new ComboItemHelper[EnumFields.Length];

                for (int i = 0; i < EnumFields.Length; i++)
                {
                    DescriptionAttribute EnumDisplayName        = null;
                    LocalizableAttribute DisplayNameLocalizable = null;

                    foreach (object CustomAttribute in EnumFields[i].GetCustomAttributes(false))
                    {
                        if (CustomAttribute is DescriptionAttribute)
                        {
                            EnumDisplayName = CustomAttribute as DescriptionAttribute;
                        }
                        else if (CustomAttribute is LocalizableAttribute)
                        {
                            DisplayNameLocalizable = CustomAttribute as LocalizableAttribute;
                        }
                    }

                    if (EnumDisplayName == null || String.IsNullOrEmpty(EnumDisplayName.Description))
                    {
                        // No alternative Display Name has been specified, so use the plain enum name.
                        ComboItemList[i].DisplayName = EnumFields[i].Name;
                    }
                    else
                    {
                        // There is an explicit Display Name specified. Localize it if required.
                        if (DisplayNameLocalizable != null && DisplayNameLocalizable.IsLocalizable && resources != null)
                        {
                            // Look up the enumeration description in localized resources; fall back to
                            // the plain enum name if the localization lookup fails.
                            ComboItemList[i].DisplayName = resources.GetString(EnumDisplayName.Description) ?? EnumFields[i].Name;
                        }
                        else
                        {
                            // Use the value passed as the enumeration description.
                            ComboItemList[i].DisplayName = EnumDisplayName.Description;
                        }
                    }

                    // Set the value.
                    ComboItemList[i].Value = Enum.Parse(source, EnumFields[i].Name);
                }

                targetCombo.DisplayMember = "DisplayName";
                targetCombo.ValueMember   = "Value";
                targetCombo.DataSource    = ComboItemList;
            }
        }
예제 #5
0
        public void SetIsLocalizable(bool isLocalizable)
        {
            var attr = (LocalizableAttribute)attributes.FirstOrDefault(a => a is LocalizableAttribute);

            if (attr != null)
            {
                attributes.RemoveAll(a => a is LocalizableAttribute);
            }
            attr = new LocalizableAttribute(isLocalizable);
            attributes.Add(attr);
        }
예제 #6
0
        public override bool Equals(object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            LocalizableAttribute other = obj as LocalizableAttribute;

            return(other?.IsLocalizable == IsLocalizable);
        }
        private static bool IsPropertyLocalizable(PropertyDescriptor propertyDescriptor)
        {
            DesignerSerializationVisibilityAttribute attribute = (DesignerSerializationVisibilityAttribute)propertyDescriptor.Attributes[typeof(DesignerSerializationVisibilityAttribute)];

            if ((attribute != null) && (attribute.Visibility == DesignerSerializationVisibility.Hidden))
            {
                return(false);
            }
            LocalizableAttribute attribute2 = (LocalizableAttribute)propertyDescriptor.Attributes[typeof(LocalizableAttribute)];

            return((attribute2 != null) && attribute2.IsLocalizable);
        }
예제 #8
0
        // Determine if two objects are equal.
        public override bool Equals(Object obj)
        {
            LocalizableAttribute other = (obj as LocalizableAttribute);

            if (other != null)
            {
                return(localizable == other.localizable);
            }
            else
            {
                return(false);
            }
        }
예제 #9
0
파일: source.cs 프로젝트: ruo2012/samples-1
    // </Snippet1>

    public void Method1()
    {
        // <Snippet2>
        // Gets the attributes for the property.
        AttributeCollection attributes =
            TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;

        // Checks to see if the property needs to be localized.
        LocalizableAttribute myAttribute =
            (LocalizableAttribute)attributes[typeof(LocalizableAttribute)];

        if (myAttribute.IsLocalizable)
        {
            // Insert code here.
        }
        // </Snippet2>
    }
 public void DefaultProperties_GetLocalizable_ReturnsExpected(LocalizableAttribute attribute, bool expectedLocalizable)
 {
     Assert.Equal(expectedLocalizable, attribute.IsLocalizable);
     Assert.Equal(!expectedLocalizable, attribute.IsDefaultAttribute());
 }
예제 #11
0
 public void NameTests(LocalizableAttribute attribute, bool isLocalizable)
 {
     Assert.Equal(isLocalizable, attribute.IsLocalizable);
 }
예제 #12
0
        public void GetIsLocalizable(bool value)
        {
            var attribute = new LocalizableAttribute(value);

            Assert.Equal(value, attribute.IsLocalizable);
        }
        private void UpdateStringFromResource(PropertyDescriptorCollection pdc)
        {
            ResourceAttribute ra = (ResourceAttribute)GetAttributes().Get(typeof(ResourceAttribute), true);
            ResourceManager   rm;

            if (ra == null)
            {
                return;
            }

            try
            {
                if (string.IsNullOrEmpty(ra.BaseName) == false && String.IsNullOrEmpty(ra.AssemblyFullName) == false)
                {
                    rm = new ResourceManager(ra.BaseName, Assembly.ReflectionOnlyLoad(ra.AssemblyFullName));
                }
                else if (string.IsNullOrEmpty(ra.BaseName) == false)
                {
                    rm = new ResourceManager(ra.BaseName, m_instance.GetType().Assembly);
                }
                else
                {
                    rm = new ResourceManager(m_instance.GetType());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            string sKeyPrefix = (ra.KeyPrefix);

            foreach (DynPropertyDescriptor pd in pdc)
            {
                LocalizableAttribute la = (LocalizableAttribute)pd.Attributes.Get(typeof(LocalizableAttribute), true);
                if (la != null && !pd.IsLocalizable)
                {
                    continue;
                }
                if (pd.LCID == CultureInfo.CurrentUICulture.LCID)
                {
                    continue;
                }

                //al = pd.AttributeList;
                string sKey;
                string sResult;

                // first category
                if (!string.IsNullOrEmpty(pd.CategoryResourceKey))
                {
                    sKey = sKeyPrefix + pd.CategoryResourceKey;

                    try
                    {
                        sResult = rm.GetString(sKey);
                        if (!string.IsNullOrEmpty(sResult))
                        {
                            pd.Attributes.Add(new CategoryAttribute(sResult), true);
                        }
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Key '{0}' does not exist in the resource.", sKey);
                    }
                }

                // now display name
                sKey = sKeyPrefix + pd.Name + "_Name";
                try
                {
                    sResult = rm.GetString(sKey);
                    if (!string.IsNullOrEmpty(sResult))
                    {
                        pd.Attributes.Add(new DisplayNameAttribute(sResult), typeof(DisplayNameAttribute));
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Key '{0}' does not exist in the resource.", sKey);
                }

                // and now description
                sKey = sKeyPrefix + pd.Name + "_Desc";
                try
                {
                    sResult = rm.GetString(sKey);
                    if (!string.IsNullOrEmpty(sResult))
                    {
                        pd.Attributes.Add(new DescriptionAttribute(sResult), true);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Key '{0}' does not exist in the resource.", sKey);
                }
            }
        }
예제 #14
0
 public void NameTests(LocalizableAttribute attribute, bool isLocalizable)
 {
     Assert.Equal(isLocalizable, attribute.IsLocalizable);
 }
예제 #15
0
        public void GetIsLocalizable(bool value)
        {
            var attribute = new LocalizableAttribute(value);

            Assert.Equal(value, attribute.IsLocalizable);
        }