IsDefaultValue() public method

public IsDefaultValue ( object value ) : bool
value object
return bool
Ejemplo n.º 1
0
        protected virtual void GeneratePropertySet(GeneratorContext ctx, CodeExpression var, PropertyDescriptor prop)
        {
            object oval = prop.GetValue(Wrapped);

            if (oval == null || (prop.HasDefault && prop.IsDefaultValue(oval)))
            {
                return;
            }

            CodeExpression val = ctx.GenerateValue(oval, prop.RuntimePropertyType, prop.Translatable && prop.IsTranslated(Wrapped));
            CodeExpression cprop;

            TypedPropertyDescriptor tprop = prop as TypedPropertyDescriptor;

            if (tprop == null || tprop.GladeProperty == prop)
            {
                cprop = new CodePropertyReferenceExpression(var, prop.Name);
            }
            else
            {
                cprop = new CodePropertyReferenceExpression(var, tprop.GladeProperty.Name);
                cprop = new CodePropertyReferenceExpression(cprop, prop.Name);
            }
            ctx.Statements.Add(new CodeAssignStatement(cprop, val));
        }
Ejemplo n.º 2
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);
                }
            }
        }
Ejemplo n.º 3
0
		protected virtual void GeneratePropertySet (GeneratorContext ctx, CodeExpression var, PropertyDescriptor prop)
		{
			object oval = prop.GetValue (Wrapped);
			if (oval == null || (prop.HasDefault && prop.IsDefaultValue (oval)))
				return;
				
			CodeExpression val = ctx.GenerateValue (oval, prop.RuntimePropertyType, prop.Translatable && prop.IsTranslated (Wrapped));
			CodeExpression cprop;
			
			TypedPropertyDescriptor tprop = prop as TypedPropertyDescriptor;
			if (tprop == null || tprop.GladeProperty == prop) {
				cprop = new CodePropertyReferenceExpression (var, prop.Name);
			} else {
				cprop = new CodePropertyReferenceExpression (var, tprop.GladeProperty.Name);
				cprop = new CodePropertyReferenceExpression (cprop, prop.Name);
			}
			ctx.Statements.Add (new CodeAssignStatement (cprop, val));
		}