예제 #1
0
        public override bool Works()
        {
            int check = 0;

            foreach (FieldInfo fieldInfo in this.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                try
                {
                    if (fieldInfo.FieldType.IsSubclassOf(typeof(aECGElement)))
                    {
                        aECGElement temp = (aECGElement)fieldInfo.GetValue(this);

                        if (temp != null)
                        {
                            check++;
                        }
                    }
                }
                catch {}
            }

            return(check == 1);
        }
예제 #2
0
        public static int ReadOne(object obj, XmlReader reader)
        {
            if (obj == null)
            {
                return(-2);
            }

            if (reader.NodeType == XmlNodeType.EndElement)
            {
                return(0);
            }

            int ret = 0;

            foreach (FieldInfo fieldInfo in obj.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                try
                {
                    if (fieldInfo.FieldType.IsSubclassOf(typeof(aECGElement)))
                    {
                        aECGElement temp = (aECGElement)fieldInfo.GetValue(obj);

                        if ((temp != null) &&
                            (String.Compare(reader.Name, temp.Name) == 0))
                        {
                            ret = temp.Read(reader);

                            return(ret);
                        }
                    }
                    else if ((fieldInfo.FieldType == typeof(string)) &&
                             char.IsLower(fieldInfo.Name[0]))
                    {
                        if (String.Compare(reader.Name, fieldInfo.Name) == 0)
                        {
                            if (reader.IsEmptyElement)
                            {
                                return(0);
                            }

                            reader.Read();

                            if ((reader.Name == fieldInfo.Name) &&
                                (reader.NodeType == XmlNodeType.EndElement))
                            {
                                return(0);
                            }

                            fieldInfo.SetValue(obj, reader.Value);

                            reader.Read();

                            if ((reader.Name != fieldInfo.Name) ||
                                (reader.NodeType != XmlNodeType.EndElement))
                            {
                                return(1);
                            }

                            return(0);
                        }
                    }
                    else if (fieldInfo.FieldType.IsArray &&
                             fieldInfo.FieldType.HasElementType &&
                             (fieldInfo.FieldType.GetElementType().IsSubclassOf(typeof(aECGElement))))
                    {
                        Array array = (Array)fieldInfo.GetValue(obj);

                        if (array != null)
                        {
                            Type type = fieldInfo.FieldType.GetElementType();

                            aECGElement temp = (aECGElement)Activator.CreateInstance(type);

                            if (String.Compare(reader.Name, temp.Name) == 0)
                            {
                                ret = temp.Read(reader);

                                if (ret == 0)
                                {
                                    for (int i = 0; i < array.Length; i++)
                                    {
                                        if (array.GetValue(i) == null)
                                        {
                                            array.SetValue(temp, i);
                                            break;
                                        }
                                    }
                                }

                                return(ret);
                            }
                        }
                    }
                }
                catch
                {
                }
            }

            aECGUnknownElement element = new aECGUnknownElement(reader.Name);

            ret = element.Read(reader);

            if (obj.GetType().IsSubclassOf(typeof(aECGElement)))
            {
                ((aECGElement)obj).UnknownElements.Add(element);
            }
            else
            {
                try
                {
                    FieldInfo fieldInfo = obj.GetType().GetField("UnknownElements");

                    ((ArrayList)fieldInfo.GetValue(obj)).Add(element);
                }
                catch
                {
                    return(-3);
                }
            }

            return(ret);
        }
예제 #3
0
        public static int EmptyAll(object obj)
        {
            if (obj == null)
            {
                return(-2);
            }

            foreach (FieldInfo fieldInfo in obj.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                try
                {
                    if (fieldInfo.FieldType.IsSubclassOf(typeof(aECGElement)))
                    {
                        aECGElement temp = (aECGElement)fieldInfo.GetValue(obj);

                        temp.Empty();
                    }
                    else if ((fieldInfo.FieldType == typeof(string)) &&
                             char.IsLower(fieldInfo.Name[0]))
                    {
                        fieldInfo.SetValue(obj, null);
                    }
                    else if (fieldInfo.FieldType.IsArray &&
                             fieldInfo.FieldType.HasElementType &&
                             (fieldInfo.FieldType.GetElementType().IsSubclassOf(typeof(aECGElement))))
                    {
                        Array array = (Array)fieldInfo.GetValue(obj);

                        if (array != null)
                        {
                            for (int i = 0; i < array.Length; i++)
                            {
                                array.SetValue(null, i);
                            }

                            fieldInfo.SetValue(obj, null);
                        }
                    }
                }
                catch
                {
                }
            }

            if (obj.GetType().IsSubclassOf(typeof(aECGElement)))
            {
                ((aECGElement)obj).UnknownElements.Clear();
            }
            else
            {
                try
                {
                    FieldInfo fieldInfo = obj.GetType().GetField("UnknownElements");

                    ((ArrayList)fieldInfo.GetValue(obj)).Clear();
                }
                catch
                {
                    return(-3);
                }
            }

            return(0);
        }
예제 #4
0
        public static int WriteAll(object obj, XmlWriter writer)
        {
            if (obj == null)
            {
                return(-2);
            }

            int ret = 0;

            foreach (FieldInfo fieldInfo in obj.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                try
                {
                    if (fieldInfo.FieldType.IsSubclassOf(typeof(aECGElement)))
                    {
                        aECGElement temp = (aECGElement)fieldInfo.GetValue(obj);

                        if (temp != null)
                        {
                            ret = temp.Write(writer);

                            if (ret != 0)
                            {
                                return(ret);
                            }
                        }
                    }
                    else if ((fieldInfo.FieldType == typeof(string)) &&
                             char.IsLower(fieldInfo.Name[0]))
                    {
                        string val = (string)fieldInfo.GetValue(obj);

                        if (val != null)
                        {
                            writer.WriteStartElement(fieldInfo.Name);
                            writer.WriteString(val);
                            writer.WriteEndElement();
                        }
                    }
                    else if (fieldInfo.FieldType.IsArray &&
                             fieldInfo.FieldType.HasElementType &&
                             (fieldInfo.FieldType.GetElementType().IsSubclassOf(typeof(aECGElement))))
                    {
                        Array array = (Array)fieldInfo.GetValue(obj);

                        if (array != null)
                        {
                            foreach (aECGElement element in array)
                            {
                                if (element == null)
                                {
                                    break;
                                }

                                element.Write(writer);
                            }
                        }
                    }
                }
                catch
                {
                }
            }

            if (obj.GetType().IsSubclassOf(typeof(aECGElement)))
            {
                foreach (aECGUnknownElement element in ((aECGElement)obj).UnknownElements)
                {
                    ret = element.Write(writer);

                    if (ret != 0)
                    {
                        return(ret);
                    }
                }
            }
            else
            {
                try
                {
                    FieldInfo fieldInfo = obj.GetType().GetField("UnknownElements");

                    foreach (aECGUnknownElement element in (ArrayList)fieldInfo.GetValue(obj))
                    {
                        ret = element.Write(writer);

                        if (ret != 0)
                        {
                            return(ret);
                        }
                    }
                }
                catch
                {
                    return(-3);
                }
            }

            return(ret);
        }