本文整理汇总了C#中System.Xml.Schema.XmlSchemaElement.AddAnnotation方法的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemaElement.AddAnnotation方法的具体用法?C# XmlSchemaElement.AddAnnotation怎么用?C# XmlSchemaElement.AddAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Schema.XmlSchemaElement
的用法示例。
在下文中一共展示了XmlSchemaElement.AddAnnotation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateSchemaTypeObjects
/// <summary>
/// Convert the property into a schema object
/// </summary>
public override void GenerateSchemaTypeObjects(PropertyInfo property, XmlSchemaType type, int level)
{
Debug.IndentLevel = level;
Debug.WriteLine("{0} {1} {2}", level, property.Name, type.Name);
var configPropertyAtts = GetAttributes<ConfigurationPropertyAttribute>(property);
if (configPropertyAtts.Length == 0)
return;
var configCollPropertyAtts = GetAttributes<ConfigurationCollectionAttribute>(property);
if (configCollPropertyAtts.Length == 0)
configCollPropertyAtts = GetAttributes<ConfigurationCollectionAttribute>(property.PropertyType);
if (configCollPropertyAtts.Length == 0)
return;
var configAttribute = configPropertyAtts[0];
var configCollAttribute = configCollPropertyAtts[0];
XmlSchemaComplexType ct;
var typeAlreadyInSchema = false;
if (Generator.ComplexMap.ContainsKey(property.PropertyType))
{
//already done the work
typeAlreadyInSchema = true;
ct = Generator.ComplexMap[property.PropertyType];
}
else
{
// got to generate a new one for the collection
ct = new XmlSchemaComplexType
{
Name = configAttribute.Name + "CT",
};
var seq = new XmlSchemaChoice
{
MinOccurs = 0,
MaxOccursString = "unbounded"
};
ct.Particle = seq;
Generator.ComplexMap.Add(property.PropertyType, ct);
Generator.Schema.Items.Add(ct);
}
var element = new XmlSchemaElement
{
Name = configAttribute.Name,
MinOccurs = configAttribute.IsRequired ? 1 : 0,
SchemaTypeName = new XmlQualifiedName(XmlHelper.PrependNamespaceAlias(ct.Name))
};
var pct = (XmlSchemaComplexType) type;
var items = ((XmlSchemaGroupBase) pct.Particle).Items;
if (items.OfType<XmlSchemaElement>().All(x => x.Name != element.Name))
items.Add(element);
// get all properties from the configuration object
foreach (var pi in GetProperties<ConfigurationPropertyAttribute>(property.PropertyType))
{
Debug.WriteLine("ConfigurationProperty: " + pi.Name);
var parser = TypeParserFactory.GetParser(Generator, pi);
parser.GenerateSchemaTypeObjects(pi, ct, level + 1);
}
// add the documentation
element.AddAnnotation(property, configPropertyAtts[0]);
// at this point the element has been added to the schema
// but we now need to add support for the child elements
if (!typeAlreadyInSchema)
{
AddCollectionChildren((XmlSchemaGroupBase) ct.Particle, configCollAttribute, level);
}
}
示例2: GenerateSchemaTypeObjects
/// <summary>
/// </summary>
public override void GenerateSchemaTypeObjects(PropertyInfo property, XmlSchemaType type, int level)
{
var atts = GetAttributes<ConfigurationPropertyAttribute>(property);
if (atts.Length == 0)
return;
XmlSchemaComplexType ct;
if (Generator.ComplexMap.ContainsKey(property.PropertyType))
{
//already done the work
ct = Generator.ComplexMap[property.PropertyType];
}
else
{
// got to generate a new one
ct = new XmlSchemaComplexType { Name = atts[0].Name + "CT" };
ct.AddAnnotation(property, null);
ct.CreateSchemaSequenceParticle();
Generator.ComplexMap.Add(property.PropertyType, ct);
Generator.Schema.Items.Add(ct);
// get all properties from the configuration object
var propertyInfos = GetProperties<ConfigurationPropertyAttribute>(property.PropertyType);
foreach (var pi in propertyInfos)
{
var parser = TypeParserFactory.GetParser(Generator, pi);
parser.GenerateSchemaTypeObjects(pi, ct, level + 1);
}
}
var element = new XmlSchemaElement
{
Name = atts[0].Name, // property.PropertyType.Name + "CT",
MinOccurs = atts[0].IsRequired ? 1 : 0,
SchemaTypeName = new XmlQualifiedName(XmlHelper.PrependNamespaceAlias(ct.Name))
};
var pct = (XmlSchemaComplexType) type;
((XmlSchemaGroupBase) pct.Particle).Items.Add(element);
// add the documentation
element.AddAnnotation(property, atts[0]);
}