本文整理汇总了C#中System.Xml.Serialization.XmlReflectionMember类的典型用法代码示例。如果您正苦于以下问题:C# XmlReflectionMember类的具体用法?C# XmlReflectionMember怎么用?C# XmlReflectionMember使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlReflectionMember类属于System.Xml.Serialization命名空间,在下文中一共展示了XmlReflectionMember类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportMembersMapping
public XmlMembersMapping ImportMembersMapping(string mappingName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool rpc)
{
Array membersObjects = _wrapperObject.InitializeArray(XmlMappingTypesHelper.XmlReflectionMemberType, members);
object[] parameters = new object[] { mappingName, ns, membersObjects, hasWrapperElement, rpc };
object o = _wrapperObject.CallMethod(s_importMembersMapping, parameters);
return new XmlMembersMapping(o);
}
示例2: CreateReflectionMember
private XmlReflectionMember CreateReflectionMember (MessagePartDescription partDesc, bool isReturnValue)
{
XmlReflectionMember m = new XmlReflectionMember ();
m.IsReturnValue = isReturnValue;
m.MemberName = partDesc.Name;
m.MemberType = partDesc.Type;
return m;
}
示例3: MembersMap
private XmlMembersMapping MembersMap (Type t, SoapAttributeOverrides overrides,
XmlReflectionMember [] members, bool inContainer, bool writeAccessors)
{
SoapReflectionImporter ri = new SoapReflectionImporter (overrides);
XmlMembersMapping mm = ri.ImportMembersMapping (null, null, members,
inContainer, writeAccessors);
return mm;
}
示例4: CreateReflectionMember
private XmlReflectionMember CreateReflectionMember (MessagePartDescription partDesc, bool isReturnValue)
{
XmlReflectionMember m = new XmlReflectionMember ();
m.IsReturnValue = isReturnValue;
m.MemberName = partDesc.Name;
m.MemberType = partDesc.Type;
m.XmlAttributes = partDesc.MemberInfo == null ? new XmlAttributes () : new XmlAttributes (partDesc.MemberInfo);
return m;
}
示例5: ImportMembersMapping
public XmlMembersMapping ImportMembersMapping (string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate)
{
XmlMemberMapping[] mapping = new XmlMemberMapping[members.Length];
for (int n=0; n<members.Length; n++)
{
XmlTypeMapMember mapMem = CreateMapMember (members[n], ns);
mapping[n] = new XmlMemberMapping (members[n].MemberName, ns, mapMem, true);
}
XmlMembersMapping mps = new XmlMembersMapping (elementName, ns, hasWrapperElement, writeAccessors, mapping);
mps.RelatedMaps = relatedMaps;
mps.Format = SerializationFormat.Encoded;
mps.Source = new MembersSerializationSource (elementName, hasWrapperElement, members, writeAccessors, false, null, includedTypes);
return mps;
}
示例6: ExportXmlSerializable_NestedClassMapping
public void ExportXmlSerializable_NestedClassMapping () {
XmlSchemas schemas = new XmlSchemas ();
XmlReflectionMember xmlReflectionMember = new XmlReflectionMember ();
XmlSchemaExporter xmlSchemaExporter = new XmlSchemaExporter (schemas);
XmlReflectionImporter xmlReflectionImporter = new XmlReflectionImporter ();
//Export mapping for DataSet1 class.
xmlReflectionMember.MemberType = typeof (DataSet1);
XmlMembersMapping xmlMembersMapping = xmlReflectionImporter.ImportMembersMapping ("DataSet1Response", "ResponseNamespace",
new XmlReflectionMember [] { xmlReflectionMember }, true);
xmlSchemaExporter.ExportMembersMapping (xmlMembersMapping);
//Export mapping for nested of DataSet1 class.
xmlReflectionMember.MemberType = typeof (DataSet1.DataTable1DataTable);
xmlMembersMapping = xmlReflectionImporter.ImportMembersMapping ("DataTable1DataTableResponse", "ResponseNamespace",
new XmlReflectionMember [] { xmlReflectionMember }, true);
xmlSchemaExporter.ExportMembersMapping (xmlMembersMapping);
}
示例7: ImportMembersMapping
MembersMapping ImportMembersMapping(XmlReflectionMember[] xmlReflectionMembers, string ns, bool hasWrapperElement, bool writeAccessors, bool validateWrapperElement) {
MembersMapping members = new MembersMapping();
members.TypeDesc = typeScope.GetTypeDesc(typeof(object[]));
MemberMapping[] mappings = new MemberMapping[xmlReflectionMembers.Length];
for (int i = 0; i < mappings.Length; i++) {
try {
XmlReflectionMember member = xmlReflectionMembers[i];
MemberMapping mapping = ImportMemberMapping(member, ns, xmlReflectionMembers, hasWrapperElement ? XmlSchemaForm.Unqualified : XmlSchemaForm.Qualified);
if (member.IsReturnValue && writeAccessors) { // no special treatment for return values with doc/enc
if (i > 0) throw new InvalidOperationException(Res.GetString(Res.XmlInvalidReturnPosition));
mapping.IsReturnValue = true;
}
mappings[i] = mapping;
}
catch (Exception e) {
if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
throw;
}
throw ReflectionException(xmlReflectionMembers[i].MemberName, e);
}
catch {
throw ReflectionException(xmlReflectionMembers[i].MemberName, null);
}
}
members.Members = mappings;
members.HasWrapperElement = hasWrapperElement;
if (hasWrapperElement) {
members.ValidateRpcWrapperElement = validateWrapperElement;
}
members.WriteAccessors = writeAccessors;
members.IsSoap = true;
if (hasWrapperElement && !writeAccessors)
members.Namespace = ns;
return members;
}
示例8: CreateMapMember
private XmlTypeMapMember CreateMapMember (Type declaringType, XmlReflectionMember rmember, string defaultNamespace)
{
XmlTypeMapMember mapMember;
XmlAttributes atts = rmember.XmlAttributes;
TypeData typeData = TypeTranslator.GetTypeData (rmember.MemberType);
if (atts.XmlArray != null) {
if (atts.XmlArray.Namespace != null && atts.XmlArray.Form == XmlSchemaForm.Unqualified)
throw new InvalidOperationException ("XmlArrayAttribute.Form must not be Unqualified when it has an explicit Namespace value.");
if (typeData.SchemaType != SchemaTypes.Array &&
!(typeData.SchemaType == SchemaTypes.Primitive && typeData.Type == typeof (byte [])))
throw new InvalidOperationException ("XmlArrayAttribute can be applied to members of array or collection type.");
}
#if !MOONLIGHT
if (atts.XmlAnyAttribute != null)
{
if ( (rmember.MemberType.FullName == "System.Xml.XmlAttribute[]") ||
(rmember.MemberType.FullName == "System.Xml.XmlNode[]") )
{
mapMember = new XmlTypeMapMemberAnyAttribute();
}
else
throw new InvalidOperationException ("XmlAnyAttributeAttribute can only be applied to members of type XmlAttribute[] or XmlNode[]");
}
else
#endif
if (atts.XmlAnyElements != null && atts.XmlAnyElements.Count > 0)
{
// no XmlNode type check is done here (seealso: bug #553032).
XmlTypeMapMemberAnyElement member = new XmlTypeMapMemberAnyElement();
member.ElementInfo = ImportAnyElementInfo (defaultNamespace, rmember, member, atts);
mapMember = member;
}
else if (atts.Xmlns)
{
XmlTypeMapMemberNamespaces mapNamespaces = new XmlTypeMapMemberNamespaces ();
mapMember = mapNamespaces;
}
else if (atts.XmlAttribute != null)
{
// An attribute
if (atts.XmlElements != null && atts.XmlElements.Count > 0)
throw new Exception ("XmlAttributeAttribute and XmlElementAttribute cannot be applied to the same member");
XmlTypeMapMemberAttribute mapAttribute = new XmlTypeMapMemberAttribute ();
if (atts.XmlAttribute.AttributeName.Length == 0)
mapAttribute.AttributeName = rmember.MemberName;
else
mapAttribute.AttributeName = atts.XmlAttribute.AttributeName;
mapAttribute.AttributeName = XmlConvert.EncodeLocalName (mapAttribute.AttributeName);
if (typeData.IsComplexType)
mapAttribute.MappedType = ImportTypeMapping (typeData.Type, null, defaultNamespace);
if (atts.XmlAttribute.Namespace != null && atts.XmlAttribute.Namespace != defaultNamespace)
{
if (atts.XmlAttribute.Form == XmlSchemaForm.Unqualified)
throw new InvalidOperationException ("The Form property may not be 'Unqualified' when an explicit Namespace property is present");
mapAttribute.Form = XmlSchemaForm.Qualified;
mapAttribute.Namespace = atts.XmlAttribute.Namespace;
}
else
{
mapAttribute.Form = atts.XmlAttribute.Form;
if (atts.XmlAttribute.Form == XmlSchemaForm.Qualified)
mapAttribute.Namespace = defaultNamespace;
else
mapAttribute.Namespace = "";
}
typeData = TypeTranslator.GetTypeData(rmember.MemberType, atts.XmlAttribute.DataType);
mapMember = mapAttribute;
}
else if (typeData.SchemaType == SchemaTypes.Array)
{
// If the member has a single XmlElementAttribute and the type is the type of the member,
// then it is not a flat list
if (atts.XmlElements.Count > 1 ||
(atts.XmlElements.Count == 1 && atts.XmlElements[0].Type != typeData.Type) ||
(atts.XmlText != null))
{
// A flat list
// check that it does not have XmlArrayAttribute
if (atts.XmlArray != null)
throw new InvalidOperationException ("XmlArrayAttribute cannot be used with members which also attributed with XmlElementAttribute or XmlTextAttribute.");
XmlTypeMapMemberFlatList member = new XmlTypeMapMemberFlatList ();
member.ListMap = new ListMap ();
member.ListMap.ItemInfo = ImportElementInfo (declaringType, XmlConvert.EncodeLocalName (rmember.MemberName), defaultNamespace, typeData.ListItemType, member, atts);
member.ElementInfo = member.ListMap.ItemInfo;
member.ListMap.ChoiceMember = member.ChoiceMember;
mapMember = member;
}
else
{
//.........这里部分代码省略.........
示例9: ImportMembersMapping
XmlMembersMapping ImportMembersMapping (string elementName,
string ns,
XmlReflectionMember[] members,
bool hasWrapperElement,
bool writeAccessors,
bool validate,
XmlMappingAccess access)
{
// Reset (); Disabled. See ChangeLog
ArrayList mapping = new ArrayList ();
for (int n=0; n<members.Length; n++)
{
if (members[n].XmlAttributes.XmlIgnore) continue;
XmlTypeMapMember mapMem = CreateMapMember (null, members[n], ns);
mapMem.GlobalIndex = n;
mapMem.CheckOptionalValueType (members);
mapping.Add (new XmlMemberMapping (members[n].MemberName, ns, mapMem, false));
}
elementName = XmlConvert.EncodeLocalName (elementName);
XmlMembersMapping mps = new XmlMembersMapping (elementName, ns, hasWrapperElement, false, (XmlMemberMapping[])mapping.ToArray (typeof(XmlMemberMapping)));
mps.RelatedMaps = relatedMaps;
mps.Format = SerializationFormat.Literal;
Type[] extraTypes = includedTypes != null ? (Type[])includedTypes.ToArray(typeof(Type)) : null;
#if !NET_2_1
mps.Source = new MembersSerializationSource (elementName, hasWrapperElement, members, false, true, ns, extraTypes);
if (allowPrivateTypes) mps.Source.CanBeGenerated = false;
#endif
return mps;
}
示例10: LoadBodyMapping
private XmlMembersMapping LoadBodyMapping(MessageDescription message, string mappingKey, out MessagePartDescriptionCollection rpcEncodedTypedMessageBodyParts)
{
MessagePartDescription returnPart;
string wrapperName, wrapperNs;
MessagePartDescriptionCollection bodyParts;
rpcEncodedTypedMessageBodyParts = null;
returnPart = OperationFormatter.IsValidReturnValue(message.Body.ReturnValue) ? message.Body.ReturnValue : null;
bodyParts = message.Body.Parts;
wrapperName = message.Body.WrapperName;
wrapperNs = message.Body.WrapperNamespace;
bool isWrapped = (wrapperName != null);
bool hasReturnValue = returnPart != null;
int paramCount = bodyParts.Count + (hasReturnValue ? 1 : 0);
if (paramCount == 0 && !isWrapped) // no need to create serializer
{
return null;
}
XmlReflectionMember[] members = new XmlReflectionMember[paramCount];
int paramIndex = 0;
if (hasReturnValue)
members[paramIndex++] = XmlSerializerHelper.GetXmlReflectionMember(returnPart, IsRpc, isWrapped);
for (int i = 0; i < bodyParts.Count; i++)
members[paramIndex++] = XmlSerializerHelper.GetXmlReflectionMember(bodyParts[i], IsRpc, isWrapped);
if (!isWrapped)
wrapperNs = ContractNamespace;
return ImportMembersMapping(wrapperName, wrapperNs, members, isWrapped, IsRpc, mappingKey);
}
示例11: GetSerializer
XmlSerializer GetSerializer (MessageBodyDescription desc)
{
if (bodySerializers.ContainsKey (desc))
return bodySerializers [desc];
int count = desc.Parts.Count + (HasReturnValue (desc) ? 1 : 0);
XmlReflectionMember [] members = new XmlReflectionMember [count];
int ind = 0;
if (HasReturnValue (desc))
members [ind++] = CreateReflectionMember (desc.ReturnValue, true);
foreach (MessagePartDescription partDesc in desc.Parts)
members [ind++] = CreateReflectionMember (partDesc, false);
XmlReflectionImporter xmlImporter = new XmlReflectionImporter ();
// Register known types into xmlImporter.
foreach (var type in OperationKnownTypes)
xmlImporter.IncludeType (type);
XmlMembersMapping [] partsMapping = new XmlMembersMapping [1];
partsMapping [0] = xmlImporter.ImportMembersMapping (desc.WrapperName, desc.WrapperNamespace, members, true);
bodySerializers [desc] = XmlSerializer.FromMappings (partsMapping) [0];
return bodySerializers [desc];
}
示例12: ImportMembersMapping
XmlMembersMapping ImportMembersMapping (string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate, XmlMappingAccess access)
{
elementName = XmlConvert.EncodeLocalName (elementName);
XmlMemberMapping[] mapping = new XmlMemberMapping[members.Length];
for (int n=0; n<members.Length; n++)
{
XmlTypeMapMember mapMem = CreateMapMember (members[n], ns);
mapping[n] = new XmlMemberMapping (XmlConvert.EncodeLocalName (members[n].MemberName), ns, mapMem, true);
}
XmlMembersMapping mps = new XmlMembersMapping (elementName, ns, hasWrapperElement, writeAccessors, mapping);
mps.RelatedMaps = relatedMaps;
mps.Format = SerializationFormat.Encoded;
Type[] extraTypes = includedTypes != null ? (Type[])includedTypes.ToArray(typeof(Type)) : null;
mps.Source = new MembersSerializationSource (elementName, hasWrapperElement, members, writeAccessors, false, null, extraTypes);
return mps;
}
示例13: BuildHeadersReflectionMembers
XmlReflectionMember [] BuildHeadersReflectionMembers (HeaderInfo[] headers)
{
XmlReflectionMember [] mems = new XmlReflectionMember [headers.Length];
for (int n=0; n<headers.Length; n++)
{
HeaderInfo header = headers [n];
XmlReflectionMember m = new XmlReflectionMember ();
m.IsReturnValue = false;
m.MemberName = header.HeaderType.Name;
m.MemberType = header.HeaderType;
// MS.NET reflects header classes in a weird way. The root element
// name is the CLR class name unless it is specified in an XmlRootAttribute.
// The usual is to use the xml type name by default, but not in this case.
XmlAttributes ats = new XmlAttributes (header.HeaderType);
if (ats.XmlRoot != null) {
XmlElementAttribute xe = new XmlElementAttribute ();
xe.ElementName = ats.XmlRoot.ElementName;
xe.Namespace = ats.XmlRoot.Namespace;
m.XmlAttributes = new XmlAttributes ();
m.XmlAttributes.XmlElements.Add (xe);
}
mems [n] = m;
}
return mems;
}
示例14: MembersSerializationSource
public MembersSerializationSource (string elementName, bool hasWrapperElement, XmlReflectionMember [] members, bool writeAccessors,
bool literalFormat, string namspace, ArrayList includedTypes)
: base (namspace, includedTypes)
{
this.elementName = elementName;
this.hasWrapperElement = hasWrapperElement;
this.writeAccessors = writeAccessors;
this.literalFormat = literalFormat;
StringBuilder sb = new StringBuilder ();
sb.Append (members.Length.ToString(CultureInfo.InvariantCulture));
foreach (XmlReflectionMember mem in members)
mem.AddKeyHash (sb);
membersHash = sb.ToString();
}
示例15: LoadHeadersMapping
private XmlMembersMapping LoadHeadersMapping(MessageDescription message, string mappingKey)
{
int headerCount = message.Headers.Count;
if (headerCount == 0)
return null;
int unknownHeaderCount = 0, headerIndex = 0;
XmlReflectionMember[] members = new XmlReflectionMember[headerCount];
for (int i = 0; i < headerCount; i++)
{
MessageHeaderDescription header = message.Headers[i];
if (!header.IsUnknownHeaderCollection)
{
members[headerIndex++] = XmlSerializerHelper.GetXmlReflectionMember(header, false/*isRpc*/, false/*isWrapped*/);
}
else
{
unknownHeaderCount++;
}
}
if (unknownHeaderCount == headerCount)
{
return null;
}
if (unknownHeaderCount > 0)
{
XmlReflectionMember[] newMembers = new XmlReflectionMember[headerCount - unknownHeaderCount];
Array.Copy(members, newMembers, newMembers.Length);
members = newMembers;
}
return ImportMembersMapping(ContractName, ContractNamespace, members, false /*isWrapped*/, false /*isRpc*/, mappingKey);
}