Beispiel #1
0
        public Type Resolve(string typeName)
        {
            var tn = XamlTypeName.Parse(typeName, ns_resolver);
            var xt = schema_context.GetXamlType(tn);

            return(xt != null ? xt.UnderlyingType : null);
        }
Beispiel #2
0
 protected internal override void WriteValue(object value)
 {
     if (base.Writer.currentDepth == base.Depth)
     {
         XamlTypeName xamlTypeName = XamlTypeName.Parse(value as string, base.Writer.namespaceTable);
         XamlType     xamlType     = base.Writer.SchemaContext.GetXamlType(xamlTypeName);
         this.property.SetType(xamlType);
     }
     base.WriteValue(value);
 }
        public override object ConvertFromString(string value, IValueSerializerContext context)
        {
            if (context == null)
            {
                return(base.ConvertFromString(value, context));
            }
            var nsr = (IXamlNamespaceResolver)context.GetService(typeof(IXamlNamespaceResolver));
            var scp = (IXamlSchemaContextProvider)context.GetService(typeof(IXamlSchemaContextProvider));

            return(scp.SchemaContext.GetXamlType(XamlTypeName.Parse(value, nsr)).UnderlyingType);
        }
        internal static XamlType GetXamlTypeFromString(string typeName, NamespaceTable namespaceTable, XamlSchemaContext xsc)
        {
            XamlTypeName xamlTypeName = XamlTypeName.Parse(typeName, namespaceTable);
            XamlType     xamlType     = xsc.GetXamlType(xamlTypeName);

            if (xamlType == null)
            {
                xamlType = GetXamlTypeFromXamlTypeName(xamlTypeName, namespaceTable, xsc);
            }
            return(xamlType);
        }
Beispiel #5
0
        public void GenericGenericName()
        {
            var ns = new MyNSResolver();

            ns.Add("s", "urn:foo");
            ns.Add("", "urn:bar");
            ns.Add("x", XamlLanguage.Xaml2006Namespace);
            var xn = XamlTypeName.Parse("List(KeyValuePair(x:Int32, s:DateTime))", ns);

            Assert.AreEqual("urn:bar", xn.Namespace, "#1");
            Assert.AreEqual("List", xn.Name, "#2");
            Assert.AreEqual("{urn:bar}List({urn:bar}KeyValuePair({http://schemas.microsoft.com/winfx/2006/xaml}Int32, {urn:foo}DateTime))", xn.ToString(), "#3");
        }
Beispiel #6
0
        public void GenericArrayName()
        {
            var ns = new MyNSResolver();

            ns.Add("s", "urn:foo");
            var xn = XamlTypeName.Parse("s:Nullable(s:Int32)[,,]", ns);

            Assert.AreEqual("urn:foo", xn.Namespace, "#1");
            // note that array suffix comes here.
            Assert.AreEqual("Nullable[,,]", xn.Name, "#2");
            // note that array suffix is detached from Name and appended after generic type arguments.
            Assert.AreEqual("{urn:foo}Nullable({urn:foo}Int32)[,,]", xn.ToString(), "#3");
        }
        internal Type ServiceProvider_Resolve(string qName)
        {
            XamlType type = this.ServiceProvider_ResolveXamlType(qName);

            if ((type != null) && (type.UnderlyingType != null))
            {
                return(type.UnderlyingType);
            }
            XamlTypeName typeName = XamlTypeName.Parse(qName, this._serviceProviderContext);

            type = base.GetXamlType(typeName, true, true);
            throw new XamlParseException(System.Xaml.SR.Get("TypeNotFound", new object[] { type.GetQualifiedName() }));
        }
        // This class doesn't implement the IServiceProvider.  That is done
        // with worker classes ValueConverterContext or MarkupConverterContext.
        // The worker class implements IServiceProvider but uses the real
        // context for the implementation of the actual services.

        internal Type ServiceProvider_Resolve(string qName)
        {
            // As soon as we have the necessary setting on ObjectWriter, we need to start passing
            // the local assembly into the context; currently, this will only return publics.
            XamlType xamlType = ServiceProvider_ResolveXamlType(qName);

            if (xamlType == null || xamlType.UnderlyingType == null)
            {
                XamlTypeName name = XamlTypeName.Parse(qName, _serviceProviderContext);
                xamlType = GetXamlType(name, true, true);
                throw new XamlParseException(SR.Get(SRID.TypeNotFound, xamlType.GetQualifiedName()));
            }
            return(xamlType.UnderlyingType);
        }
Beispiel #9
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            IXamlSchemaContextProvider schemaContextProvider =
                (IXamlSchemaContextProvider)context.GetService(typeof(IXamlSchemaContextProvider));
            IAmbientProvider ambientValueProvider =
                (IAmbientProvider)context.GetService(typeof(IAmbientProvider));
            IXamlNamespaceResolver namespaceResolver =
                (IXamlNamespaceResolver)context.GetService(typeof(IXamlNamespaceResolver));

            XamlTypeName typeName        = XamlTypeName.Parse("TemplateClass2", namespaceResolver);
            XamlType     xamlType        = schemaContextProvider.SchemaContext.GetXamlType(typeName);
            XamlMember   ambientProperty = xamlType.GetMember("Suffix");
            IEnumerable <AmbientPropertyValue> propVals = ambientValueProvider.GetAllAmbientValues(null, ambientProperty);
            string s = (string)value;

            foreach (AmbientPropertyValue val in propVals)
            {
                s += (string)val.Value;
            }
            return(s);
        }
        private bool MapTypeNameToken(ref string typeToken, out BuildType type)
        {
            type = null;

            var typeName = XamlTypeName.Parse(typeToken);

            if (typeName == null)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(typeName.Prefix))
            {
                return(false);
            }

            bool changed = MapTypeName(typeName, out type);

            if (typeName.HasTypeArgs)
            {
                var typeArguments = typeName.TypeArguments;
                for (int i = 0; i < typeArguments.Count; i++)
                {
                    var       typeArg = typeArguments[i];
                    BuildType notUsedType;
                    if (MapTypeName(typeArg, out notUsedType))
                    {
                        typeArguments[i] = typeArg;
                        changed          = true;
                    }
                }
            }

            if (changed)
            {
                typeToken = typeName.ToString();
            }

            return(changed);
        }
Beispiel #11
0
        XamlType ResolveTypeFromName(string name)
        {
            var nsr = (IXamlNamespaceResolver)service_provider.GetService(typeof(IXamlNamespaceResolver));

            return(sctx.GetXamlType(XamlTypeName.Parse(name, nsr)));
        }
                public ActivityPropertyHolder(DynamicActivityXamlReader parent, XamlReader reader)
                {
                    this.parent = parent;
                    this.nodes  = new XamlNodeQueue(parent.SchemaContext);
                    IXamlLineInfo innerReaderLineInfo = parent.innerReaderLineInfo;

                    reader.Read();
                    this.nodes.Writer.WriteStartObject(parent.activityPropertyXamlType, innerReaderLineInfo);
                    int  num  = 1;
                    int  a    = 0;
                    int  num3 = 0;
                    bool flag = reader.Read();

                    while (flag)
                    {
                        XamlMember activityPropertyName;
                        switch (reader.NodeType)
                        {
                        case XamlNodeType.StartObject:
                        case XamlNodeType.GetObject:
                        {
                            num++;
                            DynamicActivityXamlReader.IncrementIfPositive(ref a);
                            DynamicActivityXamlReader.IncrementIfPositive(ref num3);
                            if ((num3 <= 0) || !(reader.Type == parent.xamlTypeXamlType))
                            {
                                goto Label_0231;
                            }
                            this.nodes.Writer.WriteStartObject(parent.typeXamlType, innerReaderLineInfo);
                            flag = reader.Read();
                            continue;
                        }

                        case XamlNodeType.EndObject:
                        {
                            num--;
                            if (num != 0)
                            {
                                goto Label_0213;
                            }
                            flag = reader.Read();
                            continue;
                        }

                        case XamlNodeType.StartMember:
                            if (!(reader.Member.DeclaringType == XamlLanguage.Property))
                            {
                                goto Label_0231;
                            }
                            activityPropertyName = reader.Member;
                            if (!(activityPropertyName == DynamicActivityXamlReader.xPropertyName))
                            {
                                break;
                            }
                            activityPropertyName = parent.activityPropertyName;
                            if (a == 0)
                            {
                                a = 1;
                            }
                            goto Label_0115;

                        case XamlNodeType.EndMember:
                            DynamicActivityXamlReader.DecrementIfPositive(ref a);
                            DynamicActivityXamlReader.DecrementIfPositive(ref num3);
                            goto Label_0231;

                        case XamlNodeType.Value:
                            if (a != 1)
                            {
                                goto Label_014F;
                            }
                            this.Name = reader.Value as string;
                            goto Label_0231;

                        default:
                            goto Label_0231;
                        }
                        if (activityPropertyName == DynamicActivityXamlReader.xPropertyType)
                        {
                            activityPropertyName = parent.activityPropertyType;
                            if (num3 == 0)
                            {
                                num3 = 1;
                            }
                        }
                        else
                        {
                            if (activityPropertyName != DynamicActivityXamlReader.xPropertyAttributes)
                            {
                                throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.PropertyMemberNotSupportedByActivityXamlServices(activityPropertyName.Name), innerReaderLineInfo));
                            }
                            activityPropertyName = parent.activityPropertyAttributes;
                        }
Label_0115:
                        this.nodes.Writer.WriteStartMember(activityPropertyName, innerReaderLineInfo);
                        flag = reader.Read();
                        continue;
Label_014F:
                        if (num3 == 1)
                        {
                            XamlTypeName xamlTypeName = XamlTypeName.Parse(reader.Value as string, parent.namespaceTable);
                            XamlType     xamlType     = parent.SchemaContext.GetXamlType(xamlTypeName);
                            if (xamlType == null)
                            {
                                throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.InvalidPropertyType(reader.Value as string, this.Name), innerReaderLineInfo));
                            }
                            this.Type = xamlType;
                        }
                        goto Label_0231;
Label_0213:
                        DynamicActivityXamlReader.DecrementIfPositive(ref a);
                        DynamicActivityXamlReader.DecrementIfPositive(ref num3);
Label_0231:
                        this.nodes.Writer.WriteNode(reader, innerReaderLineInfo);
                        flag = reader.Read();
                    }
                    reader.Close();
                }