本文整理汇总了C#中System.Xml.Serialization.XmlTypeMapMemberElement类的典型用法代码示例。如果您正苦于以下问题:C# XmlTypeMapMemberElement类的具体用法?C# XmlTypeMapMemberElement怎么用?C# XmlTypeMapMemberElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlTypeMapMemberElement类属于System.Xml.Serialization命名空间,在下文中一共展示了XmlTypeMapMemberElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateArrayElement
protected override void GenerateArrayElement (CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, string defaultNamespace, bool forceUseMemberName)
{
XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo) member.ElementInfo[0];
CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlArray");
if (forceUseMemberName || (einfo.ElementName != member.Name)) att.Arguments.Add (GetArg ("ElementName", einfo.ElementName));
if (einfo.Namespace != defaultNamespace) att.Arguments.Add (GetArg ("Namespace", einfo.Namespace));
if (einfo.Form == XmlSchemaForm.Unqualified) att.Arguments.Add (MapCodeGenerator.GetEnumArg ("Form", "System.Xml.Schema.XmlSchemaForm", einfo.Form.ToString()));
if (einfo.IsNullable) att.Arguments.Add (GetArg ("IsNullable", true));
if (att.Arguments.Count > 0) attributes.Add (att);
}
示例2: ImportElementInfo
XmlTypeMapElementInfoList ImportElementInfo (string defaultName, string defaultNamespace, Type defaultType, XmlTypeMapMemberElement member, XmlAttributes atts)
{
XmlTypeMapElementInfoList list = new XmlTypeMapElementInfoList();
ImportTextElementInfo (list, defaultType, member, atts);
if (atts.XmlElements.Count == 0 && list.Count == 0)
{
XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(defaultType));
elem.ElementName = defaultName;
elem.Namespace = defaultNamespace;
if (elem.TypeData.IsComplexType)
elem.MappedType = ImportTypeMapping (defaultType, null, defaultNamespace);
list.Add (elem);
}
bool multiType = (atts.XmlElements.Count > 1);
foreach (XmlElementAttribute att in atts.XmlElements)
{
Type elemType = (att.Type != null) ? att.Type : defaultType;
XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(elemType, att.DataType));
elem.ElementName = (att.ElementName != null) ? att.ElementName : defaultName;
elem.Namespace = (att.Namespace != null) ? att.Namespace : defaultNamespace;
elem.Form = att.Form;
elem.IsNullable = att.IsNullable;
if (elem.IsNullable && elem.TypeData.IsValueType)
throw new InvalidOperationException ("IsNullable may not be 'true' for value type " + elem.TypeData.FullTypeName + " in member '" + defaultName + "'");
if (elem.TypeData.IsComplexType)
{
if (att.DataType != null) throw new InvalidOperationException ("'" + att.DataType + "' is an invalid value for the XmlElementAttribute.DateTime property. The property may only be specified for primitive types.");
elem.MappedType = ImportTypeMapping (elemType, null, elem.Namespace);
}
if (att.ElementName != null)
elem.ElementName = att.ElementName;
else if (multiType) {
if (elem.MappedType != null) elem.ElementName = elem.MappedType.ElementName;
else elem.ElementName = TypeTranslator.GetTypeData(elemType).XmlType;
}
else
elem.ElementName = defaultName;
list.Add (elem);
}
return list;
}
示例3: GenerateElementMember
protected override void GenerateElementMember (CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member)
{
if (member.ChoiceMember != null) {
CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Xml.Serialization.XmlChoiceIdentifier");
att.Arguments.Add (GetArg(member.ChoiceMember));
attributes.Add (att);
}
if (member.Ignore)
attributes.Add (new CodeAttributeDeclaration ("System.Xml.Serialization.XmlIgnoreAttribute"));
}
示例4: ImportTextElementInfo
void ImportTextElementInfo (XmlTypeMapElementInfoList list, Type defaultType, XmlTypeMapMemberElement member, XmlAttributes atts, string defaultNamespace)
{
if (atts.XmlText != null)
{
member.IsXmlTextCollector = true;
if (atts.XmlText.Type != null) {
TypeData td = TypeTranslator.GetTypeData (defaultType);
if ((td.SchemaType == SchemaTypes.Primitive || td.SchemaType == SchemaTypes.Enum) && atts.XmlText.Type != defaultType) {
throw new InvalidOperationException ("The type for XmlText may not be specified for primitive types.");
}
defaultType = atts.XmlText.Type;
}
#if !MOONLIGHT
if (defaultType == typeof(XmlNode)) defaultType = typeof(XmlText); // Nodes must be text nodes
#endif
XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(defaultType, atts.XmlText.DataType));
if (elem.TypeData.SchemaType != SchemaTypes.Primitive &&
elem.TypeData.SchemaType != SchemaTypes.Enum &&
elem.TypeData.SchemaType != SchemaTypes.XmlNode &&
!(elem.TypeData.SchemaType == SchemaTypes.Array && elem.TypeData.ListItemTypeData.SchemaType == SchemaTypes.XmlNode)
)
throw new InvalidOperationException ("XmlText cannot be used to encode complex types");
if (elem.TypeData.IsComplexType)
elem.MappedType = ImportTypeMapping (defaultType, null, defaultNamespace);
elem.IsTextElement = true;
elem.WrappedElement = false;
list.Add (elem);
}
}
示例5: ImportElementInfo
XmlTypeMapElementInfoList ImportElementInfo (Type cls, string defaultName, string defaultNamespace, Type defaultType, XmlTypeMapMemberElement member, XmlAttributes atts)
{
EnumMap choiceEnumMap = null;
Type choiceEnumType = null;
XmlTypeMapElementInfoList list = new XmlTypeMapElementInfoList();
ImportTextElementInfo (list, defaultType, member, atts, defaultNamespace);
if (atts.XmlChoiceIdentifier != null) {
if (cls == null)
throw new InvalidOperationException ("XmlChoiceIdentifierAttribute not supported in this context.");
member.ChoiceMember = atts.XmlChoiceIdentifier.MemberName;
MemberInfo[] mems = cls.GetMember (member.ChoiceMember, BindingFlags.Instance|BindingFlags.Public);
if (mems.Length == 0)
throw new InvalidOperationException ("Choice member '" + member.ChoiceMember + "' not found in class '" + cls);
if (mems[0] is PropertyInfo) {
PropertyInfo pi = (PropertyInfo)mems[0];
if (!pi.CanWrite || !pi.CanRead)
throw new InvalidOperationException ("Choice property '" + member.ChoiceMember + "' must be read/write.");
choiceEnumType = pi.PropertyType;
}
else choiceEnumType = ((FieldInfo)mems[0]).FieldType;
member.ChoiceTypeData = TypeTranslator.GetTypeData (choiceEnumType);
if (choiceEnumType.IsArray)
choiceEnumType = choiceEnumType.GetElementType ();
choiceEnumMap = ImportTypeMapping (choiceEnumType).ObjectMap as EnumMap;
if (choiceEnumMap == null)
throw new InvalidOperationException ("The member '" + mems[0].Name + "' is not a valid target for XmlChoiceIdentifierAttribute.");
}
if (atts.XmlElements.Count == 0 && list.Count == 0)
{
XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(defaultType));
elem.ElementName = defaultName;
elem.Namespace = defaultNamespace;
if (elem.TypeData.IsComplexType)
elem.MappedType = ImportTypeMapping (defaultType, null, defaultNamespace);
list.Add (elem);
}
bool multiType = (atts.XmlElements.Count > 1);
foreach (XmlElementAttribute att in atts.XmlElements)
{
Type elemType = (att.Type != null) ? att.Type : defaultType;
XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(elemType, att.DataType));
elem.Form = att.Form;
if (elem.Form != XmlSchemaForm.Unqualified)
elem.Namespace = (att.Namespace != null) ? att.Namespace : defaultNamespace;
elem.IsNullable = att.IsNullable;
if (elem.IsNullable && !elem.TypeData.IsNullable)
throw new InvalidOperationException ("IsNullable may not be 'true' for value type " + elem.TypeData.FullTypeName + " in member '" + defaultName + "'");
if (elem.TypeData.IsComplexType)
{
if (att.DataType.Length != 0) throw new InvalidOperationException (
string.Format(CultureInfo.InvariantCulture, "'{0}' is "
+ "an invalid value for '{1}.{2}' of type '{3}'. "
+ "The property may only be specified for primitive types.",
att.DataType, cls.FullName, defaultName,
elem.TypeData.FullTypeName));
elem.MappedType = ImportTypeMapping (elemType, null, elem.Namespace);
}
if (att.ElementName.Length != 0) {
elem.ElementName = XmlConvert.EncodeLocalName(att.ElementName);
} else if (multiType) {
if (elem.MappedType != null) {
elem.ElementName = elem.MappedType.ElementName;
} else {
elem.ElementName = TypeTranslator.GetTypeData (elemType).XmlType;
}
} else {
elem.ElementName = defaultName;
}
if (choiceEnumMap != null) {
string cname = choiceEnumMap.GetEnumName (choiceEnumType.FullName, elem.ElementName);
if (cname == null)
throw new InvalidOperationException (string.Format (
CultureInfo.InvariantCulture, "Type {0} is missing"
+ " enumeration value '{1}' for element '{1} from"
+ " namespace '{2}'.", choiceEnumType, elem.ElementName,
elem.Namespace));
elem.ChoiceValue = Enum.Parse (choiceEnumType, cname, false);
}
list.Add (elem);
}
return list;
}
示例6: ImportSimpleContent
void ImportSimpleContent (XmlQualifiedName typeQName, XmlTypeMapping map, XmlSchemaSimpleContent content, CodeIdentifiers classIds, bool isMixed)
{
XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
ClassMap cmap = (ClassMap)map.ObjectMap;
XmlQualifiedName qname = GetContentBaseType (content.Content);
TypeData simpleType = null;
if (!IsPrimitiveTypeNamespace (qname.Namespace))
{
// Add base map members to this map
XmlTypeMapping baseMap = ImportType (qname, null, true);
BuildPendingMap (baseMap);
if (baseMap.IsSimpleType) {
simpleType = baseMap.TypeData;
} else {
ClassMap baseClassMap = (ClassMap)baseMap.ObjectMap;
foreach (XmlTypeMapMember member in baseClassMap.AllMembers)
cmap.AddMember (member);
map.BaseMap = baseMap;
baseMap.DerivedTypes.Add (map);
}
}
else
simpleType = FindBuiltInType (qname);
if (simpleType != null) {
XmlTypeMapMemberElement member = new XmlTypeMapMemberElement ();
member.Name = classIds.AddUnique("Value", member);
member.TypeData = simpleType;
member.ElementInfo.Add (CreateTextElementInfo (typeQName.Namespace, member, member.TypeData));
member.IsXmlTextCollector = true;
cmap.AddMember (member);
}
if (ext != null)
ImportAttributes (typeQName, cmap, ext.Attributes, ext.AnyAttribute, classIds);
}
示例7: ImportSequenceContent
void ImportSequenceContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaObjectCollection items, CodeIdentifiers classIds, bool multiValue, ref bool isMixed)
{
foreach (XmlSchemaObject item in items)
{
if (item is XmlSchemaElement)
{
string ns;
XmlSchemaElement elem = (XmlSchemaElement) item;
XmlTypeMapping emap;
TypeData typeData = GetElementTypeData (typeQName, elem, null, out emap);
XmlSchemaElement refElem = GetRefElement (typeQName, elem, out ns);
if (elem.MaxOccurs == 1 && !multiValue)
{
XmlTypeMapMemberElement member = null;
if (typeData.SchemaType != SchemaTypes.Array)
{
member = new XmlTypeMapMemberElement ();
if (refElem.DefaultValue != null) member.DefaultValue = ImportDefaultValue (typeData, refElem.DefaultValue);
}
else if (GetTypeMapping (typeData).IsSimpleType)
{
// It is a simple list (space separated list).
// Since this is not supported, map as a single item value
member = new XmlTypeMapMemberElement ();
#if NET_2_0
// In MS.NET those types are mapped to a string
typeData = TypeTranslator.GetTypeData(typeof(string));
#else
typeData = typeData.ListItemTypeData;
#endif
}
else
member = new XmlTypeMapMemberList ();
if (elem.MinOccurs == 0 && typeData.IsValueType)
member.IsOptionalValueType = true;
member.Name = classIds.AddUnique(CodeIdentifier.MakeValid(refElem.Name), member);
member.Documentation = GetDocumentation (elem);
member.TypeData = typeData;
member.ElementInfo.Add (CreateElementInfo (ns, member, refElem.Name, typeData, refElem.IsNillable, refElem.Form, emap, items.IndexOf (item)));
cmap.AddMember (member);
}
else
{
XmlTypeMapMemberFlatList member = new XmlTypeMapMemberFlatList ();
member.ListMap = new ListMap ();
member.Name = classIds.AddUnique(CodeIdentifier.MakeValid(refElem.Name), member);
member.Documentation = GetDocumentation (elem);
member.TypeData = typeData.ListTypeData;
member.ElementInfo.Add (CreateElementInfo (ns, member, refElem.Name, typeData, refElem.IsNillable, refElem.Form, emap, items.IndexOf (item)));
member.ListMap.ItemInfo = member.ElementInfo;
cmap.AddMember (member);
}
}
else if (item is XmlSchemaAny)
{
XmlSchemaAny elem = (XmlSchemaAny) item;
XmlTypeMapMemberAnyElement member = new XmlTypeMapMemberAnyElement ();
member.Name = classIds.AddUnique ("Any", member);
member.Documentation = GetDocumentation (elem);
Type ctype;
if (elem.MaxOccurs != 1 || multiValue)
ctype = isMixed ? typeof(XmlNode[]) : typeof(XmlElement[]);
else
ctype = isMixed ? typeof(XmlNode) : typeof(XmlElement);
member.TypeData = TypeTranslator.GetTypeData (ctype);
XmlTypeMapElementInfo einfo = new XmlTypeMapElementInfo (member, member.TypeData);
einfo.IsUnnamedAnyElement = true;
member.ElementInfo.Add (einfo);
if (isMixed)
{
einfo = CreateTextElementInfo (typeQName.Namespace, member, member.TypeData);
member.ElementInfo.Add (einfo);
member.IsXmlTextCollector = true;
isMixed = false; //Allow only one XmlTextAttribute
}
cmap.AddMember (member);
}
else if (item is XmlSchemaParticle) {
ImportParticleContent (typeQName, cmap, (XmlSchemaParticle)item, classIds, multiValue, ref isMixed);
}
}
}
示例8: AddArrayAttributes
public void AddArrayAttributes (CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, string defaultNamespace, bool forceUseMemberName)
{
GenerateArrayElement (attributes, member, defaultNamespace, forceUseMemberName);
}
示例9: GenerateElementInfoMember
protected virtual void GenerateElementInfoMember (CodeAttributeDeclarationCollection attributes, XmlTypeMapMemberElement member, XmlTypeMapElementInfo einfo, TypeData defaultType, string defaultNamespace, bool addAlwaysAttr, bool forceUseMemberName)
{
}
示例10: AddElementMemberAttributes
public void AddElementMemberAttributes (XmlTypeMapMemberElement member, string defaultNamespace, CodeAttributeDeclarationCollection attributes, bool forceUseMemberName)
{
TypeData defaultType = member.TypeData;
bool addAlwaysAttr = false;
if (member is XmlTypeMapMemberFlatList)
{
defaultType = defaultType.ListItemTypeData;
addAlwaysAttr = true;
}
foreach (XmlTypeMapElementInfo einfo in member.ElementInfo)
{
if (ExportExtraElementAttributes (attributes, einfo, defaultNamespace, defaultType))
continue;
GenerateElementInfoMember (attributes, member, einfo, defaultType, defaultNamespace, addAlwaysAttr, forceUseMemberName);
if (einfo.MappedType != null) {
ExportMapCode (einfo.MappedType);
RemoveInclude (einfo.MappedType);
}
}
GenerateElementMember (attributes, member);
}
示例11: AddAnyElementFieldMember
void AddAnyElementFieldMember (CodeTypeDeclaration codeClass, XmlTypeMapMemberElement member, string defaultNamespace)
{
CodeMemberField codeField = CreateFieldMember (member);
codeClass.Members.Add (codeField);
CodeAttributeDeclarationCollection attributes = new CodeAttributeDeclarationCollection ();
foreach (XmlTypeMapElementInfo einfo in member.ElementInfo)
ExportExtraElementAttributes (attributes, einfo, defaultNamespace, einfo.TypeData);
if (attributes.Count > 0) codeField.CustomAttributes = attributes;
}
示例12: AddElementFieldMember
void AddElementFieldMember (CodeTypeDeclaration codeClass, XmlTypeMapMemberElement member, string defaultNamespace)
{
CodeMemberField codeField = CreateFieldMember (member);
codeClass.Members.Add (codeField);
CodeAttributeDeclarationCollection attributes = codeField.CustomAttributes;
if (attributes == null) attributes = new CodeAttributeDeclarationCollection ();
AddElementMemberAttributes (member, defaultNamespace, attributes, false);
if (attributes.Count > 0) codeField.CustomAttributes = attributes;
if (member.TypeData.IsValueType && member.IsOptionalValueType)
{
codeField = new CodeMemberField (typeof(bool), member.Name + "Specified");
codeField.Attributes = MemberAttributes.Public;
codeClass.Members.Add (codeField);
GenerateSpecifierMember (codeField);
}
}
示例13: ImportTextElementInfo
void ImportTextElementInfo (XmlTypeMapElementInfoList list, Type defaultType, XmlTypeMapMemberElement member, XmlAttributes atts)
{
if (atts.XmlText != null)
{
member.IsXmlTextCollector = true;
if (atts.XmlText.Type != null) defaultType = atts.XmlText.Type;
if (defaultType == typeof(XmlNode)) defaultType = typeof(XmlText); // Nodes must be text nodes
XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(defaultType, atts.XmlText.DataType));
if (elem.TypeData.SchemaType != SchemaTypes.Primitive &&
elem.TypeData.SchemaType != SchemaTypes.Enum &&
elem.TypeData.SchemaType != SchemaTypes.XmlNode &&
!(elem.TypeData.SchemaType == SchemaTypes.Array && elem.TypeData.ListItemTypeData.SchemaType == SchemaTypes.XmlNode)
)
throw new InvalidOperationException ("XmlText cannot be used to encode complex types");
elem.IsTextElement = true;
elem.WrappedElement = false;
list.Add (elem);
}
}
示例14: ImportAnyElementInfo
XmlTypeMapElementInfoList ImportAnyElementInfo (string defaultNamespace, XmlReflectionMember rmember, XmlTypeMapMemberElement member, XmlAttributes atts)
{
XmlTypeMapElementInfoList list = new XmlTypeMapElementInfoList();
ImportTextElementInfo (list, rmember.MemberType, member, atts);
foreach (XmlAnyElementAttribute att in atts.XmlAnyElements)
{
XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (member, TypeTranslator.GetTypeData(typeof(XmlElement)));
if (att.Name != null && att.Name != string.Empty)
{
elem.ElementName = att.Name;
elem.Namespace = (att.Namespace != null) ? att.Namespace : "";
}
else
{
elem.IsUnnamedAnyElement = true;
elem.Namespace = defaultNamespace;
if (att.Namespace != null)
throw new InvalidOperationException ("The element " + rmember.MemberName + " has been attributed with an XmlAnyElementAttribute and a namespace '" + att.Namespace + "', but no name. When a namespace is supplied, a name is also required. Supply a name or remove the namespace.");
}
list.Add (elem);
}
return list;
}
示例15: CreateMapMember
private XmlTypeMapMember CreateMapMember (XmlReflectionMember rmember, string defaultNamespace)
{
XmlTypeMapMember mapMember;
SoapAttributes atts = rmember.SoapAttributes;
TypeData typeData = TypeTranslator.GetTypeData (rmember.MemberType);
if (atts.SoapAttribute != null)
{
// An attribute
if (typeData.SchemaType != SchemaTypes.Enum && typeData.SchemaType != SchemaTypes.Primitive) {
throw new InvalidOperationException (string.Format (CultureInfo.InvariantCulture,
"Cannot serialize member '{0}' of type {1}. " +
"SoapAttribute cannot be used to encode complex types.",
rmember.MemberName, typeData.FullTypeName));
}
if (atts.SoapElement != null)
throw new Exception ("SoapAttributeAttribute and SoapElementAttribute cannot be applied to the same member");
XmlTypeMapMemberAttribute mapAttribute = new XmlTypeMapMemberAttribute ();
if (atts.SoapAttribute.AttributeName.Length == 0)
mapAttribute.AttributeName = XmlConvert.EncodeLocalName (rmember.MemberName);
else
mapAttribute.AttributeName = XmlConvert.EncodeLocalName (atts.SoapAttribute.AttributeName);
mapAttribute.Namespace = (atts.SoapAttribute.Namespace != null) ? atts.SoapAttribute.Namespace : "";
if (typeData.IsComplexType)
mapAttribute.MappedType = ImportTypeMapping (typeData.Type, defaultNamespace);
typeData = TypeTranslator.GetTypeData (rmember.MemberType, atts.SoapAttribute.DataType);
mapMember = mapAttribute;
mapMember.DefaultValue = GetDefaultValue (typeData, atts.SoapDefaultValue);
}
else
{
if (typeData.SchemaType == SchemaTypes.Array) mapMember = new XmlTypeMapMemberList ();
else mapMember = new XmlTypeMapMemberElement ();
if (atts.SoapElement != null && atts.SoapElement.DataType.Length != 0)
typeData = TypeTranslator.GetTypeData (rmember.MemberType, atts.SoapElement.DataType);
// Creates an ElementInfo that identifies the element
XmlTypeMapElementInfoList infoList = new XmlTypeMapElementInfoList();
XmlTypeMapElementInfo elem = new XmlTypeMapElementInfo (mapMember, typeData);
elem.ElementName = XmlConvert.EncodeLocalName ((atts.SoapElement != null && atts.SoapElement.ElementName.Length != 0) ? atts.SoapElement.ElementName : rmember.MemberName);
elem.Namespace = string.Empty;
elem.IsNullable = (atts.SoapElement != null) ? atts.SoapElement.IsNullable : false;
if (typeData.IsComplexType)
elem.MappedType = ImportTypeMapping (typeData.Type, defaultNamespace);
infoList.Add (elem);
((XmlTypeMapMemberElement)mapMember).ElementInfo = infoList;
}
mapMember.TypeData = typeData;
mapMember.Name = rmember.MemberName;
mapMember.IsReturnValue = rmember.IsReturnValue;
return mapMember;
}