System.Xml.Schema.SchemaCollectionCompiler.CompileAttribute C# (CSharp) Method

CompileAttribute() private method

private CompileAttribute ( XmlSchemaAttribute xa ) : void
xa XmlSchemaAttribute
return void
         private void CompileAttribute(XmlSchemaAttribute xa) {
            if (xa.IsProcessing) {
                SendValidationEvent(Res.Sch_AttributeCircularRef, xa);
                return;
            }
            if (xa.AttDef != null) { //already compiled?
                return;
            }
            xa.IsProcessing = true;
            SchemaAttDef decl = null;
            try {
                if (!xa.RefName.IsEmpty) {
                    XmlSchemaAttribute a = (XmlSchemaAttribute)this.schema.Attributes[xa.RefName];
                    if (a == null) {
                        throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, xa.RefName.ToString(), xa);
                    }     
                    CompileAttribute(a);
                    if (a.AttDef == null) {
                        throw new XmlSchemaException(Res.Sch_RefInvalidAttribute, xa.RefName.ToString(), xa);
                    }
                    decl = a.AttDef.Clone();
                    if(decl.Datatype != null) {
                        if(a.FixedValue != null) {
                            if(xa.DefaultValue != null) {
                                throw new XmlSchemaException(Res.Sch_FixedDefaultInRef, xa.RefName.ToString(), xa);
                            }
                            else if(xa.FixedValue != null ) {
                                if (xa.FixedValue != a.FixedValue) {
                                    throw new XmlSchemaException(Res.Sch_FixedInRef, xa.RefName.ToString(), xa);
                                }
                            }
                            else {
                                decl.Presence = SchemaDeclBase.Use.Fixed; 
                                decl.DefaultValueRaw = decl.DefaultValueExpanded = a.FixedValue;
                                decl.DefaultValueTyped = decl.Datatype.ParseValue(decl.DefaultValueRaw, NameTable, new SchemaNamespaceManager(xa), true);
                            }
                        }
                        else if (a.DefaultValue != null) {
                            if(xa.DefaultValue == null && xa.FixedValue == null) {
                                decl.Presence = SchemaDeclBase.Use.Default; 
                                decl.DefaultValueRaw = decl.DefaultValueExpanded = a.DefaultValue;
                                decl.DefaultValueTyped = decl.Datatype.ParseValue(decl.DefaultValueRaw, NameTable, new SchemaNamespaceManager(xa), true);
                            }
                        }   
                    }
                    xa.SetAttributeType(a.AttributeSchemaType);
                }
                else {
                    decl = new SchemaAttDef(xa.QualifiedName, xa.Prefix);
                    if (xa.SchemaType != null) {
                        CompileSimpleType(xa.SchemaType);
                        xa.SetAttributeType(xa.SchemaType);
                        decl.SchemaType = xa.SchemaType;
                        decl.Datatype = xa.SchemaType.Datatype;
                    }
                    else if (!xa.SchemaTypeName.IsEmpty) {
                        XmlSchemaSimpleType simpleType = GetSimpleType(xa.SchemaTypeName);
                        if (simpleType != null) {
                            xa.SetAttributeType(simpleType);
                            decl.Datatype = simpleType.Datatype;
                            decl.SchemaType = simpleType;
                        }
                        else {
                            throw new XmlSchemaException(Res.Sch_UndeclaredSimpleType, xa.SchemaTypeName.ToString(), xa);   
                        }
                    }
                    else {
                        decl.SchemaType = DatatypeImplementation.AnySimpleType;
                        decl.Datatype = DatatypeImplementation.AnySimpleType.Datatype;
                        xa.SetAttributeType(DatatypeImplementation.AnySimpleType);
                    }
                }
                if (decl.Datatype != null) {
                    decl.Datatype.VerifySchemaValid(this.schema.Notations, xa);
                }
                if (xa.DefaultValue != null || xa.FixedValue != null) {
                    if (xa.DefaultValue != null) {
                        decl.Presence = SchemaDeclBase.Use.Default; 
                        decl.DefaultValueRaw = decl.DefaultValueExpanded = xa.DefaultValue;
                    }
                    else {
                        decl.Presence = SchemaDeclBase.Use.Fixed; 
                        decl.DefaultValueRaw = decl.DefaultValueExpanded = xa.FixedValue;
                    }
                    if(decl.Datatype != null) {
                        decl.DefaultValueTyped = decl.Datatype.ParseValue(decl.DefaultValueRaw, NameTable, new SchemaNamespaceManager(xa), true);
                    }
                }
                else {
                    switch (xa.Use) {
                        case XmlSchemaUse.None: 
                        case XmlSchemaUse.Optional: 
                            decl.Presence = SchemaDeclBase.Use.Implied; 
                            break;
                        case XmlSchemaUse.Required: 
                            decl.Presence = SchemaDeclBase.Use.Required; 
                            break;
                        case XmlSchemaUse.Prohibited:
                            break;
                    }
                }
                decl.SchemaAttribute = xa; //So this is available for PSVI
                xa.AttDef = decl;
            } 
            catch (XmlSchemaException e) {
                if (e.SourceSchemaObject == null) {
                    e.SetSource(xa);
                }
                SendValidationEvent(e);
                xa.AttDef = SchemaAttDef.Empty;
            } 
            finally {
                xa.IsProcessing = false;
            }
        }