Beispiel #1
0
        // Sets the "key" arg as the key on "context".  "parentContext" is the context
        // one level above "context".  Verification is done to make sure that the 
        // "parentContext" is a valid Dictionary.  An error is thrown if it is not.
        private void SetKeyOnContext( 
            object key, 
            string attributeName,
            ReaderContextStackData context, 
            ReaderContextStackData parentContext)
        {
            try
            { 
                // make sure parent is a dictionary
                GetDictionaryFromContext(parentContext, true /*toInsert*/); 
            } 
            catch (XamlParseException e)
            { 
                // rethrow with a better error message
                if (parentContext.CheckFlag(ReaderFlags.CollectionHolder))
                {
                    BamlCollectionHolder holder = (BamlCollectionHolder)parentContext.ObjectData; 
                    object element = context.ObjectData;
 
                    if (element != null && element == holder.Dictionary) 
                    {
                        ThrowExceptionWithLine(SR.Get(SRID.ParserKeyOnExplicitDictionary, attributeName, 
                                       element.GetType().ToString(), holder.PropertyDefinition.Name), e);
                    }
                }
 
                ThrowExceptionWithLine(SR.Get(SRID.ParserNoMatchingIDictionary, attributeName), e);
            } 
 
            // set key on context
            context.Key = key; 
        }
Beispiel #2
0
        private ArrayExtension GetArrayExtensionFromContext(ReaderContextStackData context)
        {
            ArrayExtension result = null; 

            if (context != null) 
            { 
                result = context.ObjectData as ArrayExtension;
 
                if (context.CheckFlag(ReaderFlags.ArrayExt))
                {
                    result = (ArrayExtension)context.ObjectData;
                } 
                else if (context.ContextType == ReaderFlags.PropertyArray)
                { 
                    BamlCollectionHolder holder = GetCollectionHolderFromContext(context, true /*toInsert*/); 

                    result = holder.ArrayExt; 
                }
            }

            return result; 
        }
Beispiel #3
0
        private IList GetListFromContext(ReaderContextStackData context)
        { 
            IList result = null; 

            if (context != null) 
            {
                if (context.CheckFlag(ReaderFlags.IList))
                {
                    result = (IList)GetObjectDataFromContext(context); 
                }
                else if (context.ContextType == ReaderFlags.PropertyIList) 
                { 
                    BamlCollectionHolder holder = GetCollectionHolderFromContext(context, true /*toInsert*/);
 
                    result = holder.List;
                }
            }
 
            return result;
        } 
Beispiel #4
0
        private IAddChild GetIAddChildFromContext(ReaderContextStackData context)
        { 
            IAddChild result = null;

            if (context != null)
            { 
                if (context.CheckFlag(ReaderFlags.IAddChild))
                { 
                    result = BamlRecordManager.AsIAddChild(context.ObjectData); 
                }
                else if (context.ContextType == ReaderFlags.PropertyIAddChild) 
                {
                    BamlCollectionHolder holder = GetCollectionHolderFromContext(context, false /*toInsert*/);

                    result = BamlRecordManager.AsIAddChild(holder.Collection); 
                }
            } 
 
            return result;
        } 
Beispiel #5
0
        protected IDictionary GetDictionaryFromContext(ReaderContextStackData context, bool toInsert)
        {
            IDictionary result = null; 

            if (context != null) 
            { 
                if (context.CheckFlag(ReaderFlags.IDictionary))
                { 
                    result = (IDictionary)GetObjectDataFromContext(context);
                }
                else if (context.ContextType == ReaderFlags.PropertyIDictionary)
                { 
                    BamlCollectionHolder holder = GetCollectionHolderFromContext(context, toInsert);
 
                    result = holder.Dictionary; 
                }
            } 

            return result;
        }