// 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; }
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; }
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; }
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; }
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; }