Stetic.PropertyDescriptor.TranslationContext C# (CSharp) Method

TranslationContext() public method

public TranslationContext ( object obj ) : string
obj object
return string
        public virtual string TranslationContext(object obj)
        {
            ObjectWrapper wrapper = ObjectWrapper.Lookup (obj);
            if (wrapper == null || wrapper.translationInfo == null) return null;

            TranslationInfo info = (TranslationInfo)wrapper.translationInfo[obj];
            return info != null ? info.Context : null;
        }

Usage Example

Example #1
0
        public static void GetProps(ObjectWrapper wrapper, XmlElement parent_elem)
        {
            ClassDescriptor klass = wrapper.ClassDescriptor;

            foreach (ItemGroup group in klass.ItemGroups)
            {
                foreach (ItemDescriptor item in group)
                {
                    PropertyDescriptor prop = item as PropertyDescriptor;
                    if (prop == null)
                    {
                        continue;
                    }
                    if (!prop.VisibleFor(wrapper.Wrapped) || !prop.CanWrite || prop.Name == "Name")                             // Name is written in the id attribute
                    {
                        continue;
                    }

                    object value = prop.GetValue(wrapper.Wrapped);

                    // If the property has its default value, we don't need to write it
                    if (value == null || (prop.HasDefault && prop.IsDefaultValue(value)))
                    {
                        continue;
                    }

                    string val = prop.ValueToString(value);
                    if (val == null)
                    {
                        continue;
                    }

                    XmlElement prop_elem = parent_elem.OwnerDocument.CreateElement("property");
                    prop_elem.SetAttribute("name", prop.Name);
                    if (val.Length > 0)
                    {
                        prop_elem.InnerText = val;
                    }

                    if (prop.Translatable && prop.IsTranslated(wrapper.Wrapped))
                    {
                        prop_elem.SetAttribute("translatable", "yes");
                        string tcx = prop.TranslationContext(wrapper.Wrapped);
                        if (tcx != null && tcx.Length > 0)
                        {
                            prop_elem.SetAttribute("context", "yes");
                            prop_elem.InnerText = tcx + "|" + prop_elem.InnerText;
                        }
                        string tcm = prop.TranslationComment(wrapper.Wrapped);
                        if (tcm != null && tcm.Length > 0)
                        {
                            prop_elem.SetAttribute("comments", prop.TranslationComment(wrapper.Wrapped));
                        }
                    }

                    parent_elem.AppendChild(prop_elem);
                }
            }
        }