Esempio n. 1
0
 private void ValidateTypeDef(TypeDef td, ValidationCtx ctx)
 {
     if (IsTypeDefined(td.Name)) return;
     if (ctx.ValidatedTypes.ContainsKey(td.Name)) return;
     ctx.ValidatedTypes.Add(td.Name, td);
     if (td is SimpleTypeDef)
     {
         return;
     }
     else if (td is StructDef)
     {
         StructDef sd = (StructDef)td;
         foreach (MemberDef md in sd.Members)
         {
             if (!IsTypeDefined(md.TypeName))
             {
                 if (!ctx.NewTypes.ContainsKey(md.TypeName))
                 {
                     throw new ApplicationException(string.Format("Member type ({0}) not defined for {1}.{2}", md.TypeName, sd.Name, md.Name));
                 }
                 TypeDef td2 = ctx.NewTypes[md.TypeName];
                 ValidateTypeDef(td2, ctx);
             }
         }
     }
     else if (td is EnumDef)
     {
         EnumDef ed = (EnumDef)td;
     }
     else throw new Exception();
 }
Esempio n. 2
0
 public void AddTypes(ICollection<TypeDef> types)
 {
     ValidationCtx ctx = new ValidationCtx();
     foreach (TypeDef sd in types)
     {
         if (IsTypeDefined(sd.Name)) throw new ApplicationException("Type already defined: " + sd.Name);
         ctx.NewTypes.Add(sd.Name, sd);
     }
     foreach (TypeDef sd in types)
     {
         ValidateTypeDef(sd, ctx);
     }
     foreach (TypeDef sd in types)
     {
         sd.ParentTypeSet = this;
         Types.Add(sd.Name, sd);
     }
 }
Esempio n. 3
0
 public static bool ValidateXml(XmlReader xr, XmlSchemaSet schemas, IList<XmlValidationMessage> messages)
 {
     ValidationCtx ctx = new ValidationCtx();
     XmlReaderSettings rs = new XmlReaderSettings();
     rs.ValidationType = ValidationType.Schema;
     rs.Schemas = schemas;
     rs.ValidationEventHandler += new ValidationEventHandler(ctx.ValidationEventHandler);
     XmlReader xrv = XmlReader.Create(xr, rs);
     while (xrv.Read())
     {
     }
     if (messages != null)
     {
         foreach (XmlValidationMessage msg in ctx.Messages)
         {
             messages.Add(msg);
         }
     }
     return !ctx.HasError;
 }