コード例 #1
0
        protected override void PopulateElementChildren(
            XElement element, Type declareType, object obj, XConvertSettings settings)
        {
            if (obj == null)
            {
                return;
            }

            var collectionProxy = CreateCollectionProxy(obj);
            var itemDeclareType = collectionProxy.ItemType;

            foreach (var item in collectionProxy)
            {
                var itemActualType = item != null?item.GetType() : null;

                var usingItemType = itemActualType ?? itemDeclareType;

                var itemElement = XConvert.ToElement(ItemName, item, settings);
                if (itemDeclareType != usingItemType)
                {
                    itemElement.Add(XConvertUtil.CreateTypeAttribute(usingItemType, settings.AssemblyNameStyle));
                }
                element.Add(itemElement);
            }
        }
コード例 #2
0
ファイル: XConverter.cs プロジェクト: xenosl/DebugInspector
        protected virtual XAttribute CreateTypeAttribute(Type declareType, Type actualType,
                                                         TypeAttributeHandling attributeHandling, FormatterAssemblyStyle?assemblyNameStyle)
        {
            XAttribute typeAttribute = null;

            switch (attributeHandling)
            {
            case TypeAttributeHandling.Auto:
                if (actualType != declareType)
                {
                    typeAttribute = XConvertUtil.CreateTypeAttribute(actualType, assemblyNameStyle);
                }
                break;

            case TypeAttributeHandling.Objects:
                if (!actualType.IsValueType)
                {
                    typeAttribute = XConvertUtil.CreateTypeAttribute(actualType, assemblyNameStyle);
                }
                break;

            case TypeAttributeHandling.All:
                typeAttribute = XConvertUtil.CreateTypeAttribute(actualType, assemblyNameStyle);
                break;
            }
            return(typeAttribute);
        }
コード例 #3
0
 protected override void PopulateElementAttributes(
     XElement element, Type declareType, object obj, XConvertSettings settings)
 {
     element.Add(XConvertUtil.CreateTypeAttribute(declareType, settings.AssemblyNameStyle));
 }