Beispiel #1
0
 public ImportedContentTypeField GetField(string name)
 {
     if (!this.Fields.ContainsKey(name))
     {
         // Resolve via inheritance if necessary
         ImportedContentType parent = this.Parent;
         return(parent != null ? parent.GetField(name) : null);
     }
     return(Fields[name]);
 }
Beispiel #2
0
        protected void ApplyAttributes(ListItem li, XElement attributes, String objectType)
        {
            XNamespace          ns         = attributes.GetDefaultNamespace();
            ImportedContentType typeObject = this.ContentTypeImporter.ResolveLibraryContentType(objectType);

            foreach (XElement attribute in attributes.Elements(ns + "attribute"))
            {
                string fieldName           = attribute.Attribute("name").Value;
                ImportedContentTypeField f = typeObject.GetField(fieldName);
                if (f == null)
                {
                    continue;
                }
                // Ok...so...now we convert the value and slam it into the thing
                object value = null;
                if (f.Repeating)
                {
                    value = "|";
                    bool first = true;
                    foreach (XElement v in attribute.Elements(ns + "value"))
                    {
                        if (!first)
                        {
                            value += "|";
                        }
                        value += Tools.SanitizeSingleLineString((string)v);
                        first  = false;
                    }
                    value += "|";
                }
                else
                {
                    FieldType type = Tools.DecodeFieldType(attribute.Attribute("dataType").Value);
                    string    v    = Tools.SanitizeSingleLineString((string)attribute.Elements(ns + "value").FirstOrDefault());
                    if (type == FieldType.Text)
                    {
                        value = v;
                    }
                    else if (v != null && v != string.Empty)
                    {
                        switch (type)
                        {
                        case FieldType.Boolean:
                            value = XmlConvert.ToBoolean(v);
                            break;

                        case FieldType.Integer:
                            value = XmlConvert.ToInt32(v);
                            break;

                        case FieldType.Number:
                            value = XmlConvert.ToDecimal(v);
                            break;

                        case FieldType.DateTime:
                            value = Tools.ParseXmlDate(v);
                            break;

                        default:
                            value = v;
                            break;
                        }
                    }
                }
                li[f.FinalName] = value;
            }
        }