// PUBLIC METHODS /////////////////////////////////////////////////// #region IConfigurationCollection Implementation public void Add <TComplex>(ComplexTypeBuilder <TComplex> complexTypeBuilder) { Contract.Requires(complexTypeBuilder != null); this.ComplexTypeBuilderDictionary = this.ComplexTypeBuilderDictionary ?? new Dictionary <Type, object>(); var clrComplexType = typeof(TComplex); this.ComplexTypeBuilderDictionary.Add(clrComplexType, complexTypeBuilder); }
protected new void OneTimeSetUp() { NodeIdCount = 0; Module = new AssemblyModule(); ComplexTypeBuilder = new ComplexTypeBuilder( Module, Namespaces.OpcUaEncoderTests, 3, "Tests" ); }
// INTERNAL METHODS ///////////////////////////////////////////////// #region Internal Methods internal IComplexTypeBuilder GetOrAddComplexTypeBuilder <TComplex>() { this.ComplexTypeBuilderDictionary = this.ComplexTypeBuilderDictionary ?? new Dictionary <Type, object>(); var clrComplexType = typeof(TComplex); object complexTypeBuilder; if (this.ComplexTypeBuilderDictionary.TryGetValue(clrComplexType, out complexTypeBuilder)) { return((IComplexTypeBuilder)complexTypeBuilder); } complexTypeBuilder = new ComplexTypeBuilder <TComplex>(); this.ComplexTypeBuilderDictionary.Add(clrComplexType, complexTypeBuilder); return((IComplexTypeBuilder)complexTypeBuilder); }
public static ComplexTypeBuilder Start(string name) { var builder = new ComplexTypeBuilder(name); return builder; }
void TraverseParticle(XmlSchemaParticle particle, ComplexTypeBuilder complexTypeBuilder) { debug("Traversing Particle"); if (particle is XmlSchemaElement) { XmlSchemaElement elem = particle as XmlSchemaElement; if (elem.RefName.IsEmpty) { debug("Empty refname"); XmlSchemaComplexType complexType = elem.ElementSchemaType as XmlSchemaComplexType; if (complexType != null) { debug("Content Name: " + complexType.QualifiedName); // TODO: Do we need tto match on name as well as namespace? Func<KeyValuePair<string, ComplexType>, bool> existingCTPredicate = _ => _.Key == complexType.QualifiedName.Namespace && _.Value.Name == complexType.QualifiedName.Name; var isExisting = ComplexTypes.Any(existingCTPredicate); debugExistingComplexTypes(complexType); if (isExisting) { var existingComplexType = ComplexTypes.Single(existingCTPredicate); debug("Found existing complex type " + existingComplexType.Value.Name); complexTypeBuilder.AddComplexType(elem.Name, existingComplexType.Value, existingComplexType.Key); } else { TraverseParticle(complexType.ContentTypeParticle, complexTypeBuilder); } } else { debug("Trying simple type"); var xmlSchemaSimpleType = elem.ElementSchemaType != null ? elem.ElementSchemaType as XmlSchemaSimpleType : elem.SchemaType as XmlSchemaSimpleType; debug("EST" + elem.ElementSchemaType); debug("ST" + elem.SchemaType); if (xmlSchemaSimpleType != null && xmlSchemaSimpleType.Datatype != null) { debug("Cast successfull"); if (xmlSchemaSimpleType.QualifiedName == null) { throw new NotImplementedException("No qualified name for simple type"); } debug("Adding simple type"); complexTypeBuilder.AddProperty(elem.Name, XsdTypeEvaluator.OverrideCLRType(xmlSchemaSimpleType.Datatype.ValueType, xmlSchemaSimpleType.QualifiedName.ToString())); } else { debug("Couldn't cast to simple type: "); throw new NotImplementedException("Haven't implemented case of not having datatype. " + elem.ElementSchemaType.GetType().Name); } } } else { throw new NotImplementedException("Haven't dealt with filled refname"); } } else if (particle is XmlSchemaGroupBase) { //xs:all, xs:choice, xs:sequence XmlSchemaGroupBase baseParticle = particle as XmlSchemaGroupBase; foreach (XmlSchemaParticle subParticle in baseParticle.Items) { if (subParticle is XmlSchemaGroupBase || subParticle is XmlSchemaElement) { debug("Sub particle found: " + subParticle.GetType()); TraverseParticle(subParticle, complexTypeBuilder); } } } else { debug("Current stack: " + new System.Diagnostics.StackTrace()); debug(DebugUtility.GetProperties(particle)); throw new NotImplementedException("Particle is not group of element"); } }