Example #1
0
 private void AddPendingInclude(XmlIncludeAttribute attribute)
 {
     if (pendingIncludes == null)
     {
         pendingIncludes = new List <Type>();
     }
     pendingIncludes.Add(attribute.Type);
 }
Example #2
0
        /// <summary>
        /// Some properties of the automatically generated  expect intermediate types around Arrays and some Objects.
        /// This method finds a property within typeToSearchWithin which can hold an object of type typeToSearchFor
        /// </summary>
        /// <param name="typeToSearchWithin"></param>
        /// <param name="typeToSearchFor"></param>
        /// <returns></returns>
        private PropertyInfo findWrappingProperty(Type typeToSearchWithin, Type typeToSearchFor)
        {
            if (typeToSearchWithin == null)
            {
                throw new ArgumentNullException("typeToSearch");
            }
            if (typeToSearchFor == null)
            {
                throw new ArgumentNullException("referencedType");
            }
            logger.Debug(String.Format(CultureInfo.InvariantCulture,
                                       "Attempting  to find a property in type {0} which directly, or via an intermediate type, holds objects of type {1}",
                                       typeToSearchWithin.Name,
                                       typeToSearchFor.Name));

            Assembly asm = Assembly.GetAssembly(typeToSearchWithin);

            PropertyInfo[] intProps = typeToSearchWithin.GetProperties();

            foreach (PropertyInfo prop in intProps)
            {
                if (prop == null)
                {
                    continue;
                }
                logger.Debug(String.Format(CultureInfo.InvariantCulture,
                                           "Investigating property {0} (type {1}) in type {2}",
                                           prop.Name,
                                           prop.PropertyType,
                                           typeToSearchWithin.Name));

                //check this anonType is not a base Type of the typeToSearch
                Type elementType = prop.PropertyType.GetElementType();
                if (elementType != null)
                {
                    logger.Debug("Checking if " + elementType.FullName + " is a base type");
                    if (elementType.IsAssignableFrom(typeToSearchFor))
                    {
                        return(prop);
                    }
                }

                object[] xmlElementAttributes = prop.GetCustomAttributes(typeof(XmlElementAttribute), true);
                if (xmlElementAttributes == null || xmlElementAttributes.Length < 1)
                {
                    logger.Debug("The property has no XmlElementAttributes to investigate");
                    continue;
                }

                foreach (object o in xmlElementAttributes)
                {
                    XmlElementAttribute att = o as XmlElementAttribute;
                    if (o == null)
                    {
                        continue;
                    }
                    if (att.ElementName == typeToSearchFor.Name)
                    {
                        return(prop);
                    }

                    logger.Debug(String.Format(CultureInfo.InvariantCulture,
                                               "Attempting to search for XmlIncludeAttributes in type {0} defined in an XmlElementAttribute",
                                               att.ElementName));
                    Type anonType = asm.GetType("IfcDotNet.Schema." + att.ElementName);                     //HACK brittle as namespace is directly input



                    //it may be via an intermediary anonymous type (using the XmlIncludeAttribute)
                    object[] xmlIncludeAttributes = anonType.GetCustomAttributes(typeof(XmlIncludeAttribute), false);
                    if (xmlIncludeAttributes == null || xmlIncludeAttributes.Length < 1)
                    {
                        continue;
                    }
                    foreach (object inc in xmlIncludeAttributes)
                    {
                        XmlIncludeAttribute incAtt = inc as XmlIncludeAttribute;
                        if (inc == null)
                        {
                            continue;
                        }
                        logger.Debug("Found an XmlIncludeAttribute applied to " + anonType.Name + " which includes type : " + incAtt.Type.Name);
                        if (incAtt.Type.FullName == typeToSearchFor.FullName)
                        {
                            return(prop);
                        }
                    }
                }
            }
            throw new StepBindingException(String.Format(CultureInfo.InvariantCulture,
                                                         "Could not find a property in type {0} which would wrap an object of type {1}",
                                                         typeToSearchWithin.Name,
                                                         typeToSearchFor.Name));
        }
        public void TypeDefault()
        {
            XmlIncludeAttribute attr = new XmlIncludeAttribute(null);

            Assert.IsNull(attr.Type);
        }