Exemplo n.º 1
0
        public static ComplexType Scan(Type type)
        {
            if (type.IsPrimitive || type == typeof(string) || type == typeof(object) || type == typeof(Guid) || type == typeof(DateTime) || type == typeof(TimeSpan) || type == typeof(DateTimeOffset) || type.IsEnum || type == typeof(Decimal))
                return null;

            ComplexType complex = new ComplexType();
            complex.Name = Reflect.GetTypeNameFrom(type);

            if (Repository.IsNormalizedList(type))
            {
                Type enumerated = Reflect.GetEnumeratedTypeFrom(type);

                Element e = Element.Scan(enumerated, Reflect.GetTypeNameFrom(enumerated));

                if (e != null)
                {
                    e.UnboundMaxOccurs();
                    e.MakeNillable();

                    complex.elements.Add(e);
                }

                Repository.Handle(enumerated);
            }
            else
            {
                Type baseType = null;

                if (!type.IsInterface)
                    if (type.BaseType != typeof (object) && type.BaseType != typeof(ValueType) && type.BaseType != null)
                        baseType = type.BaseType;

                if (type.IsInterface)
                    foreach(Type i in type.GetInterfaces())
                        if (i == typeof(IMessage))
                            continue;
                        else
                        {
                            baseType = i;
                            break;
                        }

                List<PropertyInfo> propsToIgnore = new List<PropertyInfo>();

                if (baseType != null)
                {
                    complex.BaseName = baseType.Name;
                    propsToIgnore = new List<PropertyInfo>(baseType.GetProperties());
                }

                foreach (PropertyInfo prop in type.GetProperties())
                {
                    if (IsInList(prop, propsToIgnore))
                        continue;

                    if (!IsKeyValuePair(type) && (!prop.CanRead || !prop.CanWrite))
                        continue;

                    Repository.Handle(prop.PropertyType);

                    Element e = Element.Scan(prop.PropertyType, prop.Name);

                    if (e != null)
                        complex.elements.Add(e);
                }
            }

            foreach(TimeToBeReceivedAttribute a in type.GetCustomAttributes(typeof(TimeToBeReceivedAttribute), true))
                complex.TimeToBeReceived = a.TimeToBeReceived;

            return complex;
        }
Exemplo n.º 2
0
 private ComplexTypeWriter(ComplexType complex)
 {
     this.complex = complex;
 }
Exemplo n.º 3
0
 public static void Write(ComplexType complex, StringBuilder builder)
 {
     new ComplexTypeWriter(complex).Write(builder);
 }
Exemplo n.º 4
0
 private ComplexTypeWriter(ComplexType complex)
 {
     this.complex = complex;
 }
Exemplo n.º 5
0
 public static void Write(ComplexType complex, StringBuilder builder)
 {
     new ComplexTypeWriter(complex).Write(builder);
 }
Exemplo n.º 6
0
        public static ComplexType Scan(Type type)
        {
            if (type.IsPrimitive || type == typeof(string) || type == typeof(object) || type == typeof(Guid) || type == typeof(DateTime) || type == typeof(TimeSpan) || type == typeof(DateTimeOffset) || type.IsEnum || type == typeof(Decimal))
            {
                return(null);
            }

            var complex = new ComplexType
            {
                Name = Reflect.GetTypeNameFrom(type)
            };

            if (Repository.IsNormalizedList(type))
            {
                var enumerated = Reflect.GetEnumeratedTypeFrom(type);

                var e = Element.Scan(enumerated, Reflect.GetTypeNameFrom(enumerated));

                if (e != null)
                {
                    e.UnboundMaxOccurs();
                    e.MakeNillable();

                    complex.elements.Add(e);
                }

                Repository.Handle(enumerated);
            }
            else
            {
                Type baseType = null;

                if (!type.IsInterface)
                {
                    if (type.BaseType != typeof(object) && type.BaseType != typeof(ValueType) && type.BaseType != null)
                    {
                        baseType = type.BaseType;
                    }
                }

                if (type.IsInterface)
                {
                    foreach (var i in type.GetInterfaces())
                    {
                        if (i == typeof(IMessage))
                        {
                            continue;
                        }
                        else
                        {
                            baseType = i;
                            break;
                        }
                    }
                }

                var propsToIgnore = new List <PropertyInfo>();

                if (baseType != null)
                {
                    complex.BaseName = baseType.Name;
                    propsToIgnore    = new List <PropertyInfo>(baseType.GetProperties());
                }

                foreach (var prop in type.GetProperties())
                {
                    if (IsInList(prop, propsToIgnore))
                    {
                        continue;
                    }

                    if (!IsKeyValuePair(type) && (!prop.CanRead || !prop.CanWrite))
                    {
                        continue;
                    }

                    Repository.Handle(prop.PropertyType);

                    var e = Element.Scan(prop.PropertyType, prop.Name);

                    if (e != null)
                    {
                        complex.elements.Add(e);
                    }
                }
            }

            foreach (TimeToBeReceivedAttribute a in type.GetCustomAttributes(typeof(TimeToBeReceivedAttribute), true))
            {
                complex.TimeToBeReceived = a.TimeToBeReceived;
            }

            return(complex);
        }