本文整理汇总了C#中System.Xml.Serialization.ClassMap.SetCanBeSimpleType方法的典型用法代码示例。如果您正苦于以下问题:C# ClassMap.SetCanBeSimpleType方法的具体用法?C# ClassMap.SetCanBeSimpleType怎么用?C# ClassMap.SetCanBeSimpleType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Serialization.ClassMap
的用法示例。
在下文中一共展示了ClassMap.SetCanBeSimpleType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportClassMapping
XmlTypeMapping ImportClassMapping (TypeData typeData, XmlRootAttribute root, string defaultNamespace)
{
Type type = typeData.Type;
XmlTypeMapping map = helper.GetRegisteredClrType (type, GetTypeNamespace (typeData, root, defaultNamespace));
if (map != null) return map;
if (!allowPrivateTypes)
ReflectionHelper.CheckSerializableType (type, false);
map = CreateTypeMapping (typeData, root, null, defaultNamespace);
helper.RegisterClrType (map, type, map.XmlTypeNamespace);
helper.RegisterSchemaType (map, map.XmlType, map.XmlTypeNamespace);
// Import members
ClassMap classMap = new ClassMap ();
map.ObjectMap = classMap;
ICollection members = GetReflectionMembers (type);
foreach (XmlReflectionMember rmember in members)
{
string ns = map.XmlTypeNamespace;
if (rmember.XmlAttributes.XmlIgnore) continue;
if (rmember.DeclaringType != null && rmember.DeclaringType != type) {
XmlTypeMapping bmap = ImportClassMapping (rmember.DeclaringType, root, defaultNamespace);
ns = bmap.XmlTypeNamespace;
}
try {
XmlTypeMapMember mem = CreateMapMember (type, rmember, ns);
mem.CheckOptionalValueType (type);
classMap.AddMember (mem);
} catch (Exception ex) {
throw new InvalidOperationException (string.Format (
CultureInfo.InvariantCulture, "There was an error" +
" reflecting field '{0}'.", rmember.MemberName), ex);
}
}
// Import extra classes
if (type == typeof (object) && includedTypes != null)
{
foreach (Type intype in includedTypes)
map.DerivedTypes.Add (ImportTypeMapping (intype, defaultNamespace));
}
// Register inheritance relations
if (type.BaseType != null)
{
XmlTypeMapping bmap = ImportClassMapping (type.BaseType, root, defaultNamespace);
ClassMap cbmap = bmap.ObjectMap as ClassMap;
if (type.BaseType != typeof (object)) {
map.BaseMap = bmap;
if (!cbmap.HasSimpleContent)
classMap.SetCanBeSimpleType (false);
}
// At this point, derived classes of this map must be already registered
RegisterDerivedMap (bmap, map);
if (cbmap.HasSimpleContent && classMap.ElementMembers != null && classMap.ElementMembers.Count != 1)
throw new InvalidOperationException (String.Format (errSimple, map.TypeData.TypeName, map.BaseMap.TypeData.TypeName));
}
ImportIncludedTypes (type, defaultNamespace);
if (classMap.XmlTextCollector != null && !classMap.HasSimpleContent)
{
XmlTypeMapMember mem = classMap.XmlTextCollector;
if (mem.TypeData.Type != typeof(string) &&
mem.TypeData.Type != typeof(string[]) &&
#if !MOONLIGHT
mem.TypeData.Type != typeof(XmlNode[]) &&
#endif
mem.TypeData.Type != typeof(object[]))
throw new InvalidOperationException (String.Format (errSimple2, map.TypeData.TypeName, mem.Name, mem.TypeData.TypeName));
}
return map;
}
示例2: ImportClassMapping
XmlTypeMapping ImportClassMapping (Type type, XmlRootAttribute root, string defaultNamespace)
{
TypeData typeData = TypeTranslator.GetTypeData (type);
XmlTypeMapping map = helper.GetRegisteredClrType (type, GetTypeNamespace (typeData, root, defaultNamespace));
if (map != null) return map;
if (!allowPrivateTypes)
ReflectionHelper.CheckSerializableType (type);
map = CreateTypeMapping (typeData, root, null, defaultNamespace);
helper.RegisterClrType (map, type, map.XmlTypeNamespace);
helper.RegisterSchemaType (map, map.XmlType, map.XmlTypeNamespace);
// Import members
ClassMap classMap = new ClassMap ();
map.ObjectMap = classMap;
// try
// {
ICollection members = GetReflectionMembers (type);
foreach (XmlReflectionMember rmember in members)
{
if (rmember.XmlAttributes.XmlIgnore) continue;
XmlTypeMapMember mem = CreateMapMember (rmember, map.XmlTypeNamespace);
mem.CheckOptionalValueType (type);
classMap.AddMember (mem);
}
// }
// catch (Exception ex) {
// throw helper.CreateError (map, ex.Message);
// }
ImportIncludedTypes (type, defaultNamespace);
// Import extra classes
if (type == typeof (object) && includedTypes != null)
{
foreach (Type intype in includedTypes)
map.DerivedTypes.Add (ImportTypeMapping (intype, defaultNamespace));
}
// Register inheritance relations
if (type.BaseType != null)
{
XmlTypeMapping bmap = ImportClassMapping (type.BaseType, root, defaultNamespace);
if (type.BaseType != typeof (object)) {
map.BaseMap = bmap;
classMap.SetCanBeSimpleType (false);
}
// At this point, derived classes of this map must be already registered
RegisterDerivedMap (bmap, map);
if (((ClassMap)bmap.ObjectMap).HasSimpleContent && classMap.ElementMembers != null && classMap.ElementMembers.Count != 1)
throw new InvalidOperationException (String.Format (errSimple, map.TypeData.TypeName, map.BaseMap.TypeData.TypeName));
}
if (classMap.XmlTextCollector != null && !classMap.HasSimpleContent)
{
XmlTypeMapMember mem = classMap.XmlTextCollector;
if (mem.TypeData.Type != typeof(string) &&
mem.TypeData.Type != typeof(string[]) &&
mem.TypeData.Type != typeof(object[]) &&
mem.TypeData.Type != typeof(XmlNode[]))
throw new InvalidOperationException (String.Format (errSimple2, map.TypeData.TypeName, mem.Name, mem.TypeData.TypeName));
}
return map;
}