internal XmlSchemaInfo (IXmlSchemaInfo info) { isDefault = info.IsDefault; isNil = info.IsNil; memberType = info.MemberType; attr = info.SchemaAttribute; elem = info.SchemaElement; type = info.SchemaType; validity = info.Validity; }
static XmlQualifiedName StaticGetSchema(XmlSchemaSet schemas) { XmlSchemaType schemaType = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String); return(schemaType.QualifiedName); }
public void Serialize(Type type, object graph) { if (graph == null) { writer.WriteAttributeString("i", "nil", XmlSchema.InstanceNamespace, "true"); } else if (type == typeof(XmlElement)) { ((XmlElement)graph).WriteTo(Writer); } else if (type == typeof(XmlNode [])) { foreach (var xn in (XmlNode [])graph) { xn.WriteTo(Writer); } } else { QName resolvedQName = null; if (resolver != null) { XmlDictionaryString rname, rns; if (resolver.TryResolveType(graph != null ? graph.GetType() : typeof(object), type, default_resolver, out rname, out rns)) { resolvedQName = new QName(rname.Value, rns.Value); } } Type actualType = graph.GetType(); SerializationMap map; map = types.FindUserMap(actualType); // For some collection types, the actual type does not matter. So get nominal serialization type instead. // (The code below also covers the lines above, but I don't remove above lines to avoid extra search cost.) if (map == null) { // FIXME: not sure if type.IsInterface is the correct condition to determine whether items are serialized with i:type or not. (e.g. bug #675144 server response). actualType = types.GetSerializedType(type.IsInterface ? type : actualType); map = types.FindUserMap(actualType); } // If it is still unknown, then register it. if (map == null) { types.Add(actualType); map = types.FindUserMap(actualType); } bool explicityType = false; if (type != actualType) { // Check if underlying type of Nullable, mismatch the current type. if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>)) { explicityType = (type.GetGenericArguments() [0] != actualType); } else { explicityType = true; } } if (explicityType && (map == null || map.OutputXsiType)) { QName qname = resolvedQName ?? types.GetXmlName(actualType); string name = qname.Name; string ns = qname.Namespace; if (qname == QName.Empty) { name = XmlConvert.EncodeLocalName(actualType.Name); ns = KnownTypeCollection.DefaultClrNamespaceBase + actualType.Namespace; } else if (XmlSchemaType.GetBuiltInSimpleType(new QName(qname.Name, XmlSchema.Namespace)) != null) { ns = XmlSchema.Namespace; } if (writer.LookupPrefix(ns) == null) // it goes first (extraneous, but it makes att order compatible) { writer.WriteXmlnsAttribute(null, ns); } writer.WriteStartAttribute("i", "type", XmlSchema.InstanceNamespace); writer.WriteQualifiedName(name, ns); writer.WriteEndAttribute(); } QName predef = KnownTypeCollection.GetPredefinedTypeName(actualType); if (predef != QName.Empty) { SerializePrimitive(type, graph, predef); } else { map.Serialize(graph, this); } } }
/// <summary> /// Given a Wsdl Message part element returns the type refered to by the message part. /// </summary> /// <param name="message">A Wsdl Message element.</param> /// <returns>The name of the type used by the message element.</returns> internal static string GetMessageTypeName(ServiceDescription svcDesc, Message message) { // If there are no message part(s) the message is void so return null if (message.Parts.Count == 0) { return(null); } // If the message contains a type reference instead of an element reference find the schema type XmlSchemaType type = null; string typeName = null; string elementName = null; if (message.Parts[0].Element == null || message.Parts[0].Element.IsEmpty) { type = FindSchemaType(svcDesc, message.Parts[0].Type.Name, message.Parts[0].Type.Namespace); if (type == null || type.TypeCode == XmlTypeCode.None) { return(message.Parts[0].Type.Name); } typeName = message.Parts[0].Type.Name; } else { XmlSchemaElement element = FindSchemaElement(svcDesc, message.Parts[0].Element.Name, message.Parts[0].Element.Namespace); if (element == null || element.SchemaTypeName == null || element.SchemaTypeName.Name == "") { return(message.Parts[0].Element.Name); } elementName = element.QualifiedName.Name; type = element.ElementSchemaType; typeName = element.SchemaTypeName.Name; } // If this is a complex type return the element type name if (type is XmlSchemaComplexType) { return(elementName == null ? type.Name : elementName); } bool IsEnum = false; if (type.DerivedBy == XmlSchemaDerivationMethod.Restriction) { XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)((XmlSchemaSimpleType)type).Content; foreach (XmlSchemaFacet facet in restriction.Facets) { if (facet is XmlSchemaEnumerationFacet) { IsEnum = true; break; } } } // If this is a simple type with enumeration restrictions, return the type name. // Else return the clr type name if this is a native type or the simple type name if this is not a native type. if (IsEnum == true) { return(typeName); } else { string clrTypeName = CodeGenUtils.GetClrType(type.TypeCode); clrTypeName = clrTypeName != null && clrTypeName.IndexOf("System.") == 0 ? clrTypeName.Substring(7) : clrTypeName; if (clrTypeName == null) { return(typeName); } else if (type.Datatype.ValueType.IsArray) { string typeSuffix = (clrTypeName.Length > 2 && clrTypeName.Substring(clrTypeName.Length - 2) == "[]") ? "" : "[]"; return(clrTypeName + typeSuffix); } else { return(clrTypeName); } } }
internal static bool IsSpecialXmlType(Type type, out XmlQualifiedName typeName, out XmlSchemaType xsdType, out bool hasRoot) { xsdType = null; hasRoot = true; if (type == Globals.TypeOfXmlElement || type == Globals.TypeOfXmlNodeArray) { string name = null; if (type == Globals.TypeOfXmlElement) { xsdType = CreateAnyElementType(); name = "XmlElement"; hasRoot = false; } else { xsdType = CreateAnyType(); name = "ArrayOfXmlNode"; hasRoot = true; } typeName = new XmlQualifiedName(name, DataContract.GetDefaultStableNamespace(type)); return(true); } typeName = null; return(false); }
internal static void GetXmlTypeInfo(Type type, out XmlQualifiedName stableName, out XmlSchemaType xsdType, out bool hasRoot) { if (IsSpecialXmlType(type, out stableName, out xsdType, out hasRoot)) { return; } XmlSchemaSet schemas = new XmlSchemaSet { XmlResolver = null }; InvokeSchemaProviderMethod(type, schemas, out stableName, out xsdType, out hasRoot); if (stableName.Name == null || stableName.Name.Length == 0) { throw Compat.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidXmlDataContractName, DataContract.GetClrTypeFullName(type)))); } }
private ClrPropertyInfo BuildComplexTypeTextProperty(XmlSchemaElement parentElement, XmlSchemaComplexType schemaType) { Debug.Assert(schemaType != null); Debug.Assert(schemaType.GetContentType() == XmlSchemaContentType.TextOnly); ClrPropertyInfo textProperty = new ClrPropertyInfo(Constants.SInnerTypePropertyName, string.Empty, Constants.SInnerTypePropertyName, Occurs.One, configSettings); textProperty.Origin = SchemaOrigin.Text; ClrTypeReference typeRef = null; bool anonymous = false; //Could be derived by restriction or extension //If first time extension, make the base simple type as the type reference XmlSchemaType baseType = schemaType.BaseXmlSchemaType; if (baseType is XmlSchemaSimpleType) { typeRef = BuildTypeReference(baseType, baseType.QualifiedName, false, true); anonymous = false; if (!textPropInheritanceTracker.ContainsKey(schemaType)) { textPropInheritanceTracker.Add(schemaType, textProperty); } } else if (schemaType.HasFacetRestrictions()) { //Derived by restriction, represents the content type with restrictions as a local type //Make the base simple type as the type reference so that we know if it is a list, union or atomic XmlSchemaSimpleType st = schemaType.GetBaseSimpleType(); Debug.Assert(st != null); typeRef = BuildTypeReference(st, st.QualifiedName, true, true); typeRef.Validate = true; anonymous = true; //Also get its base complex type and see if we need to override the content property ClrPropertyInfo baseProp = null; if (textPropInheritanceTracker.TryGetValue(baseType, out baseProp)) { textProperty.IsOverride = true; if (!baseProp.IsOverride) { baseProp.IsVirtual = true; } } } else { return(null); } if (anonymous) { //anonymous type, fixed up the name later, treat complex type with restrictions as an anonymous type //because we need to generate a type to encapsualte these restrictions if (parentElement != null) { string identifier = localSymbolTable.AddLocalElement(parentElement); localSymbolTable.AddAnonymousType(identifier, parentElement, typeRef); } else { localSymbolTable.AddComplexRestrictedContentType(schemaType, typeRef); } } textProperty.TypeReference = typeRef; return(textProperty); }
public void Init(XmlSchemaType type) { Init(type.QualifiedName.Name); }
/// <summary> /// Constructor /// </summary> /// <param name="InNameToTask">Mapping of task name to information about how to construct it</param> public ScriptSchema(Dictionary <string, ScriptTask> InNameToTask) { NameToTask = InNameToTask; // Create a lookup from standard types to their qualified names Dictionary <Type, XmlQualifiedName> TypeToSchemaTypeName = new Dictionary <Type, XmlQualifiedName>(); TypeToSchemaTypeName.Add(typeof(String), GetQualifiedTypeName(ScriptSchemaStandardType.BalancedString)); TypeToSchemaTypeName.Add(typeof(Boolean), GetQualifiedTypeName(ScriptSchemaStandardType.Boolean)); TypeToSchemaTypeName.Add(typeof(Int32), GetQualifiedTypeName(ScriptSchemaStandardType.Integer)); // Create all the custom user types, and add them to the qualified name lookup List <XmlSchemaType> UserTypes = new List <XmlSchemaType>(); foreach (Type Type in NameToTask.Values.SelectMany(x => x.NameToParameter.Values).Select(x => x.ValueType)) { if (!TypeToSchemaTypeName.ContainsKey(Type)) { string Name = Type.Name + "UserType"; XmlSchemaType SchemaType = CreateUserType(Name, Type); UserTypes.Add(SchemaType); TypeToSchemaTypeName.Add(Type, new XmlQualifiedName(Name, NamespaceURI)); } } // Create all the task types Dictionary <string, XmlSchemaComplexType> TaskNameToType = new Dictionary <string, XmlSchemaComplexType>(); foreach (ScriptTask Task in NameToTask.Values) { XmlSchemaComplexType TaskType = new XmlSchemaComplexType(); TaskType.Name = Task.Name + "TaskType"; foreach (ScriptTaskParameter Parameter in Task.NameToParameter.Values) { XmlQualifiedName SchemaTypeName = GetQualifiedTypeName(Parameter.ValidationType); if (SchemaTypeName == null) { SchemaTypeName = TypeToSchemaTypeName[Parameter.ValueType]; } TaskType.Attributes.Add(CreateSchemaAttribute(Parameter.Name, SchemaTypeName, Parameter.bOptional? XmlSchemaUse.Optional : XmlSchemaUse.Required)); } TaskType.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional)); TaskNameToType.Add(Task.Name, TaskType); } // Create the schema object XmlSchema NewSchema = new XmlSchema(); NewSchema.TargetNamespace = NamespaceURI; NewSchema.ElementFormDefault = XmlSchemaForm.Qualified; NewSchema.Items.Add(CreateSchemaElement(RootElementName, ScriptSchemaStandardType.Graph)); NewSchema.Items.Add(CreateGraphType()); NewSchema.Items.Add(CreateTriggerType()); NewSchema.Items.Add(CreateTriggerBodyType()); NewSchema.Items.Add(CreateAgentType()); NewSchema.Items.Add(CreateAgentBodyType()); NewSchema.Items.Add(CreateNodeType()); NewSchema.Items.Add(CreateNodeBodyType(TaskNameToType)); NewSchema.Items.Add(CreateAggregateType()); NewSchema.Items.Add(CreateReportType()); NewSchema.Items.Add(CreateBadgeType()); NewSchema.Items.Add(CreateNotifyType()); NewSchema.Items.Add(CreateIncludeType()); NewSchema.Items.Add(CreateOptionType()); NewSchema.Items.Add(CreateEnvVarType()); NewSchema.Items.Add(CreatePropertyType()); NewSchema.Items.Add(CreateDiagnosticType(ScriptSchemaStandardType.Warning)); NewSchema.Items.Add(CreateDiagnosticType(ScriptSchemaStandardType.Error)); NewSchema.Items.Add(CreateSimpleTypeFromRegex(GetTypeName(ScriptSchemaStandardType.Name), "(" + NamePattern + "|" + StringWithPropertiesPattern + ")")); NewSchema.Items.Add(CreateSimpleTypeFromRegex(GetTypeName(ScriptSchemaStandardType.NameList), "(" + NameListPattern + "|" + StringWithPropertiesPattern + ")")); NewSchema.Items.Add(CreateSimpleTypeFromRegex(GetTypeName(ScriptSchemaStandardType.Tag), "(" + TagPattern + "|" + StringWithPropertiesPattern + ")")); NewSchema.Items.Add(CreateSimpleTypeFromRegex(GetTypeName(ScriptSchemaStandardType.TagList), "(" + TagListPattern + "|" + StringWithPropertiesPattern + ")")); NewSchema.Items.Add(CreateSimpleTypeFromRegex(GetTypeName(ScriptSchemaStandardType.NameOrTag), "(" + NameOrTagPattern + "|" + StringWithPropertiesPattern + ")")); NewSchema.Items.Add(CreateSimpleTypeFromRegex(GetTypeName(ScriptSchemaStandardType.NameOrTagList), "(" + NameOrTagListPattern + "|" + StringWithPropertiesPattern + ")")); NewSchema.Items.Add(CreateSimpleTypeFromRegex(GetTypeName(ScriptSchemaStandardType.QualifiedName), "(" + QualifiedNamePattern + "|" + StringWithPropertiesPattern + ")")); NewSchema.Items.Add(CreateSimpleTypeFromRegex(GetTypeName(ScriptSchemaStandardType.BalancedString), BalancedStringPattern)); NewSchema.Items.Add(CreateSimpleTypeFromRegex(GetTypeName(ScriptSchemaStandardType.Boolean), "(" + "true" + "|" + "false" + "|" + StringWithPropertiesPattern + ")")); NewSchema.Items.Add(CreateSimpleTypeFromRegex(GetTypeName(ScriptSchemaStandardType.Integer), "(" + "(-?[1-9][0-9]*|0)" + "|" + StringWithPropertiesPattern + ")")); foreach (XmlSchemaComplexType Type in TaskNameToType.Values) { NewSchema.Items.Add(Type); } foreach (XmlSchemaSimpleType Type in UserTypes) { NewSchema.Items.Add(Type); } // Now that we've finished, compile it and store it to the class XmlSchemaSet NewSchemaSet = new XmlSchemaSet(); NewSchemaSet.Add(NewSchema); NewSchemaSet.Compile(); foreach (XmlSchema NewCompiledSchema in NewSchemaSet.Schemas()) { CompiledSchema = NewCompiledSchema; } }
static void AddElementToXmlSchema(IUxmlFactory factory, SchemaInfo schemaInfo, XmlSchemaType type) { XmlSchemaElement element = new XmlSchemaElement(); element.Name = factory.uxmlName; if (type != null) { element.SchemaTypeName = new XmlQualifiedName(type.Name, factory.uxmlNamespace); } if (factory.substituteForTypeName != String.Empty) { element.SubstitutionGroup = new XmlQualifiedName(factory.substituteForTypeName, factory.substituteForTypeNamespace); } schemaInfo.schema.Items.Add(element); }
/// <summary> /// Creates an XML schema element for reading a value of the given type /// </summary> /// <param name="Name">Name of the field</param> /// <param name="Type">Type of the field</param> /// <returns>New schema element representing the field</returns> static XmlSchemaElement CreateSchemaFieldElement(string Name, Type Type) { XmlSchemaElement Element = new XmlSchemaElement(); Element.Name = Name; Element.MinOccurs = 0; Element.MaxOccurs = 1; if (Type == typeof(string)) { Element.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).QualifiedName; } else if (Type == typeof(bool)) { Element.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Boolean).QualifiedName; } else if (Type == typeof(int)) { Element.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Int).QualifiedName; } else if (Type == typeof(float)) { Element.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Float).QualifiedName; } else if (Type == typeof(double)) { Element.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Double).QualifiedName; } else if (Type.IsEnum) { XmlSchemaSimpleTypeRestriction Restriction = new XmlSchemaSimpleTypeRestriction(); Restriction.BaseTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).QualifiedName; foreach (string EnumName in Enum.GetNames(Type)) { XmlSchemaEnumerationFacet Facet = new XmlSchemaEnumerationFacet(); Facet.Value = EnumName; Restriction.Facets.Add(Facet); } XmlSchemaSimpleType EnumType = new XmlSchemaSimpleType(); EnumType.Content = Restriction; Element.SchemaType = EnumType; } else if (Type == typeof(string[])) { XmlSchemaElement ItemElement = new XmlSchemaElement(); ItemElement.Name = "Item"; ItemElement.SchemaTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).QualifiedName; ItemElement.MinOccurs = 0; ItemElement.MaxOccursString = "unbounded"; XmlSchemaSequence Sequence = new XmlSchemaSequence(); Sequence.Items.Add(ItemElement); XmlSchemaComplexType ArrayType = new XmlSchemaComplexType(); ArrayType.Particle = Sequence; Element.SchemaType = ArrayType; } else { throw new Exception("Unsupported field type for XmlConfigFile attribute"); } return(Element); }
private void RetrieveSerializableSchema() { if (_needSchema) { _needSchema = false; if (_getSchemaMethod != null) { // get the type info if (_schemas == null) { _schemas = new XmlSchemaSet(); } object typeInfo = _getSchemaMethod.Invoke(null, new object[] { _schemas }); _xsiType = XmlQualifiedName.Empty; if (typeInfo != null) { if (typeof(XmlSchemaType).IsAssignableFrom(_getSchemaMethod.ReturnType)) { _xsdType = (XmlSchemaType)typeInfo; // check if type is named _xsiType = _xsdType.QualifiedName; } else if (typeof(XmlQualifiedName).IsAssignableFrom(_getSchemaMethod.ReturnType)) { _xsiType = (XmlQualifiedName)typeInfo; if (_xsiType.IsEmpty) { throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaEmptyTypeName, _type.FullName, _getSchemaMethod.Name)); } } else { throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaMethodReturnType, _type.Name, _getSchemaMethod.Name, typeof(XmlSchemaProviderAttribute).Name, typeof(XmlQualifiedName).FullName)); } } else { _any = true; } // make sure that user-specified schemas are valid _schemas.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackWithErrorCode); _schemas.Compile(); // at this point we verified that the information returned by the IXmlSerializable is valid // Now check to see if the type was referenced before: // UNDONE check for the duplcate types if (!_xsiType.IsEmpty) { // try to find the type in the schemas collection if (_xsiType.Namespace != XmlSchema.Namespace) { ArrayList srcSchemas = (ArrayList)_schemas.Schemas(_xsiType.Namespace); if (srcSchemas.Count == 0) { throw new InvalidOperationException(SR.Format(SR.XmlMissingSchema, _xsiType.Namespace)); } if (srcSchemas.Count > 1) { throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaInclude, _xsiType.Namespace, _getSchemaMethod.DeclaringType.FullName, _getSchemaMethod.Name)); } XmlSchema s = (XmlSchema)srcSchemas[0]; if (s == null) { throw new InvalidOperationException(SR.Format(SR.XmlMissingSchema, _xsiType.Namespace)); } _xsdType = (XmlSchemaType)s.SchemaTypes[_xsiType]; if (_xsdType == null) { throw new InvalidOperationException(SR.Format(SR.XmlGetSchemaTypeMissing, _getSchemaMethod.DeclaringType.FullName, _getSchemaMethod.Name, _xsiType.Name, _xsiType.Namespace)); } _xsdType = _xsdType.Redefined != null ? _xsdType.Redefined : _xsdType; } } } else { IXmlSerializable serializable = (IXmlSerializable)Activator.CreateInstance(_type); _schema = serializable.GetSchema(); if (_schema != null) { if (_schema.Id == null || _schema.Id.Length == 0) { throw new InvalidOperationException(SR.Format(SR.XmlSerializableNameMissing1, _type.FullName)); } } } } }
public virtual void EndProcessing(XmlSchemaType obj) { }
public virtual bool StartProcessing(XmlSchemaType obj) { return(true); }
public static bool IsDerivedFrom(XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except) { }
public static XmlQualifiedName GetQualifiedName(this XmlSchemaType schemaType) { return(schemaType.QualifiedName.IsEmpty ? schemaType.BaseXmlSchemaType.QualifiedName : schemaType.QualifiedName); }
internal TypeDesc(System.Type type, bool isXsdType, XmlSchemaType dataType, string formatterName, TypeFlags flags) : this(type.Name, type.FullName, dataType, TypeKind.Primitive, null, flags, formatterName) { this.isXsdType = isXsdType; this.type = type; }
internal void ElementsToTypes() { bool isRoot = false; int rootElementsCount = schemas.GlobalElements.Count; foreach (XmlSchemaElement elem in schemas.GlobalElements.Values) { SymbolEntry symbol = symbolTable.AddElement(elem); XmlSchemaType schemaType = elem.ElementSchemaType; string xsdNamespace = elem.QualifiedName.Namespace; ClrTypeInfo typeInfo = null; XmlSchemaElement headElement = null; if (!elem.SubstitutionGroup.IsEmpty) { headElement = (XmlSchemaElement)schemas.GlobalElements[elem.SubstitutionGroup]; } if (schemaType.IsGlobal()) { //Global elem with global type, generate wrapper class for the element bool hasBaseContentType = headElement != null && headElement.ElementSchemaType == schemaType; ClrWrapperTypeInfo wtypeInfo = new ClrWrapperTypeInfo(hasBaseContentType); ClrTypeReference typeDef = BuildTypeReference(schemaType, schemaType.QualifiedName, false, true); //Save the fixed/default value of the element wtypeInfo.InnerType = typeDef; typeInfo = wtypeInfo; typeInfo.baseType = headElement; //If element is member of substitutionGroup, add derivation step } else { ClrContentTypeInfo ctypeInfo = new ClrContentTypeInfo(); localSymbolTable.Init(symbol.identifierName); ctypeInfo.baseType = headElement; //If element is member of substitutionGroup, add derivation step BuildProperties(elem, schemaType, ctypeInfo); BuildNestedTypes(ctypeInfo); typeInfo = ctypeInfo; } if (!isRoot) { if (rootElementsCount == 1 || CheckUnhandledAttributes(elem)) { typeInfo.IsRoot = true; isRoot = true; } } typeInfo.IsSubstitutionHead = IsSubstitutionGroupHead(elem) != null; typeInfo.IsAbstract = elem.IsAbstract; typeInfo.clrtypeName = symbol.identifierName; typeInfo.clrtypeNs = symbol.clrNamespace; typeInfo.schemaName = symbol.symbolName; typeInfo.schemaNs = xsdNamespace; typeInfo.typeOrigin = SchemaOrigin.Element; BuildAnnotationInformation(typeInfo, schemaType); binding.Types.Add(typeInfo); } }
internal TypeDesc(string name, string fullName, XmlSchemaType dataType, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags) : this(name, fullName, dataType, kind, baseTypeDesc, flags, null) { }
private ClrPropertyInfo BuildProperty(XmlSchemaElement elem, bool fromBaseType) { string identifierName = localSymbolTable.AddLocalElement(elem); XmlSchemaType schemaType = elem.ElementSchemaType; XmlQualifiedName schemaTypeName = schemaType.QualifiedName; string schemaName = elem.QualifiedName.Name; string schemaNs = elem.QualifiedName.Namespace; string clrNs = elem.FormResolved() == XmlSchemaForm.Qualified ? configSettings.GetClrNamespace(schemaNs) : string.Empty; SchemaOrigin typeRefOrigin = SchemaOrigin.Fragment; bool isTypeRef = false; bool anonymousType = schemaTypeName.IsEmpty ? true : false; XmlSchemaObject schemaObject = schemaType; ArrayList substitutionMembers = null; if (elem.IsGlobal()) { substitutionMembers = IsSubstitutionGroupHead(elem); schemaTypeName = elem.QualifiedName; isTypeRef = true; typeRefOrigin = SchemaOrigin.Element; schemaObject = schemas.GlobalElements [schemaTypeName]; //For ref, get the element decl SOM object, as nameMappings are keyed off the SOM object anonymousType = false; } ClrTypeReference typeRef = BuildTypeReference(schemaObject, schemaTypeName, anonymousType, true); typeRef.Origin = typeRefOrigin; typeRef.IsTypeRef = isTypeRef; if (anonymousType && !fromBaseType) { //to fixup later. localSymbolTable.AddAnonymousType(identifierName, elem, typeRef); } ClrPropertyInfo propertyInfo = new ClrPropertyInfo(identifierName, schemaNs, schemaName, GetOccurence(elem), configSettings); propertyInfo.Origin = SchemaOrigin.Element; propertyInfo.FromBaseType = fromBaseType; propertyInfo.TypeReference = typeRef; propertyInfo.ClrNamespace = clrNs; //SetFixedDefaultValue(elem, propertyInfo); if (substitutionMembers != null) { propertyInfo.SubstitutionMembers = substitutionMembers; } //BuildAnnotationInformation(propertyInfo, elem); return(propertyInfo); //Place it in the element's namespace, maybe element's parent type's namespace? }
/// <summary> /// Convert from the Clr type of "value" to the default Clr type that ILGen uses to represent the xml type, using /// the conversion rules of the xml type. /// </summary> internal object ChangeTypeXsltResult(XmlQueryType xmlType, object value) { if (value == null) { throw new XslTransformException(SR.Xslt_ItemNull, string.Empty); } switch (xmlType.TypeCode) { case XmlTypeCode.String: if (value.GetType() == XsltConvert.DateTimeType) { value = XsltConvert.ToString((DateTime)value); } break; case XmlTypeCode.Double: if (value.GetType() != XsltConvert.DoubleType) { value = ((IConvertible)value).ToDouble(null); } break; case XmlTypeCode.Node: if (!xmlType.IsSingleton) { XPathArrayIterator iter = value as XPathArrayIterator; // Special-case XPathArrayIterator in order to avoid copies if (iter != null && iter.AsList is XmlQueryNodeSequence) { value = iter.AsList as XmlQueryNodeSequence; } else { // Iterate over list and ensure it only contains nodes XmlQueryNodeSequence seq = new XmlQueryNodeSequence(); IList list = value as IList; if (list != null) { for (int i = 0; i < list.Count; i++) { seq.Add(EnsureNavigator(list[i])); } } else { foreach (object o in (IEnumerable)value) { seq.Add(EnsureNavigator(o)); } } value = seq; } // Always sort node-set by document order value = ((XmlQueryNodeSequence)value).DocOrderDistinct(_docOrderCmp); } break; case XmlTypeCode.Item: { Type sourceType = value.GetType(); IXPathNavigable navigable; // If static type is item, then infer type based on dynamic value switch (XsltConvert.InferXsltType(sourceType).TypeCode) { case XmlTypeCode.Boolean: value = new XmlQueryItemSequence(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Boolean), value)); break; case XmlTypeCode.Double: value = new XmlQueryItemSequence(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Double), ((IConvertible)value).ToDouble(null))); break; case XmlTypeCode.String: if (sourceType == XsltConvert.DateTimeType) { value = new XmlQueryItemSequence(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String), XsltConvert.ToString((DateTime)value))); } else { value = new XmlQueryItemSequence(new XmlAtomicValue(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String), value)); } break; case XmlTypeCode.Node: // Support XPathNavigator[] value = ChangeTypeXsltResult(XmlQueryTypeFactory.NodeS, value); break; case XmlTypeCode.Item: // Support XPathNodeIterator if (value is XPathNodeIterator) { value = ChangeTypeXsltResult(XmlQueryTypeFactory.NodeS, value); break; } // Support IXPathNavigable and XPathNavigator navigable = value as IXPathNavigable; if (navigable != null) { if (value is XPathNavigator) { value = new XmlQueryNodeSequence((XPathNavigator)value); } else { value = new XmlQueryNodeSequence(navigable.CreateNavigator()); } break; } throw new XslTransformException(SR.Xslt_UnsupportedClrType, sourceType.Name); } break; } } Debug.Assert(XmlILTypeHelper.GetStorageType(xmlType).IsAssignableFrom(value.GetType()), "Xml type " + xmlType + " is not represented in ILGen as " + value.GetType().Name); return(value); }
private static bool InvokeSchemaProviderMethod(Type clrType, XmlSchemaSet schemas, out XmlQualifiedName stableName, out XmlSchemaType xsdType, out bool hasRoot) { xsdType = null; hasRoot = true; object[] attrs = clrType.GetCustomAttributes(Globals.TypeOfXmlSchemaProviderAttribute, false); if (attrs == null || attrs.Length == 0) { stableName = DataContract.GetDefaultStableName(clrType); return(false); } XmlSchemaProviderAttribute provider = (XmlSchemaProviderAttribute)attrs[0]; if (provider.IsAny) { xsdType = CreateAnyElementType(); hasRoot = false; } string methodName = provider.MethodName; if (methodName == null || methodName.Length == 0) { if (!provider.IsAny) { throw Compat.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidGetSchemaMethod, DataContract.GetClrTypeFullName(clrType)))); } stableName = DataContract.GetDefaultStableName(clrType); } else { MethodInfo getMethod = clrType.GetMethod(methodName, /*BindingFlags.DeclaredOnly |*/ BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public, null, new Type[] { typeof(XmlSchemaSet) }, null); if (getMethod == null) { throw Compat.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.MissingGetSchemaMethod, DataContract.GetClrTypeFullName(clrType), methodName))); } if (!(Globals.TypeOfXmlQualifiedName.IsAssignableFrom(getMethod.ReturnType)) && !(Globals.TypeOfXmlSchemaType.IsAssignableFrom(getMethod.ReturnType))) { throw Compat.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidReturnTypeOnGetSchemaMethod, DataContract.GetClrTypeFullName(clrType), methodName, DataContract.GetClrTypeFullName(getMethod.ReturnType), DataContract.GetClrTypeFullName(Globals.TypeOfXmlQualifiedName), typeof(XmlSchemaType)))); } object typeInfo = getMethod.Invoke(null, new object[] { schemas }); if (provider.IsAny) { if (typeInfo != null) { throw Compat.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.InvalidNonNullReturnValueByIsAny, DataContract.GetClrTypeFullName(clrType), methodName))); } stableName = DataContract.GetDefaultStableName(clrType); } else if (typeInfo == null) { xsdType = CreateAnyElementType(); hasRoot = false; stableName = DataContract.GetDefaultStableName(clrType); } else { XmlSchemaType providerXsdType = typeInfo as XmlSchemaType; if (providerXsdType != null) { string typeName = providerXsdType.Name; string typeNs = null; if (typeName == null || typeName.Length == 0) { DataContract.GetDefaultStableName(DataContract.GetClrTypeFullName(clrType), out typeName, out typeNs); stableName = new XmlQualifiedName(typeName, typeNs); providerXsdType.Annotation = GetSchemaAnnotation(ExportActualType(stableName, new XmlDocument())); xsdType = providerXsdType; } else { foreach (XmlSchema schema in schemas.Schemas()) { foreach (XmlSchemaObject schemaItem in schema.Items) { if (schemaItem == (object)providerXsdType) { typeNs = schema.TargetNamespace; if (typeNs == null) { typeNs = string.Empty; } break; } } if (typeNs != null) { break; } } if (typeNs == null) { throw Compat.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidDataContractException(SR.Format(SR.MissingSchemaType, typeName, DataContract.GetClrTypeFullName(clrType)))); } stableName = new XmlQualifiedName(typeName, typeNs); } } else { stableName = (XmlQualifiedName)typeInfo; } } } return(true); }
/// <summary> /// In order to make a CDataWrapper property appear as a string in the WSDL, we use the XmlSchemaProvider attribute. /// </summary> public static XmlQualifiedName GetSchema(XmlSchemaSet xs) { return(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).QualifiedName); }
// Required // Author - Hao Yan, ASU ID: 1205007670 public string[] WsOperations(string url) { UriBuilder uriBuilder = new UriBuilder(url); uriBuilder.Query = "wsdl"; HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uriBuilder.Uri); webRequest.ContentType = "text/xml;charset=\"utf-8\""; webRequest.Method = "GET"; webRequest.Accept = "text/xml"; ServiceDescription wsdl; using (WebResponse response = webRequest.GetResponse()) { using (Stream stream = response.GetResponseStream()) { wsdl = ServiceDescription.Read(stream); } } List <string> operationInfo = new List <string>(); List <string> name = new List <string>(); List <string> returnType = new List <string>(); List <string> inputType = new List <string>(); List <string> _inputType = new List <string>(); Int32[] inputCount = new Int32[100]; Int32 index = 0; bool input_Type = false; bool output_Type = false; PortType portType = wsdl.PortTypes[0]; foreach (Operation operation in portType.Operations) { name.Add(operation.Name); } Types types = wsdl.Types; XmlSchema xmlSchema = types.Schemas[0]; foreach (object item in xmlSchema.Items) { XmlSchemaElement schemaElement = item as XmlSchemaElement; XmlSchemaComplexType schemaComplexType = item as XmlSchemaComplexType; if (schemaElement != null) { string str = schemaElement.Name; XmlSchemaType type = schemaElement.SchemaType; XmlSchemaComplexType complexType = type as XmlSchemaComplexType; if (str != name[index] + "Response") { index = name.FindIndex(delegate(string _str) { return(_str == str); }); if (complexType != null) { XmlSchemaParticle particle = complexType.Particle; XmlSchemaSequence sequence = particle as XmlSchemaSequence; if (sequence != null) { foreach (XmlSchemaElement childElement in sequence.Items) { if (index != -1) { inputType.Add(childElement.SchemaTypeName.Name); inputCount[index]++; input_Type = true; } } } } } else { if (complexType != null) { XmlSchemaParticle particle = complexType.Particle; XmlSchemaSequence sequence = particle as XmlSchemaSequence; if (sequence != null) { foreach (XmlSchemaElement childElement in sequence.Items) { if (index != -1) { returnType.Add(childElement.SchemaTypeName.Name); output_Type = true; } } } } } } } for (int i = 0, j = 0; i < inputType.Count && j < inputCount.Length; i += inputCount[j], j++) { string s = null; for (int m = 0; m < inputCount[j]; m++) { s = s + inputType[i + m] + ", "; } _inputType.Add(s); } for (int j = 0; j < name.Count; j++) { if (input_Type && output_Type) { operationInfo.Add("Operation Name: " + name[j] + ", " + "Input Type: " + _inputType[j] + "Return Type: " + returnType[j]); } else if (input_Type) { operationInfo.Add("Operation Name: " + name[j] + ", " + "Input Type: " + _inputType[j]); } else if (output_Type) { operationInfo.Add("Operation Name: " + name[j] + ", " + "Return Type: " + returnType[j]); } else { operationInfo.Add("Operation Name: " + name[j]); } } string[] list = operationInfo.ToArray(); return(list); }
protected void ExportGlobalElement(string elementName, string elementNs, bool isNillable, XmlQualifiedName typeName, XmlSchemaType xsdType, XmlSchemaSet schemaSet) { XmlSchemaElement element = new XmlSchemaElement { Name = elementName }; if (xsdType != null) { element.SchemaType = xsdType; } else { element.SchemaTypeName = typeName; } element.IsNillable = isNillable; this.AddElementToSchema(element, elementNs, schemaSet); }
private bool AlreadyProcessed(XmlSchemaType type) { return(!_processedTypes.Add(type)); }
private void ExportLocalElement(string wrapperNs, string elementName, string elementNs, XmlQualifiedName typeName, XmlSchemaType xsdType, bool multiple, bool isOptional, bool isNillable, XmlSchemaSequence sequence, XmlSchemaSet schemaSet) { System.Xml.Schema.XmlSchema schema = System.ServiceModel.Description.SchemaHelper.GetSchema(wrapperNs, schemaSet); XmlSchemaElement element = new XmlSchemaElement(); if (elementNs == wrapperNs) { element.Name = elementName; if (xsdType != null) { element.SchemaType = xsdType; } else { element.SchemaTypeName = typeName; System.ServiceModel.Description.SchemaHelper.AddImportToSchema(element.SchemaTypeName.Namespace, schema); } System.ServiceModel.Description.SchemaHelper.AddElementForm(element, schema); element.IsNillable = isNillable; } else { element.RefName = new XmlQualifiedName(elementName, elementNs); System.ServiceModel.Description.SchemaHelper.AddImportToSchema(elementNs, schema); this.ExportGlobalElement(elementName, elementNs, isNillable, typeName, xsdType, schemaSet); } if (multiple) { element.MaxOccurs = 79228162514264337593543950335M; } if (isOptional) { element.MinOccurs = 0M; } sequence.Items.Add(element); }
internal TypeDesc(Type type, bool isXsdType, XmlSchemaType dataType, string formatterName, TypeFlags flags) : this(type.Name, type.FullName, dataType, TypeKind.Primitive, (TypeDesc)null, flags, formatterName) { _isXsdType = isXsdType; _type = type; }
protected void ExportMessagePart(Message message, MessagePartDescription part, XmlQualifiedName typeName, XmlSchemaType xsdType, bool isOptional, bool isNillable, bool skipSchemaExport, bool generateElement, string wrapperNs, XmlSchemaSequence wrapperSequence, XmlSchemaSet schemaSet) { if (!IsNullOrEmpty(typeName) || (xsdType != null)) { string name = part.Name; string elementName = string.IsNullOrEmpty(part.UniquePartName) ? name : part.UniquePartName; MessagePart part2 = null; if (generateElement) { if (wrapperSequence != null) { if (!skipSchemaExport) { this.ExportLocalElement(wrapperNs, elementName, part.Namespace, typeName, xsdType, part.Multiple, isOptional, isNillable, wrapperSequence, schemaSet); } } else { if (!skipSchemaExport) { this.ExportGlobalElement(name, part.Namespace, isNillable, typeName, xsdType, schemaSet); } part2 = AddMessagePart(message, elementName, new XmlQualifiedName(name, part.Namespace), XmlQualifiedName.Empty); } } else { if (string.IsNullOrEmpty(typeName.Name)) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxAnonymousTypeNotSupported", new object[] { message.Name, elementName }))); } part2 = AddMessagePart(message, elementName, XmlQualifiedName.Empty, typeName); } if (part2 != null) { part.UniquePartName = part2.Name; } } }
internal override XmlValueConverter CreateValueConverter(XmlSchemaType schemaType) { return XmlUntypedConverter.Untyped; }
protected XmlQualifiedName ExportType(Type type, string partName, string operationName, out XmlSchemaType xsdType) { xsdType = null; if (type == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxExportMustHaveType", new object[] { operationName, partName }))); } if (type == typeof(void)) { return(null); } this.DataContractExporter.Export(type); XmlQualifiedName schemaTypeName = this.DataContractExporter.GetSchemaTypeName(type); if (IsNullOrEmpty(schemaTypeName)) { xsdType = this.DataContractExporter.GetSchemaType(type); } return(schemaTypeName); }
public SymbolEntry AddType(XmlSchemaType type) { return(AddSymbol(type.QualifiedName, type, Constants.TypeSuffix)); }
public void ChangeType_NullNamespaceResolverArgumentInFromStringTest() { XmlSchemaDatatype datatype = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Integer).Datatype; datatype.ChangeType("100", typeof(string), null); }