本文整理汇总了C#中System.Xml.Serialization.XmlMembersMapping类的典型用法代码示例。如果您正苦于以下问题:C# XmlMembersMapping类的具体用法?C# XmlMembersMapping怎么用?C# XmlMembersMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlMembersMapping类属于System.Xml.Serialization命名空间,在下文中一共展示了XmlMembersMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateEncodedMessage
private void CreateEncodedMessage(Message message, MessageBinding messageBinding, XmlMembersMapping members, bool wrapped)
{
this.SoapExporter.ExportMembersMapping(members, wrapped);
if (wrapped)
{
MessagePart messagePart = new MessagePart {
Name = "parameters",
Type = new XmlQualifiedName(members.TypeName, members.TypeNamespace)
};
message.Parts.Add(messagePart);
}
else
{
for (int i = 0; i < members.Count; i++)
{
XmlMemberMapping mapping = members[i];
MessagePart part2 = new MessagePart {
Name = mapping.XsdElementName,
Type = new XmlQualifiedName(mapping.TypeName, mapping.TypeNamespace)
};
message.Parts.Add(part2);
}
}
messageBinding.Extensions.Add(this.CreateSoapBodyBinding(SoapBindingUse.Encoded, members.Namespace));
}
示例2: ExportMembersMapping
/// <include file='doc\XmlSchemaExporter.uex' path='docs/doc[@for="XmlSchemaExporter.ExportMembersMapping1"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping, bool exportEnclosingType) {
xmlMembersMapping.CheckShallow();
MembersMapping mapping = (MembersMapping)xmlMembersMapping.Accessor.Mapping;
CheckScope(xmlMembersMapping.Scope);
if (mapping.HasWrapperElement && exportEnclosingType) {
ExportElement(xmlMembersMapping.Accessor);
}
else {
foreach (MemberMapping member in mapping.Members) {
if (member.Attribute != null)
throw new InvalidOperationException(Res.GetString(Res.XmlBareAttributeMember, member.Attribute.Name));
else if (member.Text != null)
throw new InvalidOperationException(Res.GetString(Res.XmlBareTextMember, member.Text.Name));
else if (member.Elements == null || member.Elements.Length == 0)
continue;
if (member.TypeDesc.IsArrayLike && !(member.Elements[0].Mapping is ArrayMapping))
throw new InvalidOperationException(Res.GetString(Res.XmlIllegalArrayElement, member.Elements[0].Name));
if (exportEnclosingType) {
ExportElement(member.Elements[0]);
}
else {
ExportMapping(member.Elements[0].Mapping, member.Elements[0].Namespace, member.Elements[0].Any);
}
}
}
ExportRootIfNecessary(xmlMembersMapping.Scope);
}
示例3: ExportMembersMapping
/// <include file='doc\SoapCodeExporter.uex' path='docs/doc[@for="SoapCodeExporter.ExportMembersMapping"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping) {
CheckScope(xmlMembersMapping.Scope);
CheckNamespace();
for (int i = 0; i < xmlMembersMapping.Count; i++) {
ExportElement((ElementAccessor)xmlMembersMapping[i].Accessor);
}
}
示例4: ExportMembersMapping
/// <include file='doc\XmlCodeExporter.uex' path='docs/doc[@for="XmlCodeExporter.ExportMembersMapping"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping)
{
xmlMembersMapping.CheckShallow();
CheckScope(xmlMembersMapping.Scope);
for (int i = 0; i < xmlMembersMapping.Count; i++)
{
AccessorMapping mapping = xmlMembersMapping[i].Mapping;
if (mapping.Xmlns == null)
{
if (mapping.Attribute != null)
{
ExportType(mapping.Attribute.Mapping, Accessor.UnescapeName(mapping.Attribute.Name), mapping.Attribute.Namespace, null, false);
}
if (mapping.Elements != null)
{
for (int j = 0; j < mapping.Elements.Length; j++)
{
ElementAccessor element = mapping.Elements[j];
ExportType(element.Mapping, Accessor.UnescapeName(element.Name), element.Namespace, null, false);
}
}
if (mapping.Text != null)
{
ExportType(mapping.Text.Mapping, Accessor.UnescapeName(mapping.Text.Name), mapping.Text.Namespace, null, false);
}
}
}
}
示例5: Add
internal void Add(MessagePartDescription part, XmlMemberMapping memberMapping, XmlMembersMapping membersMapping, bool isEncoded)
{
PartInfo partInfo = new PartInfo();
partInfo.MemberMapping = memberMapping;
partInfo.MembersMapping = membersMapping;
partInfo.IsEncoded = isEncoded;
partInfoTable[part] = partInfo;
}
示例6: SoapParameters
internal SoapParameters(XmlMembersMapping request, XmlMembersMapping response, string[] parameterOrder, CodeIdentifiers identifiers) {
ArrayList requestList = new ArrayList();
ArrayList responseList = new ArrayList();
AddMappings(requestList, request);
if (response != null) AddMappings(responseList, response);
if (parameterOrder != null) {
for (int i = 0; i < parameterOrder.Length; i++) {
string elementName = parameterOrder[i];
XmlMemberMapping requestMapping = FindMapping(requestList, elementName);
SoapParameter parameter = new SoapParameter();
if (requestMapping != null) {
if (RemoveByRefMapping(responseList, requestMapping))
parameter.codeFlags = CodeFlags.IsByRef;
parameter.mapping = requestMapping;
requestList.Remove(requestMapping);
AddParameter(parameter);
}
else {
XmlMemberMapping responseMapping = FindMapping(responseList, elementName);
if (responseMapping != null) {
parameter.codeFlags = CodeFlags.IsOut;
parameter.mapping = responseMapping;
responseList.Remove(responseMapping);
AddParameter(parameter);
}
}
}
}
foreach (XmlMemberMapping requestMapping in requestList) {
SoapParameter parameter = new SoapParameter();
if (RemoveByRefMapping(responseList, requestMapping))
parameter.codeFlags = CodeFlags.IsByRef;
parameter.mapping = requestMapping;
AddParameter(parameter);
}
if (responseList.Count > 0) {
if (!((XmlMemberMapping) responseList[0]).CheckSpecified) {
ret = (XmlMemberMapping)responseList[0];
responseList.RemoveAt(0);
}
foreach (XmlMemberMapping responseMapping in responseList) {
SoapParameter parameter = new SoapParameter();
parameter.mapping = responseMapping;
parameter.codeFlags = CodeFlags.IsOut;
AddParameter(parameter);
}
}
foreach (SoapParameter parameter in parameters) {
parameter.name = identifiers.MakeUnique(CodeIdentifier.MakeValid(parameter.mapping.MemberName));
}
}
示例7: ExportMembersMapping
/// <include file='doc\XmlCodeExporter.uex' path='docs/doc[@for="XmlCodeExporter.ExportMembersMapping"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping) {
CheckScope(xmlMembersMapping.Scope);
CheckNamespace();
for (int i = 0; i < xmlMembersMapping.Count; i++) {
Accessor accessor = xmlMembersMapping[i].Accessor;
if (!(accessor is XmlnsAccessor)) {
ExportType(accessor.Mapping, Accessor.UnescapeName(accessor.Name), accessor.Namespace, null);
}
}
}
示例8: ExportMembersMapping
/// <include file='doc\SoapSchemaExporter.uex' path='docs/doc[@for="SoapSchemaExporter.ExportMembersMapping1"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void ExportMembersMapping(XmlMembersMapping xmlMembersMapping, bool exportEnclosingType) {
CheckScope(xmlMembersMapping.Scope);
MembersMapping membersMapping = (MembersMapping)xmlMembersMapping.Accessor.Mapping;
if (exportEnclosingType) {
ExportTypeMapping(membersMapping, null);
}
else {
foreach (MemberMapping memberMapping in membersMapping.Members) {
if (memberMapping.Elements.Length > 0)
ExportTypeMapping(memberMapping.Elements[0].Mapping, null);
}
}
}
示例9: ExportTypeMapping
/// <include file='doc\XmlSchemaExporter.uex' path='docs/doc[@for="XmlSchemaExporter.ExportTypeMapping1"]/*' />
public XmlQualifiedName ExportTypeMapping(XmlMembersMapping xmlMembersMapping) {
xmlMembersMapping.CheckShallow();
CheckScope(xmlMembersMapping.Scope);
MembersMapping mapping = (MembersMapping)xmlMembersMapping.Accessor.Mapping;
if (mapping.Members.Length == 1 && mapping.Members[0].Elements[0].Mapping is SpecialMapping) {
SpecialMapping special = (SpecialMapping)mapping.Members[0].Elements[0].Mapping;
XmlSchemaType type = ExportSpecialMapping(special, xmlMembersMapping.Accessor.Namespace, false, null);
if (type != null && type.Name != null && type.Name.Length > 0) {
type.Name = xmlMembersMapping.Accessor.Name;
AddSchemaItem(type, xmlMembersMapping.Accessor.Namespace, null);
}
ExportRootIfNecessary(xmlMembersMapping.Scope);
return (new XmlQualifiedName(xmlMembersMapping.Accessor.Name, xmlMembersMapping.Accessor.Namespace));
}
return null;
}
示例10: ImportMembersMapping
/// <include file='doc\SoapReflectionImporter.uex' path='docs/doc[@for="SoapReflectionImporter.ImportMembersMapping3"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] members, bool hasWrapperElement, bool writeAccessors, bool validate, XmlMappingAccess access) {
ElementAccessor element = new ElementAccessor();
element.IsSoap = true;
element.Name = elementName == null || elementName.Length == 0 ? elementName : XmlConvert.EncodeLocalName(elementName);
element.Mapping = ImportMembersMapping(members, ns, hasWrapperElement, writeAccessors, validate);
element.Mapping.TypeName = elementName;
element.Namespace = element.Mapping.Namespace == null ? ns : element.Mapping.Namespace;
element.Form = XmlSchemaForm.Qualified;
XmlMembersMapping xmlMapping = new XmlMembersMapping(typeScope, element, access);
xmlMapping.IsSoap = true;
xmlMapping.GenerateSerializer = true;
return xmlMapping;
}
示例11: GenerateEncodedMembersElement
string GenerateEncodedMembersElement(XmlMembersMapping xmlMembersMapping) {
ElementAccessor element = xmlMembersMapping.Accessor;
MembersMapping membersMapping = (MembersMapping)element.Mapping;
MemberMapping[] mappings = membersMapping.Members;
bool hasWrapperElement = membersMapping.HasWrapperElement;
bool writeAccessors = membersMapping.WriteAccessors;
string methodName = NextMethodName(element.Name);
Writer.WriteLine();
Writer.Write("public object[] ");
Writer.Write(methodName);
Writer.WriteLine("() {");
Writer.Indent++;
Writer.WriteLine("Reader.MoveToContent();");
Writer.Write("object[] p = new object[");
Writer.Write(mappings.Length.ToString(CultureInfo.InvariantCulture));
Writer.WriteLine("];");
InitializeValueTypes("p", mappings);
if (hasWrapperElement) {
WriteReadNonRoots();
if (membersMapping.ValidateRpcWrapperElement) {
Writer.Write("if (!");
WriteXmlNodeEqual("Reader", element.Name, element.Form == XmlSchemaForm.Qualified ? element.Namespace : "");
Writer.WriteLine(") throw CreateUnknownNodeException();");
}
Writer.WriteLine("bool isEmptyWrapper = Reader.IsEmptyElement;");
Writer.WriteLine("Reader.ReadStartElement();");
}
Member[] members = new Member[mappings.Length];
for (int i = 0; i < mappings.Length; i++) {
MemberMapping mapping = mappings[i];
string source = "p[" + i.ToString(CultureInfo.InvariantCulture) + "]";
string arraySource = source;
if (mapping.Xmlns != null) {
arraySource = "((" + mapping.TypeDesc.CSharpName + ")" + source + ")";
}
Member member = new Member(this,source, arraySource, "a", i, mapping);
if (!mapping.IsSequence)
member.ParamsReadSource = "paramsRead[" + i.ToString(CultureInfo.InvariantCulture) + "]";
members[i] = member;
if (mapping.CheckSpecified == SpecifiedAccessor.ReadWrite) {
string nameSpecified = mapping.Name + "Specified";
for (int j = 0; j < mappings.Length; j++) {
if (mappings[j].Name == nameSpecified) {
member.CheckSpecifiedSource = "p[" + j.ToString(CultureInfo.InvariantCulture) + "]";
break;
}
}
}
}
string fixupMethodName = "fixup_" + methodName;
bool anyFixups = WriteMemberFixupBegin(members, fixupMethodName, "p");
if (members.Length > 0 && members[0].Mapping.IsReturnValue) Writer.WriteLine("IsReturnValue = true;");
string checkTypeHrefSource = (!hasWrapperElement && !writeAccessors) ? "hrefList" : null;
if (checkTypeHrefSource != null)
WriteInitCheckTypeHrefList(checkTypeHrefSource);
WriteParamsRead(mappings.Length);
int loopIndex = WriteWhileNotLoopStart();
Writer.Indent++;
string unrecognizedElementSource = checkTypeHrefSource == null ? "UnknownNode((object)p);" : "if (Reader.GetAttribute(\"id\", null) != null) { ReadReferencedElement(); } else { UnknownNode((object)p); }";
WriteMemberElements(members, unrecognizedElementSource, "UnknownNode((object)p);", null, null, checkTypeHrefSource);
Writer.WriteLine("Reader.MoveToContent();");
WriteWhileLoopEnd(loopIndex);
if (hasWrapperElement)
Writer.WriteLine("if (!isEmptyWrapper) ReadEndElement();");
if (checkTypeHrefSource != null)
WriteHandleHrefList(members, checkTypeHrefSource);
Writer.WriteLine("ReadReferencedElements();");
Writer.WriteLine("return p;");
Writer.Indent--;
Writer.WriteLine("}");
if (anyFixups) WriteFixupMethod(fixupMethodName, members, "object[]", false, false, "p");
return methodName;
}
示例12: GenerateMembersElement
string GenerateMembersElement(XmlMembersMapping xmlMembersMapping) {
if (xmlMembersMapping.Accessor.IsSoap)
return GenerateEncodedMembersElement(xmlMembersMapping);
else
return GenerateLiteralMembersElement(xmlMembersMapping);
}
示例13: CreateLiteralMessage
void CreateLiteralMessage(Message message, MessageBinding messageBinding, XmlMembersMapping members, bool wrapped, bool rpc) {
if (members.Count == 1 && members[0].Any && members[0].ElementName.Length == 0 && !wrapped) {
string typeName = SchemaExporter.ExportAnyType(members[0].Namespace);
MessagePart part = new MessagePart();
part.Name = members[0].MemberName;
part.Type = new XmlQualifiedName(typeName, members[0].Namespace);
message.Parts.Add(part);
}
else {
SchemaExporter.ExportMembersMapping(members, !rpc);
if (wrapped) {
MessagePart part = new MessagePart();
part.Name = "parameters";
part.Element = new XmlQualifiedName(members.XsdElementName, members.Namespace);
message.Parts.Add(part);
}
else {
for (int i = 0; i < members.Count; i++) {
XmlMemberMapping member = members[i];
MessagePart part = new MessagePart();
if (rpc) {
// Generate massage part with the type attribute
if (member.TypeName == null || member.TypeName.Length == 0) {
throw new InvalidOperationException(Res.GetString(Res.WsdlGenRpcLitAnonimousType, Method.DeclaringType.Name, Method.Name, member.MemberName));
}
part.Name = member.XsdElementName;
part.Type = new XmlQualifiedName(member.TypeName, member.TypeNamespace);
}
else {
part.Name = XmlConvert.EncodeLocalName(member.MemberName);
part.Element = new XmlQualifiedName(member.XsdElementName, member.Namespace);
}
message.Parts.Add(part);
}
}
}
messageBinding.Extensions.Add(CreateSoapBodyBinding(SoapBindingUse.Literal, rpc ? members.Namespace : null));
}
示例14: GenerateMethod
CodeMemberMethod GenerateMethod (CodeIdentifiers memberIds, HttpOperationBinding httpOper, XmlMembersMapping inputMembers, XmlTypeMapping outputMember)
{
CodeIdentifiers pids = new CodeIdentifiers ();
CodeMemberMethod method = new CodeMemberMethod ();
CodeMemberMethod methodBegin = new CodeMemberMethod ();
CodeMemberMethod methodEnd = new CodeMemberMethod ();
method.Attributes = MemberAttributes.Public;
methodBegin.Attributes = MemberAttributes.Public;
methodEnd.Attributes = MemberAttributes.Public;
// Find unique names for temporary variables
for (int n=0; n<inputMembers.Count; n++)
pids.AddUnique (inputMembers[n].MemberName, inputMembers[n]);
string varAsyncResult = pids.AddUnique ("asyncResult","asyncResult");
string varCallback = pids.AddUnique ("callback","callback");
string varAsyncState = pids.AddUnique ("asyncState","asyncState");
string messageName = memberIds.AddUnique(CodeIdentifier.MakeValid(Operation.Name),method);
method.Name = Operation.Name;
methodBegin.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("Begin" + Operation.Name),method);
methodEnd.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("End" + Operation.Name),method);
method.ReturnType = new CodeTypeReference (typeof(void));
methodEnd.ReturnType = new CodeTypeReference (typeof(void));
methodEnd.Parameters.Add (new CodeParameterDeclarationExpression (typeof (IAsyncResult),varAsyncResult));
CodeExpression[] paramArray = new CodeExpression [inputMembers.Count];
for (int n=0; n<inputMembers.Count; n++)
{
string ptype = GetSimpleType (inputMembers[n]);
CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression (ptype, inputMembers[n].MemberName);
param.Direction = FieldDirection.In;
method.Parameters.Add (param);
methodBegin.Parameters.Add (param);
paramArray [n] = new CodeVariableReferenceExpression (param.Name);
}
bool isVoid = true;
if (outputMember != null)
{
method.ReturnType = new CodeTypeReference (outputMember.TypeFullName);
methodEnd.ReturnType = new CodeTypeReference (outputMember.TypeFullName);
xmlExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, outputMember, "");
isVoid = false;
}
methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (AsyncCallback),varCallback));
methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (object),varAsyncState));
methodBegin.ReturnType = new CodeTypeReference (typeof(IAsyncResult));
// Array of input parameters
CodeArrayCreateExpression methodParams;
if (paramArray.Length > 0)
methodParams = new CodeArrayCreateExpression (typeof(object), paramArray);
else
methodParams = new CodeArrayCreateExpression (typeof(object), 0);
// Generate method url
CodeThisReferenceExpression ethis = new CodeThisReferenceExpression();
CodeExpression thisURlExp = new CodeFieldReferenceExpression (ethis, "Url");
CodePrimitiveExpression metUrl = new CodePrimitiveExpression (httpOper.Location);
CodeBinaryOperatorExpression expMethodLocation = new CodeBinaryOperatorExpression (thisURlExp, CodeBinaryOperatorType.Add, metUrl);
// Invoke call
CodePrimitiveExpression varMsgName = new CodePrimitiveExpression (messageName);
CodeMethodInvokeExpression inv;
inv = new CodeMethodInvokeExpression (ethis, "Invoke", varMsgName, expMethodLocation, methodParams);
if (!isVoid)
method.Statements.Add (new CodeMethodReturnStatement (new CodeCastExpression (method.ReturnType, inv)));
else
method.Statements.Add (inv);
// Begin Invoke Call
CodeExpression expCallb = new CodeVariableReferenceExpression (varCallback);
CodeExpression expAsyncs = new CodeVariableReferenceExpression (varAsyncState);
inv = new CodeMethodInvokeExpression (ethis, "BeginInvoke", varMsgName, expMethodLocation, methodParams, expCallb, expAsyncs);
methodBegin.Statements.Add (new CodeMethodReturnStatement (inv));
// End Invoke call
CodeExpression varAsyncr = new CodeVariableReferenceExpression (varAsyncResult);
inv = new CodeMethodInvokeExpression (ethis, "EndInvoke", varAsyncr);
if (!isVoid)
methodEnd.Statements.Add (new CodeMethodReturnStatement (new CodeCastExpression (methodEnd.ReturnType, inv)));
else
methodEnd.Statements.Add (inv);
// Attributes
//.........这里部分代码省略.........
示例15: GenerateReturnAttributes
void GenerateReturnAttributes (XmlMembersMapping members, XmlMemberMapping member, SoapBindingUse use, CodeMemberMethod method)
{
if (use == SoapBindingUse.Literal)
xmlExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, member, members.Namespace, (member.ElementName != method.Name + "Result"));
else
soapExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, member, (member.ElementName != method.Name + "Result"));
}