Ejemplo n.º 1
0
 public Property(ContentLine cl) : base(cl.Parent)
 {
     this.Name = cl.Name;
     this.Value = cl.Value;
     foreach (DictionaryEntry de in cl.Parameters)
         this.Parameters[de.Key] = de.Value;
 }
Ejemplo n.º 2
0
        virtual public void SetContentLineValue(ContentLine cl)
        {
            if (cl.Name != null)
            {
                string name = cl.Name.Replace("-","");
                Type type = GetType();

                FieldInfo field = type.GetField(name, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                if (field != null)
                {
                    object value = field.GetValue(this);
                    Type elementType = field.FieldType.IsArray ? field.FieldType.GetElementType() : field.FieldType;

                    // If it's an iCalDataType, or an array of iCalDataType, then let's fill it!
                    if (field.FieldType.IsSubclassOf(typeof(iCalDataType)) ||
                        (field.FieldType.IsArray && field.FieldType.GetElementType().IsSubclassOf(typeof(iCalDataType))))
                    {   
                        iCalDataType icdt = null;
                        if (!field.FieldType.IsArray)
                            icdt = (iCalDataType)value;
                        if (icdt == null)
                            icdt = (iCalDataType)Activator.CreateInstance(elementType);

                        // Set the content line for the object.  On most objects, this
                        // triggers the object to parse the content line with Parse().
                        icdt.ContentLine = cl;

                        // It's an array, let's add an item to the end
                        if (field.FieldType.IsArray)
                        {
                            ArrayList arr = new ArrayList();
                            if (value != null)
                                arr.AddRange((ICollection)value);                            
                            arr.Add(icdt);
                            field.SetValue(this, arr.ToArray(elementType));
                        }
                        // Otherwise, set the value directly!
                        else field.SetValue(this, icdt);
                    }
                    else
                    {
                        FieldInfo minValue = field.FieldType.GetField("MinValue");
                        object minVal = (minValue != null) ? minValue.GetValue(null) : null;

                        if (field.FieldType.IsArray)
                        {
                            ArrayList arr = new ArrayList();
                            if (value != null)
                                arr.AddRange((ICollection)value);
                            arr.Add(cl.Value);
                            field.SetValue(this, arr.ToArray(elementType));
                        }
                        // Otherwise, set the value directly!
                        else if (value == null || value.Equals(minVal))
                            field.SetValue(this, cl.Value);
                        else ;// FIXME: throw single-value exception, if "strict" parsing is enabled
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public Property(ContentLine cl) : base(cl.Parent)
 {
     this.Name  = cl.Name;
     this.Value = cl.Value;
     foreach (DictionaryEntry de in cl.Parameters)
     {
         this.Parameters[de.Key] = de.Value;
     }
 }
Ejemplo n.º 4
0
        public override void SetContentLineValue(ContentLine cl)
        {
            base.SetContentLineValue(cl);

            if (cl.Name == "UID")
            {
                Text text = new Text();
                text.ContentLine = cl;
                UID = text.Value;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// For iCalendar components, automatically finds and retrieves fields that
        /// match the field specified in the <see cref="ContentLine"/>, and sets
        /// their value.
        /// <example>
        /// For example, if a public DTStart field exists in the specified component,
        /// (i.e. <c>public Date_Time DTStart;</c>)
        /// and a content line of <c>DTSTART;TZID=US-Eastern:20060830T090000</c> is
        /// encountered, this method will automatically set the value of the
        /// DTStart field to Aug. 30, 2006, 9:00 AM in the US-Eastern TimeZone.
        /// </example>
        /// <note>
        ///     It should not be necessary to invoke this method manually as it
        ///     is handled automatically during the iCalendar parsing.
        /// </note>
        /// </summary>
        /// <param name="cl">The <see cref="ContentLine"/> to process.</param>
        virtual public void SetContentLineValue(ContentLine cl)
        {
            if (cl.Name != null)
            {
                string name = cl.Name.Replace("-", "");
                Type   type = GetType();

                //
                // Find the public field that matches the name of our content line (ignoring case)
                //
                FieldInfo    field    = type.GetField(name, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Static);
                PropertyInfo property = null;

                if (field == null)
                {
                    property = type.GetProperty(name, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Static);
                }

                if (field != null ||
                    property != null)
                {
                    // Get the field/property's value
                    object value = field == null?property.GetValue(this, null) : field.GetValue(this);

                    Type     itemType       = field == null ? property.PropertyType : field.FieldType;
                    object[] itemAttributes = field == null?property.GetCustomAttributes(true) : field.GetCustomAttributes(true);

                    Type elementType = itemType.IsArray ? itemType.GetElementType() : itemType;

                    // If it's an iCalDataType, or an array of iCalDataType, then let's fill it!
                    if (itemType.IsSubclassOf(typeof(iCalDataType)) ||
                        (itemType.IsArray && itemType.GetElementType().IsSubclassOf(typeof(iCalDataType))))
                    {
                        iCalDataType icdt = null;
                        if (!itemType.IsArray)
                        {
                            icdt = (iCalDataType)value;
                        }
                        if (icdt == null)
                        {
                            icdt = (iCalDataType)Activator.CreateInstance(elementType);
                        }

                        // Assign custom attributes for the specific field
                        icdt.Attributes = itemAttributes;

                        // Set the content line for the object.  On most objects, this
                        // triggers the object to parse the content line with Parse().
                        icdt.ContentLine = cl;

                        // It's an array, let's add an item to the end
                        if (itemType.IsArray)
                        {
                            ArrayList arr = new ArrayList();
                            if (value != null)
                            {
                                arr.AddRange((ICollection)value);
                            }
                            arr.Add(icdt);
                            if (field != null)
                            {
                                field.SetValue(this, arr.ToArray(elementType));
                            }
                            else
                            {
                                property.SetValue(this, arr.ToArray(elementType), null);
                            }
                        }
                        // Otherwise, set the value directly!
                        else
                        {
                            if (field != null)
                            {
                                field.SetValue(this, icdt);
                            }
                            else
                            {
                                property.SetValue(this, icdt, null);
                            }
                        }
                    }
                    else
                    {
                        FieldInfo minValue = itemType.GetField("MinValue");
                        object    minVal   = (minValue != null) ? minValue.GetValue(null) : null;

                        if (itemType.IsArray)
                        {
                            ArrayList arr = new ArrayList();
                            if (value != null)
                            {
                                arr.AddRange((ICollection)value);
                            }
                            arr.Add(cl.Value);

                            if (field != null)
                            {
                                field.SetValue(this, arr.ToArray(elementType));
                            }
                            else
                            {
                                property.SetValue(this, arr.ToArray(elementType), null);
                            }
                        }
                        // Always assign enum values
                        else if (itemType.IsEnum)
                        {
                            if (field != null)
                            {
                                field.SetValue(this, Enum.Parse(itemType, cl.Value.Replace("-", "_")));
                            }
                            else
                            {
                                property.SetValue(this, Enum.Parse(itemType, cl.Value.Replace("-", "_")), null);
                            }
                        }
                        // Otherwise, set the value directly!
                        else if (value == null || value.Equals(minVal))
                        {
                            if (field != null)
                            {
                                field.SetValue(this, cl.Value);
                            }
                            else
                            {
                                property.SetValue(this, cl.Value, null);
                            }
                        }
                        else
                        {
                            ; // FIXME: throw single-value exception, if "strict" parsing is enabled
                        }
                    }
                }
                else
                {
                    // This is a non-standard property.  Let's load it into memory,
                    // So we can serialize it later
                    Property p = new Property(cl);
                    p.AddToParent();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// For iCalendar components, automatically finds and retrieves fields that
        /// match the field specified in the <see cref="ContentLine"/>, and sets
        /// their value.
        /// <example>
        /// For example, if a public DTStart field exists in the specified component,
        /// (i.e. <c>public Date_Time DTStart;</c>)
        /// and a content line of <c>DTSTART;TZID=US-Eastern:20060830T090000</c> is
        /// encountered, this method will automatically set the value of the
        /// DTStart field to Aug. 30, 2006, 9:00 AM in the US-Eastern TimeZone.
        /// </example>
        /// <note>
        ///     It should not be necessary to invoke this method manually as it
        ///     is handled automatically during the iCalendar parsing.
        /// </note>
        /// </summary>
        /// <param name="cl">The <see cref="ContentLine"/> to process.</param>
        virtual public void SetContentLineValue(ContentLine cl)
        {
            if (cl.Name != null)
            {
                string name = cl.Name.Replace("-","");
                Type type = GetType();

                //
                // Find the public field that matches the name of our content line (ignoring case)
                //
                FieldInfo field = type.GetField(name, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Static);
                PropertyInfo property = null;
                
                if (field == null)
                    property = type.GetProperty(name, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Static);

                if (field != null ||
                    property != null)
                {
                    // Get the field/property's value
                    object value = field == null ? property.GetValue(this, null) : field.GetValue(this);
                    Type itemType = field == null ? property.PropertyType : field.FieldType;
                    object[] itemAttributes = field == null ? property.GetCustomAttributes(true) : field.GetCustomAttributes(true);

                    Type elementType = itemType.IsArray ? itemType.GetElementType() : itemType;

                    // If it's an iCalDataType, or an array of iCalDataType, then let's fill it!
                    if (itemType.IsSubclassOf(typeof(iCalDataType)) ||
                        (itemType.IsArray && itemType.GetElementType().IsSubclassOf(typeof(iCalDataType))))
                    {
                        iCalDataType icdt = null;
                        if (!itemType.IsArray)
                            icdt = (iCalDataType)value;
                        if (icdt == null)
                            icdt = (iCalDataType)Activator.CreateInstance(elementType);

                        // Assign custom attributes for the specific field
                        icdt.Attributes = itemAttributes;

                        // Set the content line for the object.  On most objects, this
                        // triggers the object to parse the content line with Parse().
                        icdt.ContentLine = cl;

                        // It's an array, let's add an item to the end
                        if (itemType.IsArray)
                        {
                            ArrayList arr = new ArrayList();
                            if (value != null)
                                arr.AddRange((ICollection)value);
                            arr.Add(icdt);
                            if (field != null)
                                field.SetValue(this, arr.ToArray(elementType));
                            else
                                property.SetValue(this, arr.ToArray(elementType), null);
                        }
                        // Otherwise, set the value directly!
                        else 
                        {
                            if (field != null)
                                field.SetValue(this, icdt);
                            else property.SetValue(this, icdt, null);
                        }
                    }
                    else
                    {
                        FieldInfo minValue = itemType.GetField("MinValue");
                        object minVal = (minValue != null) ? minValue.GetValue(null) : null;

                        if (itemType.IsArray)
                        {
                            ArrayList arr = new ArrayList();
                            if (value != null)
                                arr.AddRange((ICollection)value);
                            arr.Add(cl.Value);

                            if (field != null)
                                field.SetValue(this, arr.ToArray(elementType));
                            else property.SetValue(this, arr.ToArray(elementType), null);
                        }
                        // Always assign enum values
                        else if (itemType.IsEnum)
                        {
                            if (field != null)
                                field.SetValue(this, Enum.Parse(itemType, cl.Value.Replace("-", "_")));
                            else property.SetValue(this, Enum.Parse(itemType, cl.Value.Replace("-", "_")), null);
                        }
                        // Otherwise, set the value directly!
                        else if (value == null || value.Equals(minVal))
                        {
                            if (field != null)
                                field.SetValue(this, cl.Value);
                            else property.SetValue(this, cl.Value, null);
                        }
                        else ;// FIXME: throw single-value exception, if "strict" parsing is enabled
                    }
                }
                else
                {
                    // This is a non-standard property.  Let's load it into memory,
                    // So we can serialize it later
                    Property p = new Property(cl);
                    p.AddToParent();
                }
            }
        }
Ejemplo n.º 7
0
        virtual public void SetContentLineValue(ContentLine cl)
        {
            if (cl.Name != null)
            {
                string name = cl.Name;
                Type   type = GetType();

                FieldInfo field = type.GetField(name, BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                if (field != null)
                {
                    object value = field.GetValue(this);

                    // If it's an iCalDataType, or an array of iCalDataType, then let's fill it!
                    if (field.FieldType.IsSubclassOf(typeof(iCalDataType)) ||
                        (field.FieldType.IsArray && field.FieldType.GetElementType().IsSubclassOf(typeof(iCalDataType))))
                    {
                        Type elementType = field.FieldType.IsArray ? field.FieldType.GetElementType() : field.FieldType;

                        iCalDataType icdt = null;
                        if (!field.FieldType.IsArray)
                        {
                            icdt = (iCalDataType)value;
                        }
                        if (icdt == null)
                        {
                            icdt = (iCalDataType)Activator.CreateInstance(elementType);
                        }
                        icdt.ContentLine = cl;

                        // It's an array, let's add an item to the end
                        if (field.FieldType.IsArray)
                        {
                            ArrayList arr = new ArrayList();
                            if (value != null)
                            {
                                arr.AddRange((ICollection)value);
                            }
                            arr.Add(icdt);
                            field.SetValue(this, arr.ToArray(elementType));
                        }
                        // Otherwise, set the value directly!
                        else
                        {
                            field.SetValue(this, icdt);
                        }
                    }
                    else
                    {
                        FieldInfo minValue = field.FieldType.GetField("MinValue");
                        object    minVal   = (minValue != null) ? minValue.GetValue(null) : null;

                        if (value == null || value.Equals(minVal))
                        {
                            field.SetValue(this, cl.Value);
                        }
                        else
                        {
                            ; // FIXME: throw single-value exception, if "strict" parsing is enabled
                        }
                    }
                }
            }
        }