本文整理汇总了C#中System.Xml.Serialization.CodeIdentifiers.AddUnique方法的典型用法代码示例。如果您正苦于以下问题:C# CodeIdentifiers.AddUnique方法的具体用法?C# CodeIdentifiers.AddUnique怎么用?C# CodeIdentifiers.AddUnique使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Serialization.CodeIdentifiers
的用法示例。
在下文中一共展示了CodeIdentifiers.AddUnique方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateBaseSerializer
internal string GenerateBaseSerializer(string baseSerializer, string readerClass, string writerClass, CodeIdentifiers classes)
{
baseSerializer = CodeIdentifier.MakeValid(baseSerializer);
baseSerializer = classes.AddUnique(baseSerializer, baseSerializer);
this.writer.WriteLine();
this.writer.Write("public abstract class ");
this.writer.Write(CodeIdentifier.GetCSharpName(baseSerializer));
this.writer.Write(" : ");
this.writer.Write(typeof(XmlSerializer).FullName);
this.writer.WriteLine(" {");
this.writer.Indent++;
this.writer.Write("protected override ");
this.writer.Write(typeof(XmlSerializationReader).FullName);
this.writer.WriteLine(" CreateReader() {");
this.writer.Indent++;
this.writer.Write("return new ");
this.writer.Write(readerClass);
this.writer.WriteLine("();");
this.writer.Indent--;
this.writer.WriteLine("}");
this.writer.Write("protected override ");
this.writer.Write(typeof(XmlSerializationWriter).FullName);
this.writer.WriteLine(" CreateWriter() {");
this.writer.Indent++;
this.writer.Write("return new ");
this.writer.Write(writerClass);
this.writer.WriteLine("();");
this.writer.Indent--;
this.writer.WriteLine("}");
this.writer.Indent--;
this.writer.WriteLine("}");
return baseSerializer;
}
示例2: IgnoreCase
public void IgnoreCase ()
{
CodeIdentifiers c = new CodeIdentifiers (false);
c.Add ("test", "x");
c.Add ("Test", "y");
Assert.IsTrue ("test" != c.AddUnique ("Test", "z"), "#1");
Assert.IsTrue (c.IsInUse ("tEsT"), "#2");
Assert.AreEqual ("camelCase", c.MakeRightCase ("CAMELCASE"), "#3");
}
示例3: GenerateTypedSerializer
internal string GenerateTypedSerializer(string readMethod, string writeMethod, XmlMapping mapping, CodeIdentifiers classes, string baseSerializer, string readerClass, string writerClass)
{
string serializerName = CodeIdentifier.MakeValid(Accessor.UnescapeName(mapping.Accessor.Mapping.TypeDesc.Name));
serializerName = classes.AddUnique(serializerName + "Serializer", mapping);
TypeBuilder typedSerializerTypeBuilder = CodeGenerator.CreateTypeBuilder(
_moduleBuilder,
CodeIdentifier.GetCSharpName(serializerName),
TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit,
CreatedTypes[baseSerializer],
Array.Empty<Type>()
);
ilg = new CodeGenerator(typedSerializerTypeBuilder);
ilg.BeginMethod(
typeof(Boolean),
"CanDeserialize",
new Type[] { typeof(XmlReader) },
new string[] { "xmlReader" },
CodeGenerator.PublicOverrideMethodAttributes
);
if (mapping.Accessor.Any)
{
ilg.Ldc(true);
ilg.Stloc(ilg.ReturnLocal);
ilg.Br(ilg.ReturnLabel);
}
else
{
MethodInfo XmlReader_IsStartElement = typeof(XmlReader).GetMethod(
"IsStartElement",
CodeGenerator.InstanceBindingFlags,
new Type[] { typeof(String), typeof(String) }
);
ilg.Ldarg(ilg.GetArg("xmlReader"));
ilg.Ldstr(GetCSharpString(mapping.Accessor.Name));
ilg.Ldstr(GetCSharpString(mapping.Accessor.Namespace));
ilg.Call(XmlReader_IsStartElement);
ilg.Stloc(ilg.ReturnLocal);
ilg.Br(ilg.ReturnLabel);
}
ilg.MarkLabel(ilg.ReturnLabel);
ilg.Ldloc(ilg.ReturnLocal);
ilg.EndMethod();
if (writeMethod != null)
{
ilg = new CodeGenerator(typedSerializerTypeBuilder);
ilg.BeginMethod(
typeof(void),
"Serialize",
new Type[] { typeof(object), typeof(XmlSerializationWriter) },
new string[] { "objectToSerialize", "writer" },
CodeGenerator.ProtectedOverrideMethodAttributes);
MethodInfo writerType_writeMethod = CreatedTypes[writerClass].GetMethod(
writeMethod,
CodeGenerator.InstanceBindingFlags,
new Type[] { (mapping is XmlMembersMapping) ? typeof(object[]) : typeof(object) }
);
ilg.Ldarg("writer");
ilg.Castclass(CreatedTypes[writerClass]);
ilg.Ldarg("objectToSerialize");
if (mapping is XmlMembersMapping)
{
ilg.ConvertValue(typeof(object), typeof(object[]));
}
ilg.Call(writerType_writeMethod);
ilg.EndMethod();
}
if (readMethod != null)
{
ilg = new CodeGenerator(typedSerializerTypeBuilder);
ilg.BeginMethod(
typeof(object),
"Deserialize",
new Type[] { typeof(XmlSerializationReader) },
new string[] { "reader" },
CodeGenerator.ProtectedOverrideMethodAttributes);
MethodInfo readerType_readMethod = CreatedTypes[readerClass].GetMethod(
readMethod,
CodeGenerator.InstanceBindingFlags,
Array.Empty<Type>()
);
ilg.Ldarg("reader");
ilg.Castclass(CreatedTypes[readerClass]);
ilg.Call(readerType_readMethod);
ilg.EndMethod();
}
typedSerializerTypeBuilder.DefineDefaultConstructor(CodeGenerator.PublicMethodAttributes);
Type typedSerializerType = typedSerializerTypeBuilder.CreateTypeInfo().AsType();
CreatedTypes.Add(typedSerializerType.Name, typedSerializerType);
return typedSerializerType.Name;
}
示例4: ImportAnyAttributeMember
void ImportAnyAttributeMember(XmlSchemaAnyAttribute any, CodeIdentifiers members) {
SpecialMapping mapping = new SpecialMapping();
mapping.TypeDesc = scope.GetTypeDesc(typeof(XmlAttribute));
mapping.TypeName = mapping.TypeDesc.Name;
AttributeAccessor accessor = new AttributeAccessor();
accessor.Any = true;
accessor.Mapping = mapping;
MemberMapping member = new MemberMapping();
member.Elements = new ElementAccessor[0];
member.Attribute = accessor;
member.Name = members.MakeRightCase("AnyAttr");
member.Name = members.AddUnique(member.Name, member);
member.TypeDesc = ((TypeMapping)accessor.Mapping).TypeDesc;
member.TypeDesc = member.TypeDesc.CreateArrayTypeDesc();
}
示例5: GenerateBaseSerializer
internal string GenerateBaseSerializer(string baseSerializer, string readerClass, string writerClass, CodeIdentifiers classes)
{
baseSerializer = CodeIdentifier.MakeValid(baseSerializer);
baseSerializer = classes.AddUnique(baseSerializer, baseSerializer);
TypeBuilder baseSerializerTypeBuilder = CodeGenerator.CreateTypeBuilder(
_moduleBuilder,
CodeIdentifier.GetCSharpName(baseSerializer),
TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit,
typeof(XmlSerializer),
Array.Empty<Type>());
ConstructorInfo readerCtor = CreatedTypes[readerClass].GetConstructor(
CodeGenerator.InstanceBindingFlags,
Array.Empty<Type>()
);
ilg = new CodeGenerator(baseSerializerTypeBuilder);
ilg.BeginMethod(typeof(XmlSerializationReader),
"CreateReader",
Array.Empty<Type>(),
Array.Empty<string>(),
CodeGenerator.ProtectedOverrideMethodAttributes);
ilg.New(readerCtor);
ilg.EndMethod();
ConstructorInfo writerCtor = CreatedTypes[writerClass].GetConstructor(
CodeGenerator.InstanceBindingFlags,
Array.Empty<Type>()
);
ilg.BeginMethod(typeof(XmlSerializationWriter),
"CreateWriter",
Array.Empty<Type>(),
Array.Empty<string>(),
CodeGenerator.ProtectedOverrideMethodAttributes);
ilg.New(writerCtor);
ilg.EndMethod();
baseSerializerTypeBuilder.DefineDefaultConstructor(
MethodAttributes.Family | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName);
Type baseSerializerType = baseSerializerTypeBuilder.CreateTypeInfo().AsType();
CreatedTypes.Add(baseSerializerType.Name, baseSerializerType);
return baseSerializer;
}
示例6: 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);
}
}
}
示例7: CreateHeaderMessages
void CreateHeaderMessages(string methodName, SoapBindingUse use, XmlMembersMapping inHeaderMappings, XmlMembersMapping outHeaderMappings, SoapReflectedHeader[] headers, bool rpc) {
//
if (use == SoapBindingUse.Encoded) {
SoapExporter.ExportMembersMapping(inHeaderMappings, false);
if (outHeaderMappings != null)
SoapExporter.ExportMembersMapping(outHeaderMappings, false);
}
else {
SchemaExporter.ExportMembersMapping(inHeaderMappings);
if (outHeaderMappings != null)
SchemaExporter.ExportMembersMapping(outHeaderMappings);
}
CodeIdentifiers identifiers = new CodeIdentifiers();
int inCount = 0, outCount = 0;
for (int i = 0; i < headers.Length; i++) {
SoapReflectedHeader soapHeader = headers[i];
if (!soapHeader.custom) continue;
XmlMemberMapping member;
if ((soapHeader.direction & SoapHeaderDirection.In) != 0) {
member = inHeaderMappings[inCount++];
if (soapHeader.direction != SoapHeaderDirection.In)
outCount++;
}
else {
member = outHeaderMappings[outCount++];
}
MessagePart part = new MessagePart();
part.Name = member.XsdElementName;
if (use == SoapBindingUse.Encoded)
part.Type = new XmlQualifiedName(member.TypeName, member.TypeNamespace);
else
part.Element = new XmlQualifiedName(member.XsdElementName, member.Namespace);
Message message = new Message();
message.Name = identifiers.AddUnique(methodName + part.Name, message);
message.Parts.Add(part);
HeaderMessages.Add(message);
ServiceDescriptionFormatExtension soapHeaderBinding = CreateSoapHeaderBinding(new XmlQualifiedName(message.Name, Binding.ServiceDescription.TargetNamespace), part.Name, rpc ? member.Namespace : null, use);
if ((soapHeader.direction & SoapHeaderDirection.In) != 0)
OperationBinding.Input.Extensions.Add(soapHeaderBinding);
if ((soapHeader.direction & SoapHeaderDirection.Out) != 0)
OperationBinding.Output.Extensions.Add(soapHeaderBinding);
if ((soapHeader.direction & SoapHeaderDirection.Fault) != 0) {
if (soapMethod.IsClaimsConformance) {
throw new InvalidOperationException(Res.GetString(Res.BPConformanceHeaderFault, soapMethod.methodInfo.ToString(), soapMethod.methodInfo.DeclaringType.FullName, "Direction", typeof(SoapHeaderDirection).Name, SoapHeaderDirection.Fault.ToString()));
}
OperationBinding.Output.Extensions.Add(soapHeaderBinding);
}
}
}
示例8: ImportEnumeratedDataType
TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier, bool isList) {
TypeMapping mapping = (TypeMapping)ImportedMappings[dataType];
if (mapping != null)
return mapping;
XmlSchemaSimpleType sourceDataType = FindDataType(dataType.DerivedFrom);
TypeDesc sourceTypeDesc = Scope.GetTypeDesc(sourceDataType);
if (sourceTypeDesc != null && sourceTypeDesc != Scope.GetTypeDesc(typeof(string)))
return ImportPrimitiveDataType(dataType);
identifier = Accessor.UnescapeName(identifier);
string typeName = GenerateUniqueTypeName(identifier);
EnumMapping enumMapping = new EnumMapping();
enumMapping.IsReference = Schemas.IsReference(dataType);
enumMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0);
enumMapping.TypeName = identifier;
enumMapping.Namespace = typeNs;
enumMapping.IsFlags = isList;
CodeIdentifiers constants = new CodeIdentifiers();
if (!(dataType.Content is XmlSchemaSimpleTypeRestriction))
throw new InvalidOperationException(Res.GetString(Res.XmlInvalidEnumContent, dataType.Content.GetType().Name, identifier));
XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)dataType.Content;
for (int i = 0; i < restriction.Facets.Count; i++) {
object facet = restriction.Facets[i];
if (!(facet is XmlSchemaEnumerationFacet)) continue;
XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet)facet;
ConstantMapping constant = new ConstantMapping();
string constantName = CodeIdentifier.MakeValid(enumeration.Value);
constant.Name = constants.AddUnique(constantName, constant);
constant.XmlName = enumeration.Value;
constant.Value = i;
}
enumMapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping));
if (isList && enumMapping.Constants.Length > 63) {
// if we have 64+ flag constants we cannot map the type to long enum, we will use string mapping instead.
mapping = new PrimitiveMapping();
mapping.TypeDesc = Scope.GetTypeDesc(typeof(string));
mapping.TypeName = mapping.TypeDesc.DataType.Name;
ImportedMappings.Add(dataType, mapping);
return mapping;
}
ImportedMappings.Add(dataType, enumMapping);
Scope.AddTypeMapping(enumMapping);
return enumMapping;
}
示例9: ImportEnumeratedDataType
TypeMapping ImportEnumeratedDataType(XmlSchemaSimpleType dataType, string typeNs, string identifier) {
EnumMapping enumMapping = (EnumMapping)mappings[dataType];
if (enumMapping != null) return enumMapping;
XmlSchemaType sourceType = FindType(dataType.DerivedFrom);
if (sourceType is XmlSchemaComplexType) return null;
TypeDesc sourceTypeDesc = scope.GetTypeDesc((XmlSchemaSimpleType)sourceType);
if (sourceTypeDesc != null && sourceTypeDesc.FullName != typeof(string).FullName)
return ImportPrimitiveDataType(dataType);
string typeName = GenerateUniqueTypeName(identifier);
enumMapping = new EnumMapping();
enumMapping.TypeDesc = new TypeDesc(typeName, typeName, TypeKind.Enum, null, 0);
enumMapping.TypeName = identifier;
enumMapping.Namespace = typeNs;
enumMapping.IsFlags = false;
mappings.Add(dataType, enumMapping);
CodeIdentifiers constants = new CodeIdentifiers();
XmlSchemaSimpleTypeContent content = dataType.Content;
if (content is XmlSchemaSimpleTypeRestriction) {
XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)content;
for (int i = 0; i < restriction.Facets.Count; i++) {
object facet = restriction.Facets[i];
if (!(facet is XmlSchemaEnumerationFacet)) continue;
XmlSchemaEnumerationFacet enumeration = (XmlSchemaEnumerationFacet)facet;
// validate the enumeration value
if (sourceTypeDesc != null && sourceTypeDesc.HasCustomFormatter) {
XmlCustomFormatter.ToDefaultValue(enumeration.Value, sourceTypeDesc.FormatterName);
}
ConstantMapping constant = new ConstantMapping();
string constantName = CodeIdentifier.MakeValid(enumeration.Value);
constant.Name = constants.AddUnique(constantName, constant);
constant.XmlName = enumeration.Value;
constant.Value = i;
}
}
enumMapping.Constants = (ConstantMapping[])constants.ToArray(typeof(ConstantMapping));
scope.AddTypeMapping(enumMapping);
return enumMapping;
}
示例10: ImportElementMember
void ImportElementMember(XmlSchemaElement element, string identifier, CodeIdentifiers members, string ns, bool repeats) {
XmlSchemaElement abstractElement = GetAbstractElement(element);
if (abstractElement != null) {
ImportAbstractMember(abstractElement, identifier, members, ns, repeats);
return;
}
ElementAccessor accessor;
if ((accessor = ImportArray(element, identifier, ns, repeats)) == null) {
if ((accessor = ImportSerializable(element, identifier, ns, repeats)) == null) {
accessor = ImportElement(element, identifier, typeof(TypeMapping), null, ns);
}
}
MemberMapping member = new MemberMapping();
member.Name = CodeIdentifier.MakeValid(Accessor.UnescapeName(accessor.Name));
member.Name = members.AddUnique(member.Name, member);
if (member.Name.EndsWith("Specified")) {
string name = member.Name;
member.Name = members.AddUnique(member.Name, member);
members.Remove(name);
}
member.TypeDesc = ((TypeMapping)accessor.Mapping).TypeDesc;
member.Elements = new ElementAccessor[] { accessor };
if (element.IsMultipleOccurrence || repeats)
member.TypeDesc = member.TypeDesc.CreateArrayTypeDesc();
if (element.MinOccurs == 0 && member.TypeDesc.IsValueType && !element.HasDefault && !member.TypeDesc.HasIsEmpty) {
member.CheckSpecified = true;
}
}
示例11: UniqueName
internal static string UniqueName(string baseName, string[] scope) {
CodeIdentifiers identifiers = new CodeIdentifiers();
for (int i = 0; i < scope.Length; i++) {
identifiers.AddUnique(scope[i], scope[i]);
}
return identifiers.AddUnique(baseName, baseName);
}
示例12: ImportTextMember
void ImportTextMember(CodeIdentifiers members, XmlQualifiedName simpleContentType) {
TypeMapping mapping;
bool isMixed = false;
if (simpleContentType != null) {
mapping = ImportType(simpleContentType, typeof(TypeMapping), null);
if (!(mapping is PrimitiveMapping || mapping.TypeDesc.CanBeTextValue)) {
return;
}
}
else {
// this is a case of the mixed content type, just generate string typeDesc
isMixed = true;
mapping = new PrimitiveMapping();
mapping.TypeDesc = scope.GetTypeDesc(typeof(string));
mapping.TypeName = mapping.TypeDesc.DataType.Name;
}
TextAccessor accessor = new TextAccessor();
accessor.Mapping = mapping;
MemberMapping member = new MemberMapping();
member.Elements = new ElementAccessor[0];
member.Text = accessor;
if (isMixed) {
// just generate code for the standard mixed case (string[] text)
member.TypeDesc = accessor.Mapping.TypeDesc.CreateArrayTypeDesc();
member.Name = members.MakeRightCase("Text");
}
else {
// import mapping for the simpleContent
PrimitiveMapping pm = (PrimitiveMapping)accessor.Mapping;
if (pm.IsList) {
member.TypeDesc = accessor.Mapping.TypeDesc.CreateArrayTypeDesc();
member.Name = members.MakeRightCase("Text");
}
else {
member.TypeDesc = accessor.Mapping.TypeDesc;
member.Name = members.MakeRightCase("Value");
}
}
member.Name = members.AddUnique(member.Name, member);
}
示例13: ImportAnyMember
void ImportAnyMember(XmlSchemaAny any, string identifier, CodeIdentifiers members, string ns, bool mixed) {
ElementAccessor accessor = ImportAny(any, !mixed);
accessor.Name = identifier;
accessor.Namespace = ns;
MemberMapping member = new MemberMapping();
member.Elements = new ElementAccessor[] { accessor };
member.Name = members.MakeRightCase("Any");
member.Name = members.AddUnique(member.Name, member);
member.TypeDesc = ((TypeMapping)accessor.Mapping).TypeDesc;
bool repeats = any.IsMultipleOccurrence;
if (mixed) {
SpecialMapping textMapping = new SpecialMapping();
textMapping.TypeDesc = scope.GetTypeDesc(typeof(XmlNode));
textMapping.TypeName = textMapping.TypeDesc.Name;
member.TypeDesc = textMapping.TypeDesc;
TextAccessor text = new TextAccessor();
text.Mapping = textMapping;
member.Text = text;
repeats = true;
}
if (repeats) {
member.TypeDesc = member.TypeDesc.CreateArrayTypeDesc();
}
}
示例14: ImportChoiceGroup
MemberMapping ImportChoiceGroup(XmlSchemaChoice group, string identifier, CodeIdentifiers members, string ns, bool groupRepeats) {
ArrayList list = new ArrayList();
if (GatherGroupChoices(group, list, identifier, ns))
groupRepeats = true;
MemberMapping member = new MemberMapping();
member.Elements = (ElementAccessor[])list.ToArray(typeof(ElementAccessor));
bool duplicateTypes = false;
Hashtable uniqueTypeDescs = new Hashtable(list.Count);
for (int i = 0; i < list.Count; i++) {
TypeDesc td = ((TypeMapping)((ElementAccessor)list[i]).Mapping).TypeDesc;
if (uniqueTypeDescs.Contains(td.FullName)) {
duplicateTypes = true;
}
else {
uniqueTypeDescs.Add(td.FullName, td);
}
}
TypeDesc[] typeDescs = new TypeDesc[uniqueTypeDescs.Count];
uniqueTypeDescs.Values.CopyTo(typeDescs, 0);
member.TypeDesc = TypeDesc.FindCommonBaseTypeDesc(typeDescs);
if (member.TypeDesc == null) member.TypeDesc = scope.GetTypeDesc(typeof(object));
if (groupRepeats)
member.TypeDesc = member.TypeDesc.CreateArrayTypeDesc();
if (members != null) {
member.Name = members.AddUnique(groupRepeats ? "Items" : "Item", member);
}
if (duplicateTypes) {
member.ChoiceIdentifier = new ChoiceIdentifierAccessor();
member.ChoiceIdentifier.MemberName = member.Name + "ElementName";
// we need to create the EnumMapping to store all of the element names
member.ChoiceIdentifier.Mapping = ImportEnumeratedChoice(member.Elements, ns, member.Name + "ChoiceType");
member.ChoiceIdentifier.MemberIds = new string[member.Elements.Length];
ConstantMapping[] constants = ((EnumMapping)member.ChoiceIdentifier.Mapping).Constants;
for (int i = 0; i < member.Elements.Length; i++) {
member.ChoiceIdentifier.MemberIds[i] = constants[i].Name;
}
MemberMapping choiceIdentifier = new MemberMapping();
choiceIdentifier.Ignore = true;
choiceIdentifier.Name = member.ChoiceIdentifier.MemberName;
if (groupRepeats) {
choiceIdentifier.TypeDesc = member.ChoiceIdentifier.Mapping.TypeDesc.CreateArrayTypeDesc();
}
else {
choiceIdentifier.TypeDesc = member.ChoiceIdentifier.Mapping.TypeDesc;
}
// create element accessor for the choiceIdentifier
ElementAccessor choiceAccessor = new ElementAccessor();
choiceAccessor.Name = choiceIdentifier.Name;
choiceAccessor.Namespace = ns;
choiceAccessor.Mapping = member.ChoiceIdentifier.Mapping;
choiceIdentifier.Elements = new ElementAccessor[] {choiceAccessor};
if (members != null) {
choiceAccessor.Name = choiceIdentifier.Name = member.ChoiceIdentifier.MemberName = members.AddUnique(member.ChoiceIdentifier.MemberName, choiceIdentifier);
}
}
return member;
}
示例15: ImportMembersMapping
/// <include file='doc\XmlSchemaImporter.uex' path='docs/doc[@for="XmlSchemaImporter.ImportMembersMapping2"]/*' />
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public XmlMembersMapping ImportMembersMapping(XmlQualifiedName[] names, Type baseType, bool baseTypeCanBeIndirect) {
CodeIdentifiers memberScope = new CodeIdentifiers();
memberScope.UseCamelCasing = true;
MemberMapping[] members = new MemberMapping[names.Length];
for (int i = 0; i < names.Length; i++) {
XmlQualifiedName name = EncodeQName(names[i]);
ElementAccessor accessor = ImportElement(name, typeof(TypeMapping), baseType);
if (baseType != null && accessor.Mapping is StructMapping)
MakeDerived((StructMapping)accessor.Mapping, baseType, baseTypeCanBeIndirect);
MemberMapping member = new MemberMapping();
member.Name = CodeIdentifier.MakeValid(Accessor.UnescapeName(accessor.Name));
member.Name = memberScope.AddUnique(member.Name, member);
member.TypeDesc = accessor.Mapping.TypeDesc;
member.Elements = new ElementAccessor[] { accessor };
members[i] = member;
}
MembersMapping mapping = new MembersMapping();
mapping.HasWrapperElement = false;
mapping.TypeDesc = scope.GetTypeDesc(typeof(object[]));
mapping.Members = members;
ElementAccessor element = new ElementAccessor();
element.Mapping = mapping;
return new XmlMembersMapping(scope, element);
}