本文整理汇总了C#中System.Xml.Schema.XmlSchemaGroupBase类的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemaGroupBase类的具体用法?C# XmlSchemaGroupBase怎么用?C# XmlSchemaGroupBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlSchemaGroupBase类属于System.Xml.Schema命名空间,在下文中一共展示了XmlSchemaGroupBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyOptimizedItems
internal void CopyOptimizedItems (XmlSchemaGroupBase gb)
{
for (int i = 0; i < Items.Count; i++) {
XmlSchemaParticle p = Items [i] as XmlSchemaParticle;
p = p.GetOptimizedParticle (false);
if (p == XmlSchemaParticle.Empty)
continue;
gb.Items.Add (p);
gb.CompiledItems.Add (p);
}
}
示例2: IsGroupBaseFromGroupBase
private bool IsGroupBaseFromGroupBase(XmlSchemaGroupBase derivedGroupBase, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly) {
if (!IsValidOccurrenceRangeRestriction(derivedGroupBase, baseGroupBase) || derivedGroupBase.Items.Count > baseGroupBase.Items.Count) {
return false;
}
int count = 0;
for (int i = 0; i < baseGroupBase.Items.Count; ++i) {
XmlSchemaParticle baseParticle = (XmlSchemaParticle)baseGroupBase.Items[i];
if ((count < derivedGroupBase.Items.Count) && IsValidRestriction((XmlSchemaParticle)derivedGroupBase.Items[count], baseParticle)) {
count ++;
}
else if (skipEmptableOnly && !IsParticleEmptiable(baseParticle)) {
return false;
}
}
if (count < derivedGroupBase.Items.Count) {
return false;
}
return true;
}
示例3: IsGroupBaseFromGroupBase
private bool IsGroupBaseFromGroupBase(XmlSchemaGroupBase derivedGroupBase, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly)
{
if (!this.IsValidOccurrenceRangeRestriction(derivedGroupBase, baseGroupBase) || (derivedGroupBase.Items.Count > baseGroupBase.Items.Count))
{
return false;
}
int num = 0;
for (int i = 0; i < baseGroupBase.Items.Count; i++)
{
XmlSchemaParticle baseParticle = (XmlSchemaParticle) baseGroupBase.Items[i];
if ((num < derivedGroupBase.Items.Count) && this.IsValidRestriction((XmlSchemaParticle) derivedGroupBase.Items[num], baseParticle))
{
num++;
}
else if (skipEmptableOnly && !this.IsParticleEmptiable(baseParticle))
{
return false;
}
}
if (num < derivedGroupBase.Items.Count)
{
return false;
}
return true;
}
示例4: IsElementFromGroupBase
private bool IsElementFromGroupBase(XmlSchemaElement derivedElement, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly)
{
bool flag = false;
for (int i = 0; i < baseGroupBase.Items.Count; i++)
{
XmlSchemaParticle baseParticle = (XmlSchemaParticle) baseGroupBase.Items[i];
if (!flag)
{
string minOccursString = baseParticle.MinOccursString;
string maxOccursString = baseParticle.MaxOccursString;
baseParticle.MinOccurs *= baseGroupBase.MinOccurs;
if (baseParticle.MaxOccurs != 79228162514264337593543950335M)
{
if (baseGroupBase.MaxOccurs == 79228162514264337593543950335M)
{
baseParticle.MaxOccurs = 79228162514264337593543950335M;
}
else
{
baseParticle.MaxOccurs *= baseGroupBase.MaxOccurs;
}
}
flag = this.IsValidRestriction(derivedElement, baseParticle);
baseParticle.MinOccursString = minOccursString;
baseParticle.MaxOccursString = maxOccursString;
}
else if (skipEmptableOnly && !this.IsParticleEmptiable(baseParticle))
{
return false;
}
}
return flag;
}
示例5: IsGroupBaseFromGroupBase
private bool IsGroupBaseFromGroupBase(XmlSchemaGroupBase derivedGroupBase, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly) {
if (!IsValidOccurrenceRangeRestriction(derivedGroupBase, baseGroupBase)) {
restrictionErrorMsg = Res.GetString(Res.Sch_GroupBaseRestRangeInvalid);
return false;
}
if (derivedGroupBase.Items.Count > baseGroupBase.Items.Count) {
restrictionErrorMsg = Res.GetString(Res.Sch_GroupBaseRestNoMap);
return false;
}
int count = 0;
for (int i = 0; i < baseGroupBase.Items.Count; ++i) {
XmlSchemaParticle baseParticle = (XmlSchemaParticle)baseGroupBase.Items[i];
if ((count < derivedGroupBase.Items.Count)
&& IsValidRestriction((XmlSchemaParticle)derivedGroupBase.Items[count], baseParticle)) {
count ++;
}
else if (skipEmptableOnly && !IsParticleEmptiable(baseParticle)) {
if (restrictionErrorMsg == null) { //If restriction failed on previous check, do not overwrite error
restrictionErrorMsg = Res.GetString(Res.Sch_GroupBaseRestNotEmptiable);
}
return false;
}
}
if (count < derivedGroupBase.Items.Count) {
return false;
}
return true;
}
示例6: IsElementFromGroupBaseHack
private bool IsElementFromGroupBaseHack(XmlSchemaElement derivedElement, XmlSchemaGroupBase baseGroupBase, bool skipEmptableOnly) {
bool isMatched = false;
foreach(XmlSchemaParticle baseParticle in baseGroupBase.Items) {
if (!isMatched && IsRangeSimple(baseParticle.MinOccurs, baseParticle.MaxOccurs)) {
string minOccursElement = baseParticle.MinOccursString;
string maxOccursElement = baseParticle.MaxOccursString;
baseParticle.MinOccurs *= baseGroupBase.MinOccurs;
if ( baseParticle.MaxOccurs != decimal.MaxValue) {
if (baseGroupBase.MaxOccurs == decimal.MaxValue)
baseParticle.MaxOccurs = decimal.MaxValue;
else
baseParticle.MaxOccurs *= baseGroupBase.MaxOccurs;
}
isMatched = IsValidRestriction(derivedElement, baseParticle);
baseParticle.MinOccursString = minOccursElement;
baseParticle.MaxOccursString = maxOccursElement;
}
if (!isMatched && skipEmptableOnly && !IsParticleEmptiable(baseParticle)) {
return false;
}
}
return isMatched;
}
示例7: IsGroupBaseFromAny
private bool IsGroupBaseFromAny(XmlSchemaGroupBase derivedGroupBase, XmlSchemaAny baseAny) {
decimal minOccurs, maxOccurs;
CalculateEffectiveTotalRange(derivedGroupBase, out minOccurs, out maxOccurs);
if (!IsValidOccurrenceRangeRestriction(minOccurs, maxOccurs, baseAny.MinOccurs, baseAny.MaxOccurs)) {
restrictionErrorMsg = Res.GetString(Res.Sch_GroupBaseFromAny2, derivedGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseAny.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseAny.LinePosition.ToString(NumberFormatInfo.InvariantInfo));
return false;
}
// eliminate occurrance range check
string minOccursAny = baseAny.MinOccursString;
baseAny.MinOccurs = decimal.Zero;
for (int i = 0; i < derivedGroupBase.Items.Count; ++i) {
if (!IsValidRestriction((XmlSchemaParticle)derivedGroupBase.Items[i], baseAny)) {
restrictionErrorMsg = Res.GetString(Res.Sch_GroupBaseFromAny1);
baseAny.MinOccursString = minOccursAny;
return false;
}
}
baseAny.MinOccursString = minOccursAny;
return true;
}
示例8: ExportElementAccessor
private void ExportElementAccessor(XmlSchemaGroupBase group, ElementAccessor accessor, bool repeats, bool valueTypeOptional, string ns)
{
if (accessor.Any && (accessor.Name.Length == 0))
{
XmlSchemaAny item = new XmlSchemaAny {
MinOccurs = 0M,
MaxOccurs = repeats ? 79228162514264337593543950335M : 1M
};
if (((accessor.Namespace != null) && (accessor.Namespace.Length > 0)) && (accessor.Namespace != ns))
{
item.Namespace = accessor.Namespace;
}
group.Items.Add(item);
}
else
{
XmlSchemaElement element = (XmlSchemaElement) this.elements[accessor];
int num = (((repeats || accessor.HasDefault) || (!accessor.IsNullable && !accessor.Mapping.TypeDesc.IsValueType)) || valueTypeOptional) ? 0 : 1;
decimal num2 = (repeats || accessor.IsUnbounded) ? 79228162514264337593543950335M : 1M;
if (element == null)
{
element = new XmlSchemaElement {
IsNillable = accessor.IsNullable,
Name = accessor.Name
};
if (accessor.HasDefault)
{
element.DefaultValue = ExportDefaultValue(accessor.Mapping, accessor.Default);
}
if (accessor.IsTopLevelInSchema)
{
this.elements.Add(accessor, element);
element.Form = accessor.Form;
this.AddSchemaItem(element, accessor.Namespace, ns);
}
else
{
element.MinOccurs = num;
element.MaxOccurs = num2;
XmlSchema schema = this.schemas[ns];
if (schema == null)
{
element.Form = (accessor.Form == XmlSchemaForm.Qualified) ? XmlSchemaForm.None : accessor.Form;
}
else
{
element.Form = (accessor.Form == schema.ElementFormDefault) ? XmlSchemaForm.None : accessor.Form;
}
}
this.ExportElementMapping(element, accessor.Mapping, accessor.Namespace, accessor.Any);
}
if (accessor.IsTopLevelInSchema)
{
XmlSchemaElement element2 = new XmlSchemaElement {
RefName = new XmlQualifiedName(accessor.Name, accessor.Namespace),
MinOccurs = num,
MaxOccurs = num2
};
group.Items.Add(element2);
this.AddSchemaImport(accessor.Namespace, ns);
}
else
{
group.Items.Add(element);
}
}
}
示例9: ImportChoiceGroup
private MemberMapping ImportChoiceGroup(XmlSchemaGroupBase group, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, INameScope elementsScope, string ns, bool groupRepeats, ref bool needExplicitOrder, bool allowDuplicates)
{
NameTable choiceElements = new NameTable();
if (GatherGroupChoices(group, choiceElements, identifier, ns, ref needExplicitOrder, allowDuplicates))
groupRepeats = true;
MemberMapping member = new MemberMapping();
member.Elements = (ElementAccessor[])choiceElements.ToArray(typeof(ElementAccessor));
Array.Sort(member.Elements, new ElementComparer());
AddScopeElements(elementsScope, member.Elements, ref needExplicitOrder, allowDuplicates);
bool duplicateTypes = false;
bool nullableMismatch = false;
Hashtable uniqueTypeDescs = new Hashtable(member.Elements.Length);
for (int i = 0; i < member.Elements.Length; i++)
{
ElementAccessor element = member.Elements[i];
string tdFullName = element.Mapping.TypeDesc.FullName;
object val = uniqueTypeDescs[tdFullName];
if (val != null)
{
duplicateTypes = true;
ElementAccessor existingElement = (ElementAccessor)val;
if (!nullableMismatch && existingElement.IsNullable != element.IsNullable)
nullableMismatch = true;
}
else
{
uniqueTypeDescs.Add(tdFullName, element);
}
ArrayMapping arrayMapping = element.Mapping as ArrayMapping;
if (arrayMapping != null)
{
if (IsNeedXmlSerializationAttributes(arrayMapping))
{
// we cannot use ArrayMapping in choice if additional custom
// serialization attributes are needed to serialize it
element.Mapping = arrayMapping.TopLevelMapping;
element.Mapping.ReferencedByTopLevelElement = false;
element.Mapping.ReferencedByElement = true;
}
}
}
if (nullableMismatch)
member.TypeDesc = Scope.GetTypeDesc(typeof(object));
else
{
TypeDesc[] typeDescs = new TypeDesc[uniqueTypeDescs.Count];
IEnumerator enumerator = uniqueTypeDescs.Values.GetEnumerator();
for (int i = 0; i < typeDescs.Length; i++)
{
if (!enumerator.MoveNext())
break;
typeDescs[i] = ((ElementAccessor)enumerator.Current).Mapping.TypeDesc;
}
member.TypeDesc = TypeDesc.FindCommonBaseTypeDesc(typeDescs);
if (member.TypeDesc == null) member.TypeDesc = Scope.GetTypeDesc(typeof(object));
}
if (groupRepeats)
member.TypeDesc = member.TypeDesc.CreateArrayTypeDesc();
if (membersScope != null)
{
member.Name = membersScope.AddUnique(groupRepeats ? "Items" : "Item", member);
if (members != null)
{
members.Add(member.Name, 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;
//.........这里部分代码省略.........
示例10: ImportGroup
private void ImportGroup(XmlSchemaGroupBase group, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, INameScope elementsScope, string ns, bool mixed, ref bool needExplicitOrder, bool allowDuplicates, bool groupRepeats, bool allowUnboundedElements)
{
if (group is XmlSchemaChoice)
ImportChoiceGroup((XmlSchemaChoice)group, identifier, members, membersScope, elementsScope, ns, groupRepeats, ref needExplicitOrder, allowDuplicates);
else
ImportGroupMembers(group, identifier, members, membersScope, elementsScope, ns, groupRepeats, ref mixed, ref needExplicitOrder, allowDuplicates, allowUnboundedElements);
if (mixed)
{
ImportTextMember(members, membersScope, null);
}
}
示例11: RecursiveChildren
public RecursiveChildren(XmlSchemaGroupBase group)
{
this.group = group;
}
示例12: ParseGroupBase
/// <summary>
/// Parses xs:sequence and xs:choice elements in the schema
/// </summary>
/// <param name="group"></param>
/// <returns>A list of direct children elements references</returns>
private RecursiveChildren ParseGroupBase(XmlSchemaGroupBase group)
{
RecursiveChildren result;
if (groupCache.TryGetValue(group, out result))
{
log.WriteLine("Used cache: {0}", GetParticleDesc(group));
return result;
}
log.WriteLine("Parsing group {0}", GetParticleDesc(group));
result = new RecursiveChildren(group);
groupCache.Add(group, result);
foreach (XmlSchemaParticle particle in group.Items)
{
using (log.Indent())
{
if (particle is XmlSchemaGroupBase)
{
XmlSchemaGroupBase subGroup = (XmlSchemaGroupBase)particle;
result.dependencies.Add(subGroup, ParseGroupBase(subGroup));
}
else if (particle is XmlSchemaElement)
{
result.children.Add(ParseElement((XmlSchemaElement)particle));
}
else if (particle is XmlSchemaAny)
{
}
else
{
throw new NotImplementedException(particle.GetType().Name);
}
}
}
return result;
}
示例13: ParseGroupBasePass0
/*
* Pass0. Collect references to globally defined complextypes and simpletypes.
*/
private void ParseGroupBasePass0(XmlSchemaGroupBase groupBase, String dotnetClassName, ArrayList childClasses, string parentNamespace, string currentNamespace, ElementsSubset es)
{
for (int i = 0; i < groupBase.Items.Count; i++)
{
if (groupBase.Items[i] is XmlSchemaElement)
{
XmlSchemaElement elementRef = (XmlSchemaElement)groupBase.Items[i];
XmlSchemaElement element = (XmlSchemaElement)schema.Elements[elementRef.QualifiedName];
if (element == null) element = elementRef;
string ns = element.QualifiedName.Namespace != "" ? element.QualifiedName.Namespace : parentNamespace;
if (element.ElementType is XmlSchemaComplexType && element.SchemaTypeName.Namespace != Globals.XSD_NAMESPACE)
{
XmlSchemaComplexType elementComplex = (XmlSchemaComplexType)element.ElementType;
// The complex type is locally defined so a child class needs to be created.
if ((element == elementRef) && (schema.SchemaTypes[elementComplex.QualifiedName] == null))
{
// recure these later
childClasses.Add(new ChildComplexType(elementComplex, element.Name, "", ns, element.QualifiedName));
}
if ((schema.Elements[elementRef.QualifiedName] != null) && (elementComplex.Name != null && elementComplex.Name != ""))
{
// global element who's name and type are set. Both element and complextype are named.
if (!es.Elements.ContainsKey(elementRef.QualifiedName.Name))
{
// add element and recure it's complextype
es.Elements.Add(elementRef.QualifiedName.Name, elementRef.QualifiedName.Name);
if (!es.ComplexTypes.ContainsKey(elementComplex.QualifiedName.Name) && !string.IsNullOrEmpty(elementComplex.QualifiedName.Name))
{
es.ComplexTypes.Add(elementComplex.QualifiedName.Name, elementComplex.QualifiedName.Name);
ParseComplexTypePass0(elementComplex, elementComplex.QualifiedName.Name, elementComplex.QualifiedName, elementComplex.QualifiedName.Namespace, es);
}
}
}
else if (elementComplex.Name != null && elementComplex.Name != "")
{
// globally defined named schema type
if (!es.ComplexTypes.ContainsKey(elementComplex.QualifiedName.Name))
{
es.ComplexTypes.Add(elementComplex.QualifiedName.Name, elementComplex.QualifiedName.Name);
ParseComplexTypePass0(elementComplex, elementComplex.QualifiedName.Name, elementComplex.QualifiedName, elementComplex.QualifiedName.Namespace, es);
}
}
else
{
// global element complexType -- element is named, but complex type is not
if (!es.Elements.ContainsKey(elementRef.QualifiedName.Name))
{
// add element and recure it's complextype
es.Elements.Add(elementRef.QualifiedName.Name, elementRef.QualifiedName.Name);
ParseComplexTypePass0(elementComplex, elementRef.QualifiedName.Name, elementRef.QualifiedName, elementRef.QualifiedName.Namespace, es);
}
}
}
else
{
// not a ComplexType
string xsdTypeName = element.SchemaTypeName.Name;
string clrTypeName = code.FrameworkTypeMapping(xsdTypeName);
// build SimpleType enumeration if needed
if (element.ElementType is XmlSchemaSimpleType)
{
XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)element.ElementType;
ParseEnumeration0(simpleType, element.Name, es);
}
}
}
else if (groupBase.Items[i] is XmlSchemaGroupRef)
{
XmlSchemaGroup group = (XmlSchemaGroup)schema.Groups[((XmlSchemaGroupRef)groupBase.Items[i]).RefName];
ParseGroupBasePass0(group.Particle, dotnetClassName, childClasses, parentNamespace, currentNamespace, es);
}
else if (groupBase.Items[i] is XmlSchemaGroupBase)
{
// Particle inside a particle : ie. <xsd:sequence> <xsd:choice/> </xsd:sequence>
ParseGroupBasePass0((XmlSchemaGroupBase)groupBase.Items[i], dotnetClassName, childClasses, parentNamespace, currentNamespace, es);
}
}
}
示例14: ParseGroupBasePass2
/*
* Add class fields for xsd:all, xsd:choice and xsd:sequence xml elements.
* These will either be native CLR typed fields or other schema classes.
*/
private void ParseGroupBasePass2(XmlSchemaGroupBase groupBase, String className, ArrayList ctorList,
ArrayList childClasses, ArrayList parentClassStack, Hashtable dotnetFieldList, string parentNamespace, Hashtable classReferencesAdded)
{
if (classReferencesAdded == null) classReferencesAdded = new Hashtable(); // avoid duplicate complexType field references within a .net class
for (int i = 0; i < groupBase.Items.Count; i++)
{
decimal maxOccurs = groupBase.MaxOccurs;
if (groupBase.Items[i] is XmlSchemaElement)
{
XmlSchemaElement elementRef = (XmlSchemaElement)groupBase.Items[i];
XmlSchemaElement element = (XmlSchemaElement)schema.Elements[elementRef.QualifiedName];
if (element == null) element = elementRef;
maxOccurs = elementRef.MaxOccurs > maxOccurs ? elementRef.MaxOccurs : maxOccurs;
// for unqualified elements or attributes, element/attribute.QualifiedName.Namespace will be empty -- so use parentNamespace
string ns = element.QualifiedName.Namespace != "" ? element.QualifiedName.Namespace : parentNamespace;
if (element.ElementType is XmlSchemaComplexType && element.SchemaTypeName.Namespace != Globals.XSD_NAMESPACE)
{
// this will generate to a class in code
string dotnetTypeName = "";
XmlSchemaComplexType elementComplex = (XmlSchemaComplexType)element.ElementType;
// avoid duplicate references for the same type (allowed in xsd -- not in .net)
string fname = element.Name;
if (classReferencesAdded.ContainsKey(fname))
{
continue;
//fname = element.Name + "2";
//while (classReferencesAdded.ContainsKey(fname))
// fname = fname + "2";
}
else
classReferencesAdded.Add(element.Name, element.Name);
// The complex type is locally defined so a child class needs to be created.
if ((element == elementRef) && (schema.SchemaTypes[elementComplex.QualifiedName] == null))
{
// The complex type is locally defined. Locally scoped complexTypes may not be unique
string parentList = "";
foreach (string s in parentClassStack)
{
parentList += s;
}
dotnetTypeName = (string)globalQualifiedComplexTypeClasses[element.QualifiedName + parentList];
childClasses.Add(new ChildComplexType(elementComplex, element.Name, dotnetTypeName, ns, element.QualifiedName));
dotnetTypeName = LanguageBase.ReplaceInvalidChars(dotnetTypeName);
code.ClassComplexTypeFieldCode(outStream, element.Name, fname, dotnetTypeName, dotnetTypeName, className,
maxOccurs, 1, elementFormDefault, ns, element.IsNillable, false);
}
else // not a locally defined complexType
{
// The complexType is either globally defined at the <xsd:schema> level,
// or it's tied to a globally defined element. In the case of the
// globally defined complexType at the <xsd:schema> level, elementComplex.Name
// will not be null because the complexType will have name. In that case
// we use the complexType name for the class name.
string qualifiedTypeName = "";
if ((elementComplex.QualifiedName.Name == null || elementComplex.QualifiedName.Name == "") &&
(elementRef.QualifiedName.Name != null && elementRef.QualifiedName.Name != ""))
{
// global element
ns = elementRef.QualifiedName.Namespace; // element's referenced namespace is used
//qualifiedTypeName = (string) globalQualifiedComplexTypeClasses[elementRef.QualifiedName];
qualifiedTypeName = GlobalElementToClrMap(elementRef.QualifiedName);
dotnetTypeName = AddQualifiedNamespaceReference(element.Name, ns, parentNamespace, GlobalXsdType.Element);
}
else if ((schema.Elements[elementRef.QualifiedName] != null) && (elementComplex.QualifiedName.Name != null && elementComplex.QualifiedName.Name != ""))
{
// An element who's "ref" attribute points to a global typed element (name and type are set and has no schema children)
// use the ref in this case -- and not the type
ns = elementRef.QualifiedName.Namespace; // element's referenced namespace is used
//qualifiedTypeName = (string) globalQualifiedComplexTypeClasses[elementRef.QualifiedName];
qualifiedTypeName = GlobalElementToClrMap(elementRef.QualifiedName);
dotnetTypeName = AddQualifiedNamespaceReference(element.Name, ns, parentNamespace, GlobalXsdType.Element);
}
else if (elementRef.QualifiedName.Name != null && elementRef.QualifiedName.Name != "")
{
// named complexType
ns = parentNamespace; //elements of a "type" take their parent namespace. The children go into the "types" namespace.
qualifiedTypeName = (string)globalQualifiedComplexTypeClasses[elementComplex.QualifiedName];
dotnetTypeName = elementComplex.Name;
if (elementComplex.QualifiedName.Namespace != ns && elementComplex.QualifiedName.Namespace != null)
dotnetTypeName = AddQualifiedNamespaceReference(dotnetTypeName, elementComplex.QualifiedName.Namespace, parentNamespace, GlobalXsdType.ComplexType);
else
dotnetTypeName = AddQualifiedNamespaceReference(dotnetTypeName, ns, parentNamespace, GlobalXsdType.ComplexType);
}
else
{
//.........这里部分代码省略.........
示例15: ParseGroupBasePass1
/*
* Pass1. Collect info on classes, collections (List<> types), and any local enumerations.
*/
private void ParseGroupBasePass1(XmlSchemaGroupBase groupBase, String dotnetClassName, ArrayList childClasses, ArrayList parentClassStack, string parentNamespace, string currentNamespace)
{
for (int i = 0; i < groupBase.Items.Count; i++)
{
if (groupBase.Items[i] is XmlSchemaElement)
{
XmlSchemaElement elementRef = (XmlSchemaElement)groupBase.Items[i];
XmlSchemaElement element = (XmlSchemaElement)schema.Elements[elementRef.QualifiedName];
if (element == null) element = elementRef;
string ns = element.QualifiedName.Namespace != "" ? element.QualifiedName.Namespace : parentNamespace;
if (element.ElementType is XmlSchemaComplexType && element.SchemaTypeName.Namespace != Globals.XSD_NAMESPACE)
{
XmlSchemaComplexType elementComplex = (XmlSchemaComplexType)element.ElementType;
string childComplexTypeName = ""; // a nested complexType, who's name may not be unique in the schema
// The complex type is locally defined so a child class needs to be created.
if ((element == elementRef) && (schema.SchemaTypes[elementComplex.QualifiedName] == null))
{
childComplexTypeName = CalculateNestedChildTypeName(element.Name, globalComplexTypeClasses, parentClassStack);
childClasses.Add(new ChildComplexType(elementComplex, element.Name, childComplexTypeName, ns, element.QualifiedName));
globalComplexTypeClasses.Add(childComplexTypeName, childComplexTypeName);
// local complexType elements can repeat within a namespace
string parentList = "";
foreach (string s in parentClassStack)
{
parentList += s;
}
globalQualifiedComplexTypeClasses.Add(element.QualifiedName + parentList, childComplexTypeName);
}
// For "unbounded" types -- check to see if this fits the IEnumerator pattern. Collect support for IEnumerator here.
if (elementRef.MaxOccurs > 1 || groupBase.MaxOccurs > 1)
{
// If this is the only element in a contained ComplexType, and this element
// is unbounded, then we can support IEnumerator on the contained class
// so we can easilly enumerate through the contained child collection.
string enumerableClass = dotnetClassName;
if (childComplexTypeName != "")
enumerableClass = childComplexTypeName;
if (groupBase.Items.Count == 1 && !enumerableClasses.ContainsKey(enumerableClass))
{
// enumerable class
ArrayList values = new ArrayList();
values.Add(element.Name); //name
// type
if (childComplexTypeName != "")
{
values.Add(childComplexTypeName); // nested local complextype
}
else if ((schema.Elements[elementRef.QualifiedName] != null) && (elementComplex.Name != null && elementComplex.Name != ""))
{
string q = AddQualifiedNamespaceReference(element.Name, element.QualifiedName.Namespace, currentNamespace, GlobalXsdType.Element);
values.Add(q); //global element who's name and type are set
}
else if (elementComplex.Name != null && elementComplex.Name != "")
{
string q = AddQualifiedNamespaceReference(elementComplex.Name, elementComplex.QualifiedName.Namespace, currentNamespace, GlobalXsdType.ComplexType);
values.Add(q); // global named schema type
}
else
{
string q = AddQualifiedNamespaceReference(element.Name, element.QualifiedName.Namespace, currentNamespace, GlobalXsdType.Element);
values.Add(q); // global element complextype
}
enumerableClasses.Add(dotnetClassName, values);
}
}
// collect support for abstract classes
if (elementComplex.IsAbstract)
{
ArrayList abstractClasses = null;
if (classesReferencingAbstractTypes[dotnetClassName] == null)
{
abstractClasses = new ArrayList();
abstractClasses.Add(elementComplex.QualifiedName);
classesReferencingAbstractTypes.Add(dotnetClassName, abstractClasses);
}
else
{
abstractClasses = (ArrayList)classesReferencingAbstractTypes[dotnetClassName];
abstractClasses.Add(elementComplex.QualifiedName);
}
}
}
else
{
// not a ComplexType
string xsdTypeName = element.SchemaTypeName.Name;
string clrTypeName = code.FrameworkTypeMapping(xsdTypeName);
//.........这里部分代码省略.........