private ClrPropertyInfo BuildProperty(XmlSchemaAttribute attribute, bool fromBaseType, bool isNew) { string schemaName = attribute.QualifiedName.Name; string schemaNs = attribute.QualifiedName.Namespace; string propertyName = localSymbolTable.AddAttribute(attribute); Occurs attrPropertyOccurs = attribute.Use == XmlSchemaUse.Required ? Occurs.One : Occurs.ZeroOrOne; ClrPropertyInfo propertyInfo = new ClrPropertyInfo(propertyName, schemaNs, schemaName, attrPropertyOccurs); propertyInfo.Origin = SchemaOrigin.Attribute; propertyInfo.FromBaseType = fromBaseType; propertyInfo.IsNew = isNew; propertyInfo.VerifyRequired = configSettings.VerifyRequired; XmlSchemaSimpleType schemaType = attribute.AttributeSchemaType; var qName = schemaType.QualifiedName; if (qName.IsEmpty) { qName = attribute.QualifiedName; } // http://linqtoxsd.codeplex.com/WorkItem/View.aspx?WorkItemId=4106 ClrTypeReference typeRef = BuildTypeReference(schemaType, qName, false, true); propertyInfo.TypeReference = typeRef; Debug.Assert(schemaType.Datatype != null); SetFixedDefaultValue(attribute, propertyInfo); return(propertyInfo); }
private ClrPropertyInfo BuildProperty(XmlSchemaAttribute attribute, bool fromBaseType, bool isNew, ClrTypeInfo containingType = null) { string schemaName = attribute.QualifiedName.Name; string schemaNs = attribute.QualifiedName.Namespace; string propertyName = localSymbolTable.AddAttribute(attribute); Occurs attrPropertyOccurs = attribute.Use == XmlSchemaUse.Required ? Occurs.One : Occurs.ZeroOrOne; ClrPropertyInfo propertyInfo = new ClrPropertyInfo(propertyName, schemaNs, schemaName, attrPropertyOccurs); propertyInfo.Origin = SchemaOrigin.Attribute; propertyInfo.FromBaseType = fromBaseType; propertyInfo.IsNew = isNew; propertyInfo.VerifyRequired = configSettings.VerifyRequired; XmlSchemaSimpleType schemaType = attribute.AttributeSchemaType; var isInlineEnum = attribute.AttributeSchemaType.IsEnum() && attribute.AttributeSchemaType.IsDerivedByRestriction() && ((attribute.AttributeSchemaType.Content as XmlSchemaSimpleTypeRestriction)?.Facets .Cast <XmlSchemaObject>().Any() ?? false); var isAnonymous = !attribute.AttributeSchemaType.IsGlobal() && !attribute.AttributeSchemaType.IsBuiltInSimpleType(); var qName = schemaType.QualifiedName; if (qName.IsEmpty) { qName = attribute.QualifiedName; } // http://linqtoxsd.codeplex.com/WorkItem/View.aspx?WorkItemId=4106 ClrTypeReference typeRef = BuildTypeReference(schemaType, qName, isAnonymous, true); if (isInlineEnum && isAnonymous) { typeRef.Name += "Enum"; if (typeRef.ClrFullTypeName.IsNullOrEmpty()) { var typeScopedResolutionString = containingType?.GetNestedTypeScopedResolutionString(); if (typeScopedResolutionString.IsNullOrEmpty()) // if this is empty, then take the referencing element { var closestNamedParent = attribute.GetClosestNamedParent().GetPotentialName(); typeScopedResolutionString = closestNamedParent; } typeRef.UpdateClrFullTypeName(propertyInfo, typeScopedResolutionString); } } propertyInfo.TypeReference = typeRef; Debug.Assert(schemaType.Datatype != null); SetFixedDefaultValue(attribute, propertyInfo); return(propertyInfo); }