예제 #1
0
        private void PreLoadPropertyMappingsDictionary(Type rootItemType)
        {
            foreach (Type itemType in Assembly.GetAssembly(rootItemType).GetExportedTypes())
            {
                if (typeof(IFrameworkItem).IsAssignableFrom(itemType) && !itemType.IsAbstract && !PropertyMappingDictionary.ContainsKey(itemType))
                {
                    var            propertyBindings = new Dictionary <XName, PropertyBindingAttributePair>();
                    PropertyInfo[] itemProperties   = itemType.GetProperties();

                    var bindingAttributeKeyValuePairs =
                        from property in itemProperties
                        from bindingAttribute in CustomAttributeProvider.Global.GetAttribute <AstXNameBindingAttribute>(property, false)
                        where property.CanWrite || CommonUtility.IsContainerOf(typeof(ICollection <object>), property.PropertyType)
                        select new { property, attribute = bindingAttribute };

                    foreach (var pair in bindingAttributeKeyValuePairs)
                    {
                        XName xname;
                        if (pair.attribute.IsChildListElement)
                        {
                            xname = XName.Get(pair.property.Name, DefaultXmlNamespace);
                        }
                        else
                        {
                            xname = XName.Get(pair.attribute.Name, DefaultXmlNamespace);
                        }

                        propertyBindings[xname] = new PropertyBindingAttributePair(pair.property, pair.attribute);
                    }

                    PropertyMappingDictionary.Add(itemType, propertyBindings);
                }
            }
        }
예제 #2
0
파일: AstParser.cs 프로젝트: mosamy/vulcan
 private static void ParseAttributes(ParserContext context)
 {
     foreach (XAttribute attribute in context.XElement.Attributes())
     {
         PropertyBindingAttributePair propertyBinding = PropertyBinder.GetPropertyBinding(context, attribute.Name, true);
         ParseChildXObject(context, attribute, attribute.Value, propertyBinding == null ? null : propertyBinding.Property);
     }
 }
예제 #3
0
파일: AstParser.cs 프로젝트: mosamy/vulcan
        private static void ParseChildElements(ParserContext context)
        {
            foreach (XElement childElement in context.XElement.Elements())
            {
                PropertyBindingAttributePair propertyBinding = PropertyBinder.GetPropertyBinding(context, childElement.Name, false);
                ParseChildXObject(context, childElement, childElement.Value, propertyBinding == null ? null : propertyBinding.Property);
            }

            XElement element = context.XElement;
            PropertyBindingAttributePair textPropertyBinding  = PropertyBinder.GetPropertyBinding(context, XName.Get("__self", element.Name.NamespaceName), false);
            AstXNameBindingAttribute     textBindingAttribute = textPropertyBinding == null ? null : textPropertyBinding.BindingAttribute;

            if (textBindingAttribute != null && textBindingAttribute.IsSelf)
            {
                ParseChildXObject(context, element.LastNode, element.Value, textPropertyBinding.Property);
            }
        }