public DictionaryListObjectPropertyInfo(object value, NamedAttribute attr)
     : base(attr, null)
 {
     fValue     = value;
     fValueType = value.GetType();
     fLocalName = attr.LocalName;
 }
 public DictionaryListObjectPropertyInfo(object value, NamedAttribute attr, QName root)
     : this(value, attr)
 {
     if (root != null)
     {
         fLocalName = root.LocalName;
     }
 }
Beispiel #3
0
        private void WriteComplexElement(NamedAttribute attribute, object writer,
                                         object value, WriteSettings settings, ObjectPropertyInfo info)
        {
            JsonWriter jsonWriter = writer.Convert <JsonWriter>();

            if (info.WriteMode == SerializerWriteMode.WriteName)
            {
                QName name = info.QName;
                jsonWriter.WritePropertyName(name.LocalName);
            }
            WriteComplexContent(jsonWriter, value.ConvertToString());
        }
Beispiel #4
0
 private static void CheckAttribute(IObjectSerializer serializer,
                                    NamedAttribute attribute, bool checkAttribute)
 {
     if (checkAttribute)
     {
         if (attribute == null || string.IsNullOrEmpty(attribute.LocalName))
         {
             throw new ToolkitException(string.Format(ObjectUtil.SysCulture,
                                                      "{0}要求传入的attribute参数必须配置LocalName,当前没有配置", serializer), serializer);
         }
     }
 }
Beispiel #5
0
        public CustomPropertyInfo(Type dataType, NamedAttribute attribute)
        {
            TkDebug.AssertArgumentNull(dataType, "dataType", null);
            TkDebug.AssertArgumentNull(attribute, "attribute", null);

            TkDebug.Assert(attribute is SimpleElementAttribute || attribute is BaseDictionaryAttribute,
                           string.Format(ObjectUtil.SysCulture,
                                         "attribute必须是ElementAttribute或者DictionaryAttribute,现在的attribute是{0}",
                                         attribute.GetType()), null);

            DataType  = dataType;
            Attribute = attribute;
        }
Beispiel #6
0
        private static void WriteSimpleElement(NamedAttribute attribute, object writer,
                                               object value, WriteSettings settings, ObjectPropertyInfo info, bool useSourceType)
        {
            //if (ObjectUtil.IsDefaultValue(attribute.DefaultValue, value))
            //    return;

            JsonWriter jsonWriter = writer.Convert <JsonWriter>();

            if (info.WriteMode == SerializerWriteMode.WriteName)
            {
                QName name = info.QName;
                jsonWriter.WritePropertyName(name.LocalName);
            }
            WriteSimpleJsonValue(jsonWriter, value, settings, info, useSourceType);
        }
        public SingleElementWriter(ObjectPropertyInfo propertyInfo)
        {
            Content    = propertyInfo;
            fAttribute = Content.Attribute.Convert <NamedAttribute>();
            SimpleElementAttribute eleAttr = fAttribute as SimpleElementAttribute;

            if (eleAttr != null)
            {
                IsValueMulitple = eleAttr.IsMultiple;
            }
            IOrder order = fAttribute as IOrder;

            Order        = order != null ? order.Order : int.MaxValue;
            PropertyName = propertyInfo.PropertyName;
        }
Beispiel #8
0
        //#region IEnumerable<ObjectPropertyInfo> 成员

        //public IEnumerator<ObjectPropertyInfo> GetEnumerator()
        //{
        //    return fElements.Values.GetEnumerator();
        //}

        //#endregion IEnumerable<ObjectPropertyInfo> 成员

        //#region IEnumerable 成员

        //IEnumerator IEnumerable.GetEnumerator()
        //{
        //    return GetEnumerator();
        //}

        //#endregion IEnumerable 成员

        //private void InternalAdd(Type type, PropertyInfo property,
        //    NamedAttribute elementAttribute, string modelName)
        //{
        //    elementAttribute.SetNameMode(modelName, property);
        //    ObjectPropertyInfo item = new ReflectorObjectPropertyInfo(property, elementAttribute, modelName);
        //    QName key = elementAttribute.GetQName(item.LocalName);
        //    try
        //    {
        //        fElements.Add(key, item);
        //        fLocalElements.Add(key.LocalName, item);
        //        ObjectPropertyInfoList list;
        //        if (fProperties.ContainsKey(property))
        //            list = fProperties[property];
        //        else
        //        {
        //            list = new ObjectPropertyInfoList(property, elementAttribute.Required);
        //            fProperties.Add(property, list);
        //        }
        //        list.Add(type, item);
        //    }
        //    catch (Exception ex)
        //    {
        //        TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
        //            "类型{0}的属性{1}中的XmlElementAttribute或者MultipleFlagAttribute的Name(值为{2})已存在,请检查",
        //            type, property.Name, key), ex, type);
        //    }
        //}

        //private void AddAttribute(SimpleElementAttribute elementAttribute, Type type,
        //    PropertyInfo property, string modelName)
        //{
        //    //ElementAttribute attr = elementAttribute as ElementAttribute;
        //    //bool addDefault = attr.DefaultValue != null && !attr.IsMultiple &&
        //    //    attr.GetType() == typeof(XmlElementAttribute);
        //    InternalAdd(type, property, elementAttribute, modelName);
        //}

        private void AddSingleAttrible(Type type, PropertyInfo property,
                                       NamedAttribute elementAttribute, string modelName)
        {
            elementAttribute.SetNameMode(modelName, property);
            ObjectPropertyInfo item = new ReflectorObjectPropertyInfo(property, elementAttribute, modelName);
            QName key = elementAttribute.GetQName(item.LocalName);

            try
            {
                fSingleElements.Add(key, item);
                fSingleLocalElements.Add(key.LocalName, item);
                fElementWriter.Add(new SingleElementWriter(item));
            }
            catch (Exception ex)
            {
                TkDebug.ThrowToolkitException(string.Format(ObjectUtil.SysCulture,
                                                            "类型{0}的属性{1}中的XmlElementAttribute或者MultipleFlagAttribute的Name(值为{2})已存在,请检查",
                                                            type, property.Name, key), ex, type);
            }
        }
Beispiel #9
0
 internal void Add(Type type, PropertyInfo property,
                   NamedAttribute elementAttribute, string modelName)
 {
     //InternalAdd(type, property, elementAttribute, modelName);
     AddSingleAttrible(type, property, elementAttribute, modelName);
 }
Beispiel #10
0
 public CustomPropertyInfo(Type dataType, NamedAttribute attribute, ITkTypeConverter converter)
     : this(dataType, attribute)
 {
     Converter = converter;
 }