public override bool Read()
        {
            bool readResult = base.Read();

            if (readResult)
            {
                switch (this.NodeType)
                {
                    case XamlNodeType.StartObject:
                        this.objects.Push(this.Instance);
                        this.MapObjectWithSequenceNumber(this.Instance);
                        break;
                    case XamlNodeType.GetObject:
                        this.objects.Push(this.Instance);
                        break;
                    case XamlNodeType.EndObject:
                        this.objects.Pop();
                        break;
                    case XamlNodeType.StartMember:
                        this.xamlMember = this.Member;
                        break;
                    case XamlNodeType.EndMember:
                        this.xamlMember = null;
                        break;
                    case XamlNodeType.Value:
                        this.MapObjectWithSequenceNumber(this.GetRealObject());
                        break;
                }
            }

            return readResult;
        }
		public XamlSetTypeConverterEventArgs (XamlMember member, TypeConverter typeConverter, object value, ITypeDescriptorContext serviceProvider, CultureInfo cultureInfo)
			: base (member, value)
		{
			CultureInfo = cultureInfo;
			ServiceProvider = serviceProvider;
			TypeConverter = typeConverter;
		}
 public DynamicActivityXamlReader(bool isBuilder, XamlReader innerReader, XamlSchemaContext schemaContext)
 {
     this.isBuilder = isBuilder;
     this.innerReader = innerReader;
     this.schemaContext = schemaContext ?? innerReader.SchemaContext;
     this.xamlTypeXamlType = this.schemaContext.GetXamlType(typeof(XamlType));
     this.typeXamlType = this.schemaContext.GetXamlType(typeof(System.Type));
     this.baseActivityXamlType = this.schemaContext.GetXamlType(typeof(Activity));
     this.activityPropertyXamlType = this.schemaContext.GetXamlType(typeof(DynamicActivityProperty));
     this.activityPropertyType = this.activityPropertyXamlType.GetMember("Type");
     this.activityPropertyName = this.activityPropertyXamlType.GetMember("Name");
     this.activityPropertyValue = this.activityPropertyXamlType.GetMember("Value");
     this.activityPropertyAttributes = this.activityPropertyXamlType.GetMember("Attributes");
     this.namespaceTable = new NamespaceTable();
     this.frontLoadedDirectives = true;
     this.nodeQueue = new XamlNodeQueue(this.schemaContext);
     this.nodeReader = this.nodeQueue.Reader;
     IXamlLineInfo info = innerReader as IXamlLineInfo;
     if ((info != null) && info.HasLineInfo)
     {
         this.innerReaderLineInfo = info;
         this.nodeReaderLineInfo = (IXamlLineInfo) this.nodeQueue.Reader;
         this.hasLineInfo = true;
     }
 }
 public XamlMemberInvoker(XamlMember member)
 {
     if (member == null)
     {
         throw new ArgumentNullException("member");
     }
     this._member = member;
 }
Example #5
0
 public XamlDomMember(XamlMember xamlMember)
 {
     _member = xamlMember;
     if (xamlMember != null)
     {
         _schemaContext = xamlMember.Type.SchemaContext;
     }
 }
Example #6
0
        public XamlDomMember(XamlMember xamlMember, params XamlDomItem[] items)
            : this(xamlMember)
        {
            foreach (var item in items)
            {
                Items.Add(item);
            }

            Resolve();
        }
 private string LookupPrefix(XamlMember property)
 {
     string str;
     string prefix = this.xamlXmlWriter.LookupPrefix(property.GetXamlNamespaces(), out str);
     if ((prefix == null) && !this.meSettings.ContinueWritingWhenPrefixIsNotFound)
     {
         this.failed = true;
         return string.Empty;
     }
     return prefix;
 }
 private void CheckMemberForUniqueness(Node objectNode, XamlMember property)
 {
     if (!this.settings.AssumeValidInput)
     {
         if (objectNode.Members == null)
         {
             objectNode.Members = new XamlPropertySet();
         }
         else if (objectNode.Members.Contains(property))
         {
             throw new InvalidOperationException(System.Xaml.SR.Get("XamlMarkupExtensionWriterDuplicateMember", new object[] { property.Name }));
         }
         objectNode.Members.Add(property);
     }
 }
 private void AddDependencyForUnresolvedChildren(object childThatHasUnresolvedChildren, XamlMember property, object parentInstance, XamlType parentType, bool parentIsGotten, XamlSavedContext deferredMarkupExtensionContext)
 {
     if (((property != null) && property.IsDirective) && ((parentInstance == null) && (property != XamlLanguage.Key)))
     {
         List<string> result = new List<string>();
         this._nameFixupGraph.GetDependentNames(childThatHasUnresolvedChildren, result);
         string str = string.Join(", ", result.ToArray());
         throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("TransitiveForwardRefDirectives", new object[] { childThatHasUnresolvedChildren.GetType(), property, str })));
     }
     NameFixupToken token = this.GetTokenForUnresolvedChildren(childThatHasUnresolvedChildren, property, deferredMarkupExtensionContext);
     token.Target.Instance = parentInstance;
     token.Target.InstanceType = parentType;
     token.Target.InstanceWasGotten = parentIsGotten;
     this.PendCurrentFixupToken_SetValue(token);
 }
 internal void Set(XamlMember member)
 {
     if (FrameType != XamlStackFrameType.Object && FrameType != XamlStackFrameType.GetObject)
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SR.UnexpectedXaml));
     }
     HashSet<XamlMember> setMembers = _isSet as HashSet<XamlMember>;
     if (setMembers == null)
     {
         setMembers = new HashSet<XamlMember>();
         _isSet = setMembers;
     }
     if (!setMembers.Contains(member))
     {
         setMembers.Add(member);
     }
 }
 private void Logic_ApplyPropertyValue(ObjectWriterContext ctx, XamlMember prop, object value, bool onParent)
 {
     object inst = onParent ? ctx.ParentInstance : ctx.CurrentInstance;
     if (value is XData)
     {
         XData xData = value as XData;
         if (prop.Type.IsXData)
         {
             this.Runtime.SetXmlInstance(inst, prop, xData);
             return;
         }
         value = xData.Text;
     }
     this.SetValue(inst, prop, value);
     if (prop.IsDirective)
     {
         XamlMember aliasedProperty = (onParent ? ctx.ParentType : ctx.CurrentType).GetAliasedProperty(prop as XamlDirective);
         if ((prop != XamlLanguage.Key) && (aliasedProperty != null))
         {
             this.Logic_DuplicatePropertyCheck(ctx, aliasedProperty, onParent);
             object obj3 = this.Logic_CreateFromValue(ctx, aliasedProperty.TypeConverter, value, aliasedProperty, aliasedProperty.Name);
             this.SetValue(inst, aliasedProperty, obj3);
         }
         if (prop == XamlLanguage.Name)
         {
             if (inst == ctx.CurrentInstance)
             {
                 this.Logic_RegisterName_OnCurrent(ctx, (string) value);
             }
             else
             {
                 this.Logic_RegisterName_OnParent(ctx, (string) value);
             }
         }
         else if (prop == XamlLanguage.ConnectionId)
         {
             this.Logic_SetConnectionId(ctx, (int) value, inst);
         }
         else if (prop == XamlLanguage.Base)
         {
             this.Logic_CheckBaseUri(ctx, (string) value);
             ctx.BaseUri = new Uri((string) value);
             if (ctx.ParentInstance != null)
             {
                 this.Runtime.SetUriBase(ctx.ParentType, ctx.ParentInstance, ctx.BaseUri);
             }
         }
     }
 }
 public override void WriteStartMember(XamlMember property)
 {
     this.ThrowIfDisposed();
     if (property == null)
     {
         throw new ArgumentNullException("property");
     }
     this._deferringWriter.WriteStartMember(property);
     if (!this._deferringWriter.Handled)
     {
         string message = null;
         if (this._nextNodeMustBeEndMember)
         {
             message = System.Xaml.SR.Get("ValueMustBeFollowedByEndMember");
         }
         else if (property == XamlLanguage.UnknownContent)
         {
             message = System.Xaml.SR.Get("TypeHasNoContentProperty", new object[] { this._context.CurrentType });
         }
         else if (property.IsUnknown)
         {
             message = System.Xaml.SR.Get("CantSetUnknownProperty", new object[] { property.ToString() });
         }
         else if (this._context.CurrentProperty != null)
         {
             message = System.Xaml.SR.Get("OpenPropertyInCurrentFrame_SM", new object[] { this._context.CurrentType.ToString(), this._context.CurrentProperty.ToString(), property.ToString() });
         }
         else if (this._context.CurrentType == null)
         {
             message = System.Xaml.SR.Get("NoTypeInCurrentFrame_SM", new object[] { property.ToString() });
         }
         if (message != null)
         {
             throw this.WithLineInfo(new XamlObjectWriterException(message));
         }
         this._context.CurrentProperty = property;
         this.Logic_DuplicatePropertyCheck(this._context, property, false);
         if (this._context.CurrentInstance == null)
         {
             if (!this.IsConstructionDirective(this._context.CurrentProperty) && !this.IsDirectiveAllowedOnNullInstance(this._context.CurrentProperty, this._context.CurrentType))
             {
                 this.Logic_CreateAndAssignToParentStart(this._context);
             }
             if (property == XamlLanguage.PositionalParameters)
             {
                 this._context.CurrentCollection = new List<PositionalParameterDescriptor>();
             }
         }
         else
         {
             if (this.IsTextConstructionDirective(property))
             {
                 throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("LateConstructionDirective", new object[] { property.Name })));
             }
             if (this._context.CurrentIsTypeConvertedObject)
             {
                 if (!property.IsDirective && !property.IsAttachable)
                 {
                     throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("SettingPropertiesIsNotAllowed", new object[] { property.Name })));
                 }
                 if (property.IsAttachable && (this._context.CurrentInstance is NameFixupToken))
                 {
                     NameFixupToken currentInstance = (NameFixupToken) this._context.CurrentInstance;
                     throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("AttachedPropOnFwdRefTC", new object[] { property, this._context.CurrentType, string.Join(", ", currentInstance.NeededNames.ToArray()) })));
                 }
             }
         }
         if ((property.IsDirective && (property != XamlLanguage.Items)) && (property != XamlLanguage.PositionalParameters))
         {
             XamlType type = property.Type;
             if (type.IsCollection || type.IsDictionary)
             {
                 this._context.CurrentCollection = this.Runtime.CreateInstance(property.Type, null);
             }
         }
     }
 }
 private bool IsDirectiveAllowedOnNullInstance(XamlMember xamlMember, XamlType xamlType)
 {
     return ((xamlMember == XamlLanguage.Key) || ((xamlMember == XamlLanguage.Uid) && (null == xamlType.GetAliasedProperty(XamlLanguage.Uid))));
 }
 private void ValidateUnknown(XamlMember member)
 {
     if (member == XamlLanguage.UnknownContent)
     {
         ValidationError(SR.MemberUnknownContect(GetXamlTypeName(_stack.TopFrame.Type)));
     }            
     else if (member.IsUnknown)
     {
         bool retryAttachable = false;
         XamlType declaringType = member.DeclaringType;
         if (_stack.Depth == 1 && declaringType.IsUnknown &&
             !string.IsNullOrEmpty(this.rootNamespace) &&
             this.definedType != null && declaringType.Name == this.definedType.Name)
         {
             // Need to handle the case where the namespace of a member on the document root
             // is missing the project root namespace
             string clrNs;
             if (XamlBuildTaskServices.TryExtractClrNs(declaringType.PreferredXamlNamespace, out clrNs))
             {
                 clrNs = string.IsNullOrEmpty(clrNs) ? this.rootNamespace : this.rootNamespace + "." + clrNs;
                 if (clrNs == this.definedType.Namespace)
                 {
                     declaringType = SchemaContext.GetXamlType(this.definedType);
                     retryAttachable = true;
                 }
             }
         }
         XamlMember typeMember = declaringType.GetMember(member.Name);
         if (typeMember == null && retryAttachable)
         {
             typeMember = declaringType.GetAttachableMember(member.Name);
         }
         if (typeMember == null || typeMember.IsUnknown)
         {
             if (member.IsAttachable)
             {
                 ValidationError(SR.UnresolvedAttachableMember(GetXamlTypeName(member.DeclaringType) + "." + member.Name));
             }
             else if (member.IsDirective)
             {
                 ValidationError(SR.UnresolvedDirective(member.PreferredXamlNamespace + ":" + member.Name));
             }
             else
             {
                 // Skip if declaring type is unknown as the member unknown error messages become redundant.
                 if (declaringType != null && !declaringType.IsUnknown)
                 {
                     ValidationError(SR.UnresolvedMember(member.Name, GetXamlTypeName(declaringType)));
                 }
             }
         }
     }
 }
 protected virtual bool OnSetValue(object eventSender, XamlMember member, object value)
 {
     if (this._xamlSetValueHandler != null)
     {
         XamlSetValueEventArgs e = new XamlSetValueEventArgs(member, value);
         this._xamlSetValueHandler(eventSender, e);
         return e.Handled;
     }
     return false;
 }
		IEnumerable<XamlNodeInfo> GetItemsNodes (XamlMember xm, XamlObject xobj)
		{
			var obj = xobj.GetRawValue ();
			if (obj == null)
				yield break;
			var ie = xobj.Type.Invoker.GetItems (obj);
			while (ie.MoveNext ()) {
				var iobj = ie.Current;
				// If it is dictionary, then retrieve the key, and rewrite the item as the Value part.
				object ikey = null;
				if (xobj.Type.IsDictionary) {
					Type kvpType = iobj.GetType ();
					bool isNonGeneric = kvpType == typeof (DictionaryEntry);
					var kp = isNonGeneric ? null : kvpType.GetProperty ("Key");
					var vp = isNonGeneric ? null : kvpType.GetProperty ("Value");
					ikey = isNonGeneric ? ((DictionaryEntry) iobj).Key : kp.GetValue (iobj, null);
					iobj = isNonGeneric ? ((DictionaryEntry) iobj).Value : vp.GetValue (iobj, null);
				}

				var wobj = TypeExtensionMethods.GetExtensionWrapped (iobj);
				var xiobj = new XamlObject (GetType (wobj), wobj);
				if (ikey != null) {
					// Key member is written *inside* the item object.
					//
					// It is messy, but Key and Value are *sorted*. In most cases Key goes first, but for example PositionalParameters comes first.
					// To achieve this behavior, we compare XamlLanguage.Key and value's Member and returns in order. It's all nasty hack, but at least it could be achieved like this!

					var en = GetNodes (null, xiobj).ToArray ();
					yield return en [0]; // StartObject

					var xknm = new XamlNodeMember (xobj, XamlLanguage.Key);
					var nodes1 = en.Skip (1).Take (en.Length - 2);
					var nodes2 = GetKeyNodes (ikey, xobj.Type.KeyType, xknm);
					foreach (var xn in EnumerateMixingMember (nodes1, XamlLanguage.Key, nodes2))
						yield return xn;
					yield return en [en.Length - 1];
				}
				else
					foreach (var xn in GetNodes (null, xiobj))
						yield return xn;
			}
		}
 public AmbientPropertyValue(XamlMember property, object value)
 {
     // null arguments are allowed (4.0RC).
     RetrievedProperty = property;
     Value             = value;
 }
Example #18
0
 public XamlDuplicateMemberException(XamlMember member, XamlType type)
     : base(SR.Get(SRID.DuplicateMemberSet, (member != null) ? member.Name : null, (type != null) ? type.Name : null))
 {
     DuplicateMember = member;
     ParentType      = type;
 }
Example #19
0
 public AmbientPropertyValue(XamlMember property, object value)
 {
     _property = property;
     _value    = value;
 }
 public XamlNodeMember(XamlObject owner, XamlMember member)
 {
     this.owner  = owner;
     this.member = member;
 }
 public XamlDuplicateMemberException(XamlMember member, XamlType type)
     : this(String.Format("duplicate member '{0}' in type '{1}'", member, type))
 {
     DuplicateMember = member;
     ParentType      = type;
 }
Example #22
0
 public abstract void WriteStartMember(XamlMember xamlMember);
Example #23
0
        IEnumerable <XamlXmlNodeInfo> ReadMember(XamlType parentType, XamlMember xm)
        {
            yield return(Node(XamlNodeType.StartMember, xm));

            if (xm.IsEvent)
            {
                yield return(Node(XamlNodeType.Value, r.Value));

                r.Read();
            }
            else if (!xm.IsWritePublic)
            {
                if (xm.Type.IsXData)
                {
                    foreach (var ni in ReadXData())
                    {
                        yield return(ni);
                    }
                }
                else if (xm.Type.IsCollection)
                {
                    yield return(Node(XamlNodeType.GetObject, xm.Type));

                    yield return(Node(XamlNodeType.StartMember, XamlLanguage.Items));

                    foreach (var ni in ReadCollectionItems(parentType, XamlLanguage.Items))
                    {
                        yield return(ni);
                    }
                    yield return(Node(XamlNodeType.EndMember, XamlLanguage.Items));

                    yield return(Node(XamlNodeType.EndObject, xm.Type));
                }
                else
                {
                    throw new XamlParseException(String.Format("Read-only member '{0}' showed up in the source XML, and the xml contains element content that cannot be read.", xm.Name))
                          {
                              LineNumber = this.LineNumber, LinePosition = this.LinePosition
                          }
                };
            }
            else
            {
                if (xm.Type.IsCollection || xm.Type.IsDictionary)
                {
                    foreach (var ni in ReadCollectionItems(parentType, xm))
                    {
                        yield return(ni);
                    }
                }
                else
                {
                    foreach (var ni in ReadObjectElement(parentType, xm))
                    {
                        if (ni.NodeType == XamlNodeType.None)
                        {
                            throw new Exception("should not happen");
                        }
                        yield return(ni);
                    }
                }
            }

            yield return(Node(XamlNodeType.EndMember, xm));
        }
Example #24
0
        // member element, implicit member, children via content property, or value
        IEnumerable <XamlXmlNodeInfo> ReadMemberElement(XamlType parentType, XamlType xt)
        {
            XamlMember xm   = null;
            var        name = r.LocalName;
            int        idx  = name.IndexOf('.');

            // FIXME: it skips strict type name check, as it could result in MarkupExtension mismatch (could be still checked, though)
            if (idx >= 0 /* && name.Substring (0, idx) == xt.Name*/)
            {
                name = name.Substring(idx + 1);
                xm   = xt.GetMember(name);
            }
            else
            {
                xm = (XamlMember)FindStandardDirective(name, AllowedMemberLocations.MemberElement) ??
                     // not a standard directive? then try attachable
                     xt.GetAttachableMember(name) ??
                     // still not? then try ordinal member
                     xt.GetMember(name);
                if (xm == null)
                {
                    // still not? could it be omitted as content property or items ?
                    if ((xm = GetExtraMember(xt)) != null)
                    {
                        // Note that this does not involve r.Read()
                        foreach (var ni in ReadMember(xt, xm))
                        {
                            yield return(ni);
                        }
                        yield break;
                    }
                }
            }
            if (xm == null)
            {
                // Current element could be for another member in the parent type (if exists)
                if (parentType != null && parentType.GetMember(name) != null)
                {
                    // stop the iteration and signal the caller to not read current element as an object. (It resolves conflicts between "start object for current collection's item" and "start member for the next member in the parent object".
                    yield return(Node(XamlNodeType.None, null));

                    yield break;
                }

                // ok, then create unknown member.
                xm = new XamlMember(name, xt, false);                  // FIXME: not sure if isAttachable is always false.
            }

            if (!r.IsEmptyElement)
            {
                r.Read();
                foreach (var ni in ReadMember(xt, xm))
                {
                    yield return(ni);
                }
                r.MoveToContent();
                r.ReadEndElement();
            }
            else
            {
                r.Read();
            }
        }
 private object Logic_CreateFromValue(ObjectWriterContext ctx, XamlValueConverter<TypeConverter> typeConverter, object value, XamlMember property, string targetName, IAddLineInfo lineInfo)
 {
     object obj3;
     try
     {
         obj3 = this.Runtime.CreateFromValue(ctx.ServiceProviderContext, typeConverter, value, property);
     }
     catch (Exception exception)
     {
         if (CriticalExceptions.IsCriticalException(exception))
         {
             throw;
         }
         string message = System.Xaml.SR.Get("TypeConverterFailed", new object[] { targetName, value });
         throw lineInfo.WithLineInfo(new XamlObjectWriterException(message, exception));
     }
     return obj3;
 }
Example #26
0
 internal static string GetInternalXmlName(this XamlMember xm)
 {
     return(xm.IsAttachable ? String.Concat(xm.DeclaringType.GetInternalXmlName(), ".", xm.Name) : xm.Name);
 }
 private void Logic_DuplicatePropertyCheck(ObjectWriterContext ctx, XamlMember property, bool onParent)
 {
     if (!this._skipDuplicatePropertyCheck)
     {
         System.Xaml.Context.HashSet<XamlMember> set = onParent ? ctx.ParentAssignedProperties : ctx.CurrentAssignedProperties;
         if (set.ContainsKey(property))
         {
             if (property != XamlLanguage.Space)
             {
                 XamlType type = onParent ? ctx.ParentType : ctx.CurrentType;
                 throw this.WithLineInfo(new XamlDuplicateMemberException(property, type));
             }
         }
         else
         {
             set.Add(property);
         }
     }
 }
        internal static object ResolveValue(ITypeDescriptorContext serviceProvider,
                                            DependencyProperty property, CultureInfo culture, object source)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            // Only need to type convert strings and byte[]
            if (!(source is byte[] || source is String || source is Stream))
            {
                return(source);
            }

            IXamlSchemaContextProvider ixsc = (serviceProvider.GetService(typeof(IXamlSchemaContextProvider))
                                               as IXamlSchemaContextProvider);

            if (ixsc == null)
            {
                throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Value", typeof(Object).FullName));
            }
            XamlSchemaContext schemaContext = ixsc.SchemaContext;

            if (property != null)
            {
                //Get XamlMember from dp
                System.Xaml.XamlMember xamlProperty =
                    schemaContext.GetXamlType(property.OwnerType).GetMember(property.Name);
                if (xamlProperty == null)
                {
                    xamlProperty =
                        schemaContext.GetXamlType(property.OwnerType).GetAttachableMember(property.Name);
                }

                System.Xaml.Schema.XamlValueConverter <TypeConverter> typeConverter = null;

                if (xamlProperty != null)
                {
                    // If we have a Baml2006SchemaContext and the property is of type Enum, we already know that the
                    // type converter must be the EnumConverter.
                    if (xamlProperty.Type.UnderlyingType.IsEnum && schemaContext is Baml2006.Baml2006SchemaContext)
                    {
                        typeConverter = XamlReader.BamlSharedSchemaContext.GetTypeConverter(xamlProperty.Type.UnderlyingType);
                    }
                    else
                    {
                        typeConverter = xamlProperty.TypeConverter;

                        if (typeConverter == null)
                        {
                            typeConverter = xamlProperty.Type.TypeConverter;
                        }
                    }
                }
                else
                {
                    typeConverter = schemaContext.GetXamlType(property.PropertyType).TypeConverter;
                }


                // No Type converter case...
                if (typeConverter.ConverterType == null)
                {
                    return(source);
                }

                TypeConverter converter = null;

                if (xamlProperty != null && xamlProperty.Type.UnderlyingType == typeof(Boolean))
                {
                    if (source is String)
                    {
                        converter = new BooleanConverter();
                    }
                    else if (source is byte[])
                    {
                        byte[] bytes = source as byte[];
                        if (bytes != null && bytes.Length == 1)
                        {
                            return(bytes[0] != 0);
                        }
                        else
                        {
                            throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Value", typeof(Object).FullName));
                        }
                    }
                    else
                    {
                        throw new NotSupportedException(SR.Get(SRID.ParserCannotConvertPropertyValue, "Value", typeof(Object).FullName));
                    }
                }
                else
                {
                    converter = (TypeConverter)typeConverter.ConverterInstance;
                }

                return(converter.ConvertFrom(serviceProvider, culture, source));
            }
            else
            {
                return(source);
            }
        }
Example #29
0
        // Note that it could return invalid (None) node to tell the caller that it is not really an object element.
        IEnumerable <XamlXmlNodeInfo> ReadObjectElement(XamlType parentType, XamlMember currentMember)
        {
            if (r.NodeType != XmlNodeType.Element)
            {
                //throw new XamlParseException (String.Format ("Element is expected, but got {0}", r.NodeType));
                yield return(Node(XamlNodeType.Value, r.Value));

                yield break;
            }

            if (r.MoveToFirstAttribute())
            {
                do
                {
                    if (r.NamespaceURI == XamlLanguage.Xmlns2000Namespace)
                    {
                        yield return(Node(XamlNodeType.NamespaceDeclaration, new NamespaceDeclaration(r.Value, r.Prefix == "xmlns" ? r.LocalName : String.Empty)));
                    }
                } while (r.MoveToNextAttribute());
                r.MoveToElement();
            }

            var sti = GetStartTagInfo();

            var xt = sctx.GetXamlType(sti.TypeName);

            if (xt == null)
            {
                // Current element could be for another member in the parent type (if exists)
                if (parentType != null && (r.LocalName.IndexOf('.') > 0 || parentType.GetMember(r.LocalName) != null))
                {
                    // stop the iteration and signal the caller to not read current element as an object. (It resolves conflicts between "start object for current collection's item" and "start member for the next member in the parent object".
                    yield return(Node(XamlNodeType.None, null));

                    yield break;
                }

                // creates name-only XamlType. Also, it does not seem that it does not store this XamlType to XamlSchemaContext (Try GetXamlType(xtn) after reading such xaml node, it will return null).
                xt = new XamlType(sti.Namespace, sti.Name, sti.TypeName.TypeArguments == null ? null : sti.TypeName.TypeArguments.Select <XamlTypeName, XamlType> (xxtn => sctx.GetXamlType(xxtn)).ToArray(), sctx);
            }

            bool isGetObject = false;

            if (currentMember != null && !xt.CanAssignTo(currentMember.Type))
            {
                if (currentMember.DeclaringType != null && currentMember.DeclaringType.ContentProperty == currentMember)
                {
                    isGetObject = true;
                }

                // It could still be GetObject if current_member
                // is not a directive and current type is not
                // a markup extension.
                // (I'm not very sure about the condition;
                // it could be more complex.)
                // seealso: bug #682131
                else if (!(currentMember is XamlDirective) &&
                         !xt.IsMarkupExtension)
                {
                    isGetObject = true;
                }
            }

            if (isGetObject)
            {
                yield return(Node(XamlNodeType.GetObject, currentMember.Type));

                foreach (var ni in ReadMembers(parentType, currentMember.Type))
                {
                    yield return(ni);
                }
                yield return(Node(XamlNodeType.EndObject, currentMember.Type));

                yield break;
            }
            // else

            yield return(Node(XamlNodeType.StartObject, xt));

            // process attribute members (including MarkupExtensions)
            ProcessAttributesToMember(sctx, sti, xt);

            foreach (var pair in sti.Members)
            {
                yield return(Node(XamlNodeType.StartMember, pair.Key));

                // Try markup extension
                // FIXME: is this rule correct?
                var v = pair.Value;
                if (!String.IsNullOrEmpty(v) && v [0] == '{')
                {
                    var pai = ParsedMarkupExtensionInfo.Parse(v, xaml_namespace_resolver, sctx);
                    yield return(Node(XamlNodeType.StartObject, pai.Type));

                    foreach (var xepair in pai.Arguments)
                    {
                        yield return(Node(XamlNodeType.StartMember, xepair.Key));

                        if (xepair.Value is List <string> )
                        {
                            foreach (var s in (List <string>)xepair.Value)
                            {
                                yield return(Node(XamlNodeType.Value, s));
                            }
                        }
                        else
                        {
                            yield return(Node(XamlNodeType.Value, xepair.Value));
                        }
                        yield return(Node(XamlNodeType.EndMember, xepair.Key));
                    }
                    yield return(Node(XamlNodeType.EndObject, pai.Type));
                }
                else
                {
                    yield return(Node(XamlNodeType.Value, pair.Value));
                }

                yield return(Node(XamlNodeType.EndMember, pair.Key));
            }

            // process content members
            if (!r.IsEmptyElement)
            {
                r.Read();
                foreach (var ni in ReadMembers(parentType, xt))
                {
                    yield return(ni);
                }
                r.ReadEndElement();
            }
            else
            {
                r.Read();                  // consume empty element.
            }
            yield return(Node(XamlNodeType.EndObject, xt));
        }
Example #30
0
 public XamlMemberAdapter(XamlMember member, XamlSchemaContext context, string propName, MethodInfo getter, MethodInfo setter)
     : base(attachablePropertyName: propName, getter: getter, setter: setter, schemaContext: context)
 {
     this.member = member;
 }
 private bool AllowsMultiple(XamlMember member)
 {
     return
         member == XamlLanguage.Items ||
         member == XamlLanguage.PositionalParameters ||
         member == XamlLanguage.UnknownContent;
 }
Example #32
0
 public XamlMemberAdapter(XamlMember member, XamlSchemaContext context) : base(GetPropertyInfo(member), context)
 {
     this.member = member;
 }
 private object Logic_PushAndPopAProvideValueStackFrame(ObjectWriterContext ctx, XamlMember prop, MarkupExtension me, bool useIRME)
 {
     XamlMember currentProperty = ctx.CurrentProperty;
     ctx.CurrentProperty = prop;
     ctx.PushScope();
     ctx.CurrentInstance = me;
     object obj2 = null;
     if (useIRME)
     {
         this.Logic_AssignProvidedValue(ctx);
     }
     else
     {
         obj2 = this.Runtime.CallProvideValue(me, ctx.ServiceProviderContext);
     }
     ctx.PopScope();
     ctx.CurrentProperty = currentProperty;
     return obj2;
 }
Example #34
0
 private static PropertyInfo GetPropertyInfo(XamlMember member)
 {
     return(member.DeclaringType.UnderlyingType.GetProperty(member.Name));
 }
 private void SetValue(object inst, XamlMember property, object value)
 {
     if (property.IsDirective || !this.OnSetValue(inst, property, value))
     {
         this.Runtime.SetValue(inst, property, value);
     }
 }
Example #36
0
        internal static bool IsConstructorArgument(this XamlMember xm)
        {
            var ap = xm.GetCustomAttributeProvider();

            return(ap != null && ap.GetCustomAttributes(typeof(ConstructorArgumentAttribute), false).Length > 0);
        }
 private NameFixupToken GetTokenForUnresolvedChildren(object childThatHasUnresolvedChildren, XamlMember property, XamlSavedContext deferredMarkupExtensionContext)
 {
     NameFixupToken token = new NameFixupToken();
     if (deferredMarkupExtensionContext != null)
     {
         token.FixupType = FixupType.MarkupExtensionFirstRun;
         token.SavedContext = deferredMarkupExtensionContext;
     }
     else
     {
         token.FixupType = FixupType.UnresolvedChildren;
     }
     token.ReferencedObject = childThatHasUnresolvedChildren;
     token.Target.Property = property;
     return token;
 }
		IEnumerable<XamlNodeInfo> GetNodes (XamlMember xm, XamlObject xobj)
		{
			return GetNodes (xm, xobj, null, false);
		}
 private bool IsTextConstructionDirective(XamlMember xamlMember)
 {
     if (((xamlMember != XamlLanguage.Arguments) && (xamlMember != XamlLanguage.FactoryMethod)) && (xamlMember != XamlLanguage.PositionalParameters))
     {
         return (xamlMember == XamlLanguage.TypeArguments);
     }
     return true;
 }
Example #40
0
		void TestMemberCommon (XamlMember m, string name, Type type, Type declType, bool hasSetter)
		{
			Assert.IsNotNull (m, "#1");
			Assert.IsNotNull (m.DeclaringType, "#2");
			Assert.AreEqual (declType, m.DeclaringType.UnderlyingType, "#2-2");
			Assert.IsNotNull (m.Invoker, "#3");
			Assert.IsNotNull (m.Invoker.UnderlyingGetter, "#3-2");
			if (hasSetter)
				Assert.IsNotNull (m.Invoker.UnderlyingSetter, "#3-3");
			else
				Assert.IsNull (m.Invoker.UnderlyingSetter, "#3-3");
			Assert.IsFalse (m.IsUnknown, "#4");
			Assert.IsTrue (m.IsReadPublic, "#5");
			Assert.AreEqual (hasSetter, m.IsWritePublic, "#6");
			Assert.AreEqual (name, m.Name, "#7");
			Assert.IsTrue (m.IsNameValid, "#8");
			Assert.AreEqual (XamlLanguage.Xaml2006Namespace, m.PreferredXamlNamespace, "#9");
			// use declType here (mostly identical to targetType)
			Assert.AreEqual (new XamlType (declType, m.TargetType.SchemaContext), m.TargetType, "#10");
			Assert.IsNotNull (m.Type, "#11");
			Assert.AreEqual (type, m.Type.UnderlyingType, "#11-2");
			// Property.Type is a special case here.
			if (name == "Type" && m.DeclaringType != XamlLanguage.Property)
				Assert.AreEqual (m.Type.TypeConverter, m.TypeConverter, "#12");
			// String type is a special case here.
			if (type == typeof (string))
				Assert.AreEqual (m.Type.ValueSerializer, m.ValueSerializer, "#13a");
			else
				Assert.IsNull (m.ValueSerializer, "#13b");
			Assert.IsNull (m.DeferringLoader, "#14");
			Assert.IsNotNull (m.UnderlyingMember, "#15");
			Assert.AreEqual (!hasSetter, m.IsReadOnly, "#16");
			Assert.IsFalse (m.IsWriteOnly, "#17");
			Assert.IsFalse (m.IsAttachable, "#18");
			Assert.IsFalse (m.IsEvent, "#19");
			Assert.IsFalse (m.IsDirective, "#20");
			Assert.IsNotNull (m.DependsOn, "#21");
			Assert.AreEqual (0, m.DependsOn.Count, "#21-2");
			Assert.IsFalse (m.IsAmbient, "#22");
		}
 private object Logic_CreateFromValue(ObjectWriterContext ctx, XamlValueConverter<TypeConverter> typeConverter, object value, XamlMember property, string targetName)
 {
     return this.Logic_CreateFromValue(ctx, typeConverter, value, property, targetName, this);
 }
Example #42
0
 public XamlNodeInfo Set(XamlNodeType nodeType, XamlMember value)
 {
     NodeType = nodeType;
     Value    = value;
     return(this);
 }
Example #43
0
 public XamlNodeInfo(XamlNodeType nodeType, XamlMember member)
 {
     NodeType = nodeType;
     Value    = member;
 }
Example #44
0
        public static string ConstructorArgumentName(this XamlMember xm)
        {
            var caa = xm.GetCustomAttributeProvider().GetCustomAttribute <ConstructorArgumentAttribute> (false);

            return(caa.ArgumentName);
        }
 public XamlMemberInvokerAdapter(XamlMember member) : base(member)
 {
     this.member = member;
 }
Example #46
0
 public override void WriteStartMember(XamlMember member)
 {
     ThrowIsDisposed();
     _addDelegate(XamlNodeType.StartMember, member);
 }
		IEnumerable<XamlNodeInfo> EnumerateMixingMember (IEnumerable<XamlNodeInfo> nodes1, XamlMember m2, IEnumerable<XamlNodeInfo> nodes2)
		{
			if (nodes2 == null) {
				foreach (var cn in nodes1)
					yield return cn;
				yield break;
			}

			var e1 = nodes1.GetEnumerator ();
			var e2 = nodes2.GetEnumerator ();
			int nest = 0;
			while (e1.MoveNext ()) {
				if (e1.Current.NodeType == XamlNodeType.StartMember) {
					if (nest > 0)
						nest++;
					else
						if (TypeExtensionMethods.CompareMembers (m2, e1.Current.Member.Member) < 0) {
							while (e2.MoveNext ())
								yield return e2.Current;
						}
						else
							nest++;
				}
				else if (e1.Current.NodeType == XamlNodeType.EndMember)
					nest--;
				yield return e1.Current;
			}
			while (e2.MoveNext ())
				yield return e2.Current;
		}
Example #48
0
 internal static ICustomAttributeProvider GetCustomAttributeProvider(this XamlMember member)
 {
     return(member.UnderlyingMember);
 }
		IEnumerable<XamlNodeInfo> GetNodes (XamlMember xm, XamlObject xobj, XamlType overrideMemberType, bool partOfPositionalParameters)
		{
			// collection items: each item is exposed as a standalone object that has StartObject, EndObject and contents.
			if (xm == XamlLanguage.Items) {
				foreach (var xn in GetItemsNodes (xm, xobj))
					yield return xn;
				yield break;
			}
			
			// Arguments: each argument is written as a standalone object
			if (xm == XamlLanguage.Arguments) {
				foreach (var argm in xobj.Type.GetSortedConstructorArguments ()) {
					var argv = argm.Invoker.GetValue (xobj.GetRawValue ());
					var xarg = new XamlObject (argm.Type, argv);
					foreach (var cn in GetNodes (null, xarg))
						yield return cn;
				}
				yield break;
			}

			// PositionalParameters: items are from constructor arguments, written as Value node sequentially. Note that not all of them are in simple string value. Also, null values are not written as NullExtension
			if (xm == XamlLanguage.PositionalParameters) {
				foreach (var argm in xobj.Type.GetSortedConstructorArguments ()) {
					foreach (var cn in GetNodes (argm, new XamlObject (argm.Type, xobj.GetMemberValue (argm)), null, true))
						yield return cn;
				}
				yield break;
			}

			if (xm == XamlLanguage.Initialization) {
				yield return new XamlNodeInfo (TypeExtensionMethods.GetStringValue (xobj.Type, xm, xobj.GetRawValue (), value_serializer_ctx));
				yield break;
			}

			// Value - only for non-top-level node (thus xm != null)
			if (xm != null) {
				// overrideMemberType is (so far) used for XamlLanguage.Key.
				var xtt = overrideMemberType ?? xm.Type;
				if (!xtt.IsMarkupExtension && // this condition is to not serialize MarkupExtension whose type has TypeConverterAttribute (e.g. StaticExtension) as a string.
				    (xtt.IsContentValue (value_serializer_ctx) || xm.IsContentValue (value_serializer_ctx))) {
					// though null value is special: it is written as a standalone object.
					var val = xobj.GetRawValue ();
					if (val == null) {
						if (!partOfPositionalParameters)
							foreach (var xn in GetNodes (null, null_object))
								yield return xn;
						else
							yield return new XamlNodeInfo (String.Empty);
					}
					else
						yield return new XamlNodeInfo (TypeExtensionMethods.GetStringValue (xtt, xm, val, value_serializer_ctx));
					yield break;
				}
			}

			// collection items: return GetObject and Items.
			if (xm != null && xm.Type.IsCollection && !xm.IsWritePublic) {
				yield return new XamlNodeInfo (XamlNodeType.GetObject, xobj);
				// Write Items member only when there are items (i.e. do not write it if it is empty).
				var xnm = new XamlNodeMember (xobj, XamlLanguage.Items);
				var en = GetNodes (XamlLanguage.Items, xnm.Value).GetEnumerator ();
				if (en.MoveNext ()) {
					yield return new XamlNodeInfo (XamlNodeType.StartMember, xnm);
					do {
						yield return en.Current;
					} while (en.MoveNext ());
					yield return new XamlNodeInfo (XamlNodeType.EndMember, xnm);
				}
				yield return new XamlNodeInfo (XamlNodeType.EndObject, xobj);
			} else if (xm != null && xm.Type.IsXData) {
				var sw = new StringWriter ();
				var xw = XmlWriter.Create (sw, new XmlWriterSettings () { OmitXmlDeclaration = true, ConformanceLevel = ConformanceLevel.Auto });
				var val = xobj.GetRawValue () as IXmlSerializable;
				if (val == null)
					yield break; // do not output anything
				val.WriteXml (xw);
				xw.Close ();
				var obj = new XData () { Text = sw.ToString () };
				foreach (var xn in GetNodes (null, new XamlObject (XamlLanguage.XData, obj)))
					yield return xn;
			} else {
				// Object - could become Reference
				var val = xobj.GetRawValue ();
				if (!xobj.Type.IsContentValue (value_serializer_ctx) && val != null) {
					string refName = NameResolver.GetName (val);
					if (refName != null) {
						// The target object is already retrieved, so we don't return the same object again.
						NameResolver.SaveAsReferenced (val); // Record it as named object.
						// Then return Reference object instead.
						foreach (var xn in GetNodes (null, new XamlObject (XamlLanguage.Reference, new Reference (refName))))
							yield return xn;
						yield break;
					} else {
						// The object appeared in the xaml tree for the first time. So we store the reference with a unique name so that it could be referenced later.
						refName = GetReferenceName (xobj);
						if (NameResolver.IsCollectingReferences && NameResolver.Contains (refName))
							throw new InvalidOperationException (String.Format ("There is already an object of type {0} named as '{1}'. Object names must be unique.", val.GetType (), refName));
						NameResolver.SetNamedObject (refName, val, true); // probably fullyInitialized is always true here.
					}
				}
				yield return new XamlNodeInfo (XamlNodeType.StartObject, xobj);
				// If this object is referenced and there is no [RuntimeNameProperty] member, then return Name property in addition.
				if (val != null && xobj.Type.GetAliasedProperty (XamlLanguage.Name) == null) {
					string name = NameResolver.GetReferencedName (val);
					if (name != null) {
						var sobj = new XamlObject (XamlLanguage.String, name);
						foreach (var cn in GetMemberNodes (new XamlNodeMember (sobj, XamlLanguage.Name), new XamlNodeInfo [] { new XamlNodeInfo (name)}))
							yield return cn;
					}
				}
				foreach (var xn in GetObjectMemberNodes (xobj))
					yield return xn;
				yield return new XamlNodeInfo (XamlNodeType.EndObject, xobj);
			}
		}
Example #50
0
        public XamlObject GetMemberObjectValue(XamlMember xm)
        {
            var mv = GetMemberValue(xm);

            return(new XamlObject(GetType(mv), mv));
        }
        public override void WriteStartMember(XamlMember xamlMember)
        {
            switch (this.currentState)
            {
                case ActivityTemplateFactoryBuilderWriterStates.InitialState:
                    SharedFx.Assert("It is impossible to start a member during InitialState");
                    break;
                case ActivityTemplateFactoryBuilderWriterStates.BufferingState:
                    if (xamlMember == this.ActivityTemplateFactoryBuilderImplementationMember)
                    {
                        xamlMember = this.ActivityTemplateFactoryImplementationMember;

                        if (!this.xamlLanguageNamespaceWritten)
                        {
                            // Required namespace for XAML x:Class 
                            this.underlyingWriter.WriteNamespace(new NamespaceDeclaration("http://schemas.microsoft.com/winfx/2006/xaml", "x"));
                        }

                        this.underlyingWriter.WriteStartObject(this.ActivityTemplateFactoryType);
                        this.underlyingWriter.WriteStartMember(XamlLanguage.Class);
                        this.underlyingWriter.WriteValue(this.className);
                        this.underlyingWriter.WriteEndMember();
                        this.underlyingWriter.WriteStartMember(XamlLanguage.TypeArguments);
                        this.underlyingWriter.WriteValue(this.targetType);
                        this.underlyingWriter.WriteEndMember();
                        this.Transform(this.queuedNodes.Reader, this.underlyingWriter);
                        this.underlyingWriter.WriteStartMember(xamlMember);
                        this.currentState = ActivityTemplateFactoryBuilderWriterStates.BypassState;
                    }

                    if (xamlMember == this.ActivityTemplateFactoryBuilderNameMember)
                    {
                        this.currentState = ActivityTemplateFactoryBuilderWriterStates.BufferingNameState;
                    }
                    else if (xamlMember == this.ActivityTemplateFactoryBuilderTargetTypeMember)
                    {
                        this.currentState = ActivityTemplateFactoryBuilderWriterStates.BufferingTargetTypeState;
                    }
                    else
                    {
                        this.queuedNodes.Writer.WriteStartMember(xamlMember);
                    }

                    break;
                case ActivityTemplateFactoryBuilderWriterStates.BypassState:
                    this.underlyingWriter.WriteStartMember(xamlMember);
                    break;
                default:
                    SharedFx.Assert(
                        this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingNameState 
                        || this.currentState == ActivityTemplateFactoryBuilderWriterStates.BufferingTargetTypeState, 
                        "These are the only possible ActivityTemplateFactoryBuilderWriterStates.");
                    SharedFx.Assert("It is impossible to get an object when we are buffering the name / targetType.");
                    break;
            }
        }
Example #52
0
 public XamlNodeMember Set(XamlObject owner, XamlMember member)
 {
     Owner  = owner;
     Member = member;
     return(this);
 }