public XamlSavedContext(SavedContextType savedContextType, ObjectWriterContext owContext, XamlContextStack<ObjectWriterFrame> stack)
 {
     this._savedContextType = savedContextType;
     this._context = owContext.SchemaContext;
     this._stack = stack;
     if (savedContextType == SavedContextType.Template)
     {
         stack.CurrentFrame.Instance = null;
     }
     this.BaseUri = owContext.BaseUri;
 }
Example #2
0
 public XamlSavedContext(SavedContextType savedContextType, ObjectWriterContext owContext, XamlContextStack <ObjectWriterFrame> stack)
 {
     this._savedContextType = savedContextType;
     this._context          = owContext.SchemaContext;
     this._stack            = stack;
     if (savedContextType == SavedContextType.Template)
     {
         stack.CurrentFrame.Instance = null;
     }
     this.BaseUri = owContext.BaseUri;
 }
Example #3
0
        public XamlSavedContext(SavedContextType savedContextType, ObjectWriterContext owContext, XamlContextStack <ObjectWriterFrame> stack)
        {
            //We should harvest all information necessary from the xamlContext so that we can answer all ServiceProvider based questions.
            _savedContextType = savedContextType;
            _context          = owContext.SchemaContext;
            _stack            = stack;

            // Null out CurrentFrameValue in case of template to save on survived allocations
            if (savedContextType == SavedContextType.Template)
            {
                stack.CurrentFrame.Instance = null;
            }
            this.BaseUri = owContext.BaseUri;
        }
 public static object GetTargetProperty(ObjectWriterContext xamlContext)
 {
     IProvideValueTarget parentProperty = xamlContext.ParentProperty as IProvideValueTarget;
     if (parentProperty != null)
     {
         return parentProperty.TargetProperty;
     }
     XamlMember member = xamlContext.ParentProperty;
     if (member == null)
     {
         return null;
     }
     if (member.IsAttachable)
     {
         return member.Setter;
     }
     return member.UnderlyingMember;
 }
 private bool Logic_WillParentCollectionAdd(ObjectWriterContext ctx, Type type, bool excludeObjectType)
 {
     XamlType itemType = ctx.ParentType.ItemType;
     if (excludeObjectType && (itemType == XamlLanguage.Object))
     {
         return false;
     }
     return itemType.UnderlyingType.IsAssignableFrom(type);
 }
 private void Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
 {
     XamlMember parentProperty = ctx.ParentProperty;
     object currentInstance = ctx.CurrentInstance;
     XamlType type = parentProperty.Type;
     if (parentProperty.IsDirective && (type.IsCollection || type.IsDictionary))
     {
         if ((currentInstance is NameFixupToken) && (parentProperty != XamlLanguage.Items))
         {
             NameFixupToken token = currentInstance as NameFixupToken;
             string str = string.Join(",", token.NeededNames.ToArray());
             string message = System.Xaml.SR.Get("ForwardRefDirectives", new object[] { str });
             throw this.WithLineInfo(new XamlObjectWriterException(message));
         }
         if (parentProperty == XamlLanguage.PositionalParameters)
         {
             ctx.CurrentType = XamlLanguage.PositionalParameterDescriptor;
             ctx.CurrentInstance = new PositionalParameterDescriptor(currentInstance, false);
         }
         this.Logic_DoAssignmentToParentCollection(ctx);
     }
     else if (ctx.ParentInstance != null)
     {
         if (ctx.ParentIsPropertyValueSet)
         {
             throw this.WithLineInfo(new XamlDuplicateMemberException(ctx.ParentProperty, ctx.ParentType));
         }
         ctx.ParentIsPropertyValueSet = true;
         if (currentInstance is NameFixupToken)
         {
             NameFixupToken token2 = (NameFixupToken) currentInstance;
             if (parentProperty.IsDirective)
             {
                 if (parentProperty != XamlLanguage.Key)
                 {
                     string str3 = string.Join(",", token2.NeededNames.ToArray());
                     string str4 = System.Xaml.SR.Get("ForwardRefDirectives", new object[] { str3 });
                     throw this.WithLineInfo(new XamlObjectWriterException(str4));
                 }
                 this.Logic_PendKeyFixupToken(ctx, token2);
             }
             else
             {
                 this.PendCurrentFixupToken_SetValue(token2);
             }
         }
         else
         {
             XamlType parentType = ctx.ParentType;
             if (!ctx.CurrentIsObjectFromMember)
             {
                 this.Logic_ApplyPropertyValue(ctx, parentProperty, currentInstance, true);
                 if (parentProperty == parentType.GetAliasedProperty(XamlLanguage.Name))
                 {
                     this.Logic_RegisterName_OnParent(ctx, (string) currentInstance);
                 }
                 if (parentProperty == XamlLanguage.Key)
                 {
                     ctx.ParentKey = currentInstance;
                 }
             }
         }
     }
     else
     {
         if (!parentProperty.IsDirective)
         {
             throw new XamlInternalException(System.Xaml.SR.Get("BadStateObjectWriter"));
         }
         if (parentProperty == XamlLanguage.Base)
         {
             this.Logic_CheckBaseUri(ctx, (string) currentInstance);
             ctx.BaseUri = new Uri((string) currentInstance);
         }
         else if (currentInstance is NameFixupToken)
         {
             if (parentProperty != XamlLanguage.Key)
             {
                 NameFixupToken token3 = (NameFixupToken) currentInstance;
                 string str5 = string.Join(",", token3.NeededNames.ToArray());
                 string str6 = System.Xaml.SR.Get("ForwardRefDirectives", new object[] { str5 });
                 throw this.WithLineInfo(new XamlObjectWriterException(str6));
             }
             this.Logic_PendKeyFixupToken(ctx, (NameFixupToken) currentInstance);
         }
         else if (parentProperty == XamlLanguage.Key)
         {
             ctx.ParentKey = currentInstance;
         }
         else
         {
             ctx.ParentPreconstructionPropertyValues.Add(parentProperty, currentInstance);
         }
     }
 }
 private void Logic_EndInit(ObjectWriterContext ctx)
 {
     XamlType currentType = ctx.CurrentType;
     object currentInstance = ctx.CurrentInstance;
     this.Runtime.InitializationGuard(currentType, currentInstance, false);
     this.OnAfterEndInit(currentInstance);
 }
 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;
 }
 private void Logic_DeferProvideValue(ObjectWriterContext ctx)
 {
     XamlSavedContext savedContext = ctx.GetSavedContext(SavedContextType.ReparseMarkupExtension);
     if (((ctx.LiveDepth > 2) && (ctx.ParentProperty == XamlLanguage.Key)) && ctx.GrandParentType.IsDictionary)
     {
         NameFixupToken token = this.GetTokenForUnresolvedChildren(ctx.CurrentInstance, XamlLanguage.Key, savedContext);
         this.Logic_PendKeyFixupToken(ctx, token);
     }
     else
     {
         this.AddDependencyForUnresolvedChildren(ctx.CurrentInstance, ctx.ParentProperty, ctx.ParentInstance, ctx.ParentType, ctx.ParentIsObjectFromMember, savedContext);
     }
 }
 private void Logic_ConvertPositionalParamsToArgs(ObjectWriterContext ctx)
 {
     XamlType currentType = ctx.CurrentType;
     if (!currentType.IsMarkupExtension)
     {
         throw this.WithLineInfo(new XamlInternalException(System.Xaml.SR.Get("NonMEWithPositionalParameters")));
     }
     List<PositionalParameterDescriptor> currentCollection = (List<PositionalParameterDescriptor>) ctx.CurrentCollection;
     object[] objArray = new object[currentCollection.Count];
     IEnumerable<XamlType> positionalParameters = currentType.GetPositionalParameters(currentCollection.Count);
     if (positionalParameters == null)
     {
         string message = string.Format(TypeConverterHelper.InvariantEnglishUS, System.Xaml.SR.Get("NoSuchConstructor"), new object[] { currentCollection.Count, currentType.Name });
         throw this.WithLineInfo(new XamlObjectWriterException(message));
     }
     int num = 0;
     foreach (XamlType type2 in positionalParameters)
     {
         object obj2;
         if (num >= currentCollection.Count)
         {
             throw this.WithLineInfo(new XamlInternalException(System.Xaml.SR.Get("PositionalParamsWrongLength")));
         }
         PositionalParameterDescriptor descriptor = currentCollection[num];
         if (descriptor.WasText)
         {
             XamlValueConverter<TypeConverter> typeConverter = type2.TypeConverter;
             object obj3 = descriptor.Value;
             obj2 = this.Logic_CreateFromValue(ctx, typeConverter, obj3, null, type2.Name);
         }
         else
         {
             obj2 = currentCollection[num].Value;
         }
         objArray[num++] = obj2;
         ctx.CurrentCtorArgs = objArray;
     }
 }
 private void Logic_CreateFromInitializationValue(ObjectWriterContext ctx)
 {
     XamlType parentType = ctx.ParentType;
     XamlValueConverter<TypeConverter> typeConverter = parentType.TypeConverter;
     object currentInstance = ctx.CurrentInstance;
     object obj3 = null;
     if (parentType.IsUnknown)
     {
         string message = System.Xaml.SR.Get("CantCreateUnknownType", new object[] { parentType.GetQualifiedName() });
         throw this.WithLineInfo(new XamlObjectWriterException(message));
     }
     if (typeConverter == null)
     {
         throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("InitializationSyntaxWithoutTypeConverter", new object[] { parentType.GetQualifiedName() })));
     }
     obj3 = this.Logic_CreateFromValue(ctx, typeConverter, currentInstance, null, parentType.Name);
     ctx.PopScope();
     ctx.CurrentInstance = obj3;
     ctx.CurrentIsTypeConvertedObject = true;
     if (!(obj3 is NameFixupToken))
     {
         if (parentType.IsCollection || parentType.IsDictionary)
         {
             ctx.CurrentCollection = obj3;
         }
         this.Logic_ApplyCurrentPreconstructionPropertyValues(ctx, true);
     }
 }
 private void Logic_AssignProvidedValue(ObjectWriterContext ctx)
 {
     if (!this.Logic_ProvideValue(ctx) && (ctx.ParentProperty != null))
     {
         this.Logic_DoAssignmentToParentProperty(ctx);
     }
 }
 private void Logic_CheckAssignmentToParentStart(ObjectWriterContext ctx)
 {
     bool flag = (ctx.ParentProperty == XamlLanguage.Items) && ctx.ParentType.IsDictionary;
     if (ctx.CurrentType.IsUsableDuringInitialization && !flag)
     {
         ctx.CurrentWasAssignedAtCreation = true;
         this.Logic_DoAssignmentToParentProperty(ctx);
     }
     else
     {
         ctx.CurrentWasAssignedAtCreation = false;
     }
 }
 private void Logic_ValidateXClass(ObjectWriterContext ctx, object value)
 {
     if (ctx.Depth > 1)
     {
         throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("DirectiveNotAtRoot", new object[] { XamlLanguage.Class })));
     }
     string str = value as string;
     if (str == null)
     {
         throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("DirectiveMustBeString", new object[] { XamlLanguage.Class })));
     }
     object currentInstance = ctx.CurrentInstance;
     Type type = (currentInstance != null) ? currentInstance.GetType() : ctx.CurrentType.UnderlyingType;
     if (type.FullName != str)
     {
         string rootNamespace = this.SchemaContext.GetRootNamespace(type.Assembly);
         if (!string.IsNullOrEmpty(rootNamespace))
         {
             str = rootNamespace + "." + str;
         }
         if (type.FullName != str)
         {
             throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("XClassMustMatchRootInstance", new object[] { str, type.FullName })));
         }
     }
 }
 private bool Logic_ShouldConvertKey(ObjectWriterContext ctx)
 {
     if (this._preferUnconvertedDictionaryKeys && !ctx.GrandParentShouldConvertChildKeys)
     {
         if (ctx.GrandParentShouldNotConvertChildKeys)
         {
             return false;
         }
         XamlType grandParentType = ctx.GrandParentType;
         if (((grandParentType != null) && grandParentType.IsDictionary) && (typeof(IDictionary).IsAssignableFrom(grandParentType.UnderlyingType) && !IsBuiltInGenericDictionary(grandParentType.UnderlyingType)))
         {
             return false;
         }
         ctx.GrandParentShouldConvertChildKeys = true;
     }
     return true;
 }
 private void Logic_SetConnectionId(ObjectWriterContext ctx, int connectionId, object instance)
 {
     object rootInstance = ctx.RootInstance;
     this.Runtime.SetConnectionId(rootInstance, connectionId, instance);
 }
Example #17
0
 public DeferringWriter(ObjectWriterContext context)
 {
     _context = context;
     _mode    = DeferringMode.Off;
 }
Example #18
0
 public ServiceProviderContext(ObjectWriterContext context)
 {
     _xamlContext = context;
 }
 private void Logic_BeginInit(ObjectWriterContext ctx)
 {
     object currentInstance = ctx.CurrentInstance;
     XamlType currentType = ctx.CurrentType;
     this.Runtime.InitializationGuard(currentType, currentInstance, true);
     if (ctx.BaseUri != null)
     {
         this.Runtime.SetUriBase(currentType, currentInstance, ctx.BaseUri);
     }
     if (currentInstance == ctx.RootInstance)
     {
         this.Logic_SetConnectionId(ctx, 0, currentInstance);
     }
     this.OnAfterBeginInit(currentInstance);
 }
 private void RegisterName(ObjectWriterContext ctx, string name, object inst, XamlType xamlType, INameScope nameScope, INameScope parentNameScope, bool isRoot)
 {
     INameScope objA = nameScope;
     NameScopeDictionary dictionary = nameScope as NameScopeDictionary;
     if (dictionary != null)
     {
         objA = dictionary.UnderlyingNameScope;
     }
     if (object.ReferenceEquals(objA, inst) && !isRoot)
     {
         nameScope = parentNameScope;
     }
     if (!(inst is NameFixupToken))
     {
         try
         {
             nameScope.RegisterName(name, inst);
         }
         catch (Exception exception)
         {
             if (CriticalExceptions.IsCriticalException(exception))
             {
                 throw;
             }
             throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("NameScopeException", new object[] { exception.Message }), exception));
         }
     }
 }
 private void Logic_CheckBaseUri(ObjectWriterContext ctx, string value)
 {
     if ((ctx.BaseUri != null) || (ctx.Depth > 2))
     {
         throw new XamlObjectWriterException(System.Xaml.SR.Get("CannotSetBaseUri"));
     }
 }
 private void TryCreateParentInstance(ObjectWriterContext ctx)
 {
     if ((ctx.ParentInstance == null) && (ctx.ParentProperty != XamlLanguage.Arguments))
     {
         ctx.LiftScope();
         this.Logic_CreateAndAssignToParentStart(ctx);
         ctx.UnLiftScope();
     }
 }
 private void Logic_CreateAndAssignToParentStart(ObjectWriterContext ctx)
 {
     object obj2;
     object obj3;
     XamlType currentType = ctx.CurrentType;
     if (ctx.CurrentIsObjectFromMember)
     {
         throw this.WithLineInfo(new XamlInternalException(System.Xaml.SR.Get("ConstructImplicitType")));
     }
     if (currentType.IsMarkupExtension && (ctx.CurrentCtorArgs != null))
     {
         object[] currentCtorArgs = ctx.CurrentCtorArgs;
         for (int i = 0; i < currentCtorArgs.Length; i++)
         {
             MarkupExtension me = currentCtorArgs[i] as MarkupExtension;
             if (me != null)
             {
                 currentCtorArgs[i] = this.Logic_PushAndPopAProvideValueStackFrame(ctx, XamlLanguage.PositionalParameters, me, false);
             }
         }
     }
     if (!ctx.CurrentHasPreconstructionPropertyValuesDictionary || !ctx.CurrentPreconstructionPropertyValues.TryGetValue(XamlLanguage.FactoryMethod, out obj3))
     {
         obj2 = this.Runtime.CreateInstance(currentType, ctx.CurrentCtorArgs);
     }
     else
     {
         XamlType type2;
         XamlPropertyName name = XamlPropertyName.Parse((string) obj3);
         if (name == null)
         {
             string message = string.Format(TypeConverterHelper.InvariantEnglishUS, System.Xaml.SR.Get("InvalidExpression"), new object[] { obj3 });
             throw this.WithLineInfo(new XamlInternalException(message));
         }
         if (name.Owner == null)
         {
             type2 = currentType;
         }
         else
         {
             type2 = ctx.GetXamlType(name.Owner);
             if (type2 == null)
             {
                 XamlTypeName xamlTypeName = ctx.GetXamlTypeName(name.Owner);
                 throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("CannotResolveTypeForFactoryMethod", new object[] { xamlTypeName, name.Name })));
             }
         }
         obj2 = this.Runtime.CreateWithFactoryMethod(type2, name.Name, ctx.CurrentCtorArgs);
         XamlType xamlType = this.GetXamlType(obj2.GetType());
         if (!xamlType.CanAssignTo(currentType))
         {
             throw this.WithLineInfo(new XamlObjectWriterException(System.Xaml.SR.Get("NotAssignableFrom", new object[] { currentType.GetQualifiedName(), xamlType.GetQualifiedName() })));
         }
     }
     ctx.CurrentCtorArgs = null;
     ctx.CurrentInstance = obj2;
     if (currentType.IsCollection || currentType.IsDictionary)
     {
         ctx.CurrentCollection = obj2;
     }
     this.Logic_BeginInit(ctx);
     if (((ctx.LiveDepth > 1) && !(obj2 is MarkupExtension)) && (ctx.LiveDepth > 1))
     {
         this.Logic_CheckAssignmentToParentStart(ctx);
     }
     this.OnBeforeProperties(obj2);
     this.Logic_ApplyCurrentPreconstructionPropertyValues(ctx);
 }
 protected override void Dispose(bool disposing)
 {
     try
     {
         this._inDispose = true;
         if (disposing && !base.IsDisposed)
         {
             if ((this._context.LiveDepth > 1) || (this._context.CurrentType != null))
             {
                 while (this._context.LiveDepth > 0)
                 {
                     if (this._context.CurrentProperty != null)
                     {
                         this.WriteEndMember();
                     }
                     this.WriteEndObject();
                 }
             }
             this._deferringWriter.Close();
             this._deferringWriter = null;
             this._context = null;
             this._afterBeginInitHandler = null;
             this._beforePropertiesHandler = null;
             this._afterPropertiesHandler = null;
             this._afterEndInitHandler = null;
         }
     }
     finally
     {
         base.Dispose(disposing);
         this._inDispose = false;
     }
 }
 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);
 }
 private void Initialize(XamlSchemaContext schemaContext, XamlSavedContext savedContext, XamlObjectWriterSettings settings)
 {
     this._inDispose = false;
     if (schemaContext == null)
     {
         throw new ArgumentNullException("schemaContext");
     }
     if ((savedContext != null) && (schemaContext != savedContext.SchemaContext))
     {
         throw new ArgumentException(System.Xaml.SR.Get("SavedContextSchemaContextMismatch"), "schemaContext");
     }
     if (settings != null)
     {
         this._afterBeginInitHandler = settings.AfterBeginInitHandler;
         this._beforePropertiesHandler = settings.BeforePropertiesHandler;
         this._afterPropertiesHandler = settings.AfterPropertiesHandler;
         this._afterEndInitHandler = settings.AfterEndInitHandler;
         this._xamlSetValueHandler = settings.XamlSetValueHandler;
         this._rootObjectInstance = settings.RootObjectInstance;
         this._skipDuplicatePropertyCheck = settings.SkipDuplicatePropertyCheck;
         this._skipProvideValueOnRoot = settings.SkipProvideValueOnRoot;
         this._preferUnconvertedDictionaryKeys = settings.PreferUnconvertedDictionaryKeys;
     }
     INameScope rootNameScope = (settings != null) ? settings.ExternalNameScope : null;
     XamlRuntime runtime = this.CreateRuntime(settings, schemaContext);
     if (savedContext != null)
     {
         this._context = new ObjectWriterContext(savedContext, settings, rootNameScope, runtime);
     }
     else
     {
         if (schemaContext == null)
         {
             throw this.WithLineInfo(new XamlInternalException());
         }
         this._context = new ObjectWriterContext(schemaContext, settings, rootNameScope, runtime);
         this._context.AddNamespacePrefix("xml", "http://www.w3.org/XML/1998/namespace");
     }
     this._context.IsInitializedCallback = this;
     this._deferringWriter = new DeferringWriter(this._context);
     this._rootNamescope = null;
 }
 private bool Logic_CreatePropertyValueFromValue(ObjectWriterContext ctx)
 {
     XamlMember parentProperty = ctx.ParentProperty;
     XamlType type1 = parentProperty.Type;
     object currentInstance = ctx.CurrentInstance;
     XamlReader deferredContent = currentInstance as XamlReader;
     if (deferredContent != null)
     {
         XamlValueConverter<XamlDeferringLoader> deferringLoader = parentProperty.DeferringLoader;
         if (deferringLoader != null)
         {
             ctx.CurrentInstance = this.Runtime.DeferredLoad(ctx.ServiceProviderContext, deferringLoader, deferredContent);
             return true;
         }
     }
     XamlValueConverter<TypeConverter> typeConverter = parentProperty.TypeConverter;
     object obj3 = null;
     XamlType declaringType = null;
     if (parentProperty.IsAttachable)
     {
         declaringType = parentProperty.DeclaringType;
     }
     else
     {
         declaringType = ctx.ParentType;
     }
     if (((parentProperty != null) && !parentProperty.IsUnknown) && (declaringType != null))
     {
         XamlType grandParentType = ctx.GrandParentType;
         if ((parentProperty.IsDirective && (parentProperty == XamlLanguage.Key)) && ((grandParentType != null) && grandParentType.IsDictionary))
         {
             typeConverter = grandParentType.KeyType.TypeConverter;
         }
         if (((typeConverter != null) && (typeConverter.ConverterType != null)) && (typeConverter != BuiltInValueConverter.String))
         {
             TypeConverter converterInstance = this.Runtime.GetConverterInstance<TypeConverter>(typeConverter);
             if ((converterInstance != null) && (declaringType.SetTypeConverterHandler != null))
             {
                 XamlSetTypeConverterEventArgs e = new XamlSetTypeConverterEventArgs(parentProperty, converterInstance, currentInstance, ctx.ServiceProviderContext, TypeConverterHelper.InvariantEnglishUS, ctx.ParentInstance) {
                     CurrentType = declaringType
                 };
                 declaringType.SetTypeConverterHandler(ctx.ParentInstance, e);
                 if (e.Handled)
                 {
                     return false;
                 }
             }
         }
     }
     if (typeConverter != null)
     {
         obj3 = this.Logic_CreateFromValue(ctx, typeConverter, currentInstance, parentProperty, parentProperty.Name);
     }
     else
     {
         obj3 = currentInstance;
     }
     ctx.CurrentInstance = obj3;
     return true;
 }
 private void Logic_AddToParentDictionary(ObjectWriterContext ctx, object key, object value)
 {
     if (ctx.CurrentKeyIsUnconverted && !ctx.ParentShouldNotConvertChildKeys)
     {
         if (!ctx.ParentShouldConvertChildKeys)
         {
             try
             {
                 this.Runtime.AddToDictionary(ctx.ParentCollection, ctx.ParentType, value, ctx.CurrentType, key);
                 ctx.ParentShouldNotConvertChildKeys = true;
                 return;
             }
             catch (XamlObjectWriterException exception)
             {
                 if (!(exception.InnerException is ArgumentException) && !(exception.InnerException is InvalidCastException))
                 {
                     throw;
                 }
                 Debugger.IsLogging();
             }
             ctx.ParentShouldConvertChildKeys = true;
         }
         ctx.CurrentProperty = XamlLanguage.Key;
         ctx.PushScope();
         ctx.CurrentInstance = key;
         this.Logic_CreatePropertyValueFromValue(ctx);
         key = ctx.CurrentInstance;
         ctx.PopScope();
         ctx.CurrentProperty = null;
     }
     this.Runtime.AddToDictionary(ctx.ParentCollection, ctx.ParentType, value, ctx.CurrentType, key);
 }
 private void Logic_DoAssignmentToParentCollection(ObjectWriterContext ctx)
 {
     object parentCollection = ctx.ParentCollection;
     XamlType parentType = ctx.ParentType;
     XamlType currentType = ctx.CurrentType;
     object currentInstance = ctx.CurrentInstance;
     if (!parentType.IsDictionary)
     {
         if (!this.Logic_PendAssignmentToParentCollection(ctx, null, false))
         {
             MarkupExtension me = currentInstance as MarkupExtension;
             if ((me != null) && !this.Logic_WillParentCollectionAdd(ctx, currentInstance.GetType(), true))
             {
                 currentInstance = this.Runtime.CallProvideValue(me, ctx.ServiceProviderContext);
             }
             this.Runtime.Add(parentCollection, parentType, currentInstance, currentType);
         }
     }
     else
     {
         if (currentType == null)
         {
             currentType = (currentInstance == null) ? parentType.ItemType : this.GetXamlType(currentInstance.GetType());
         }
         object currentKey = ctx.CurrentKey;
         bool currentIsKeySet = ctx.CurrentIsKeySet;
         if (!this.Logic_PendAssignmentToParentCollection(ctx, currentKey, currentIsKeySet))
         {
             if (!currentIsKeySet)
             {
                 currentKey = this.GetKeyFromInstance(currentInstance, currentType, this);
             }
             this.Logic_AddToParentDictionary(ctx, currentKey, currentInstance);
         }
     }
 }
 private void Logic_ApplyCurrentPreconstructionPropertyValues(ObjectWriterContext ctx)
 {
     this.Logic_ApplyCurrentPreconstructionPropertyValues(ctx, false);
 }
 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);
         }
     }
 }
 private void Logic_ApplyCurrentPreconstructionPropertyValues(ObjectWriterContext ctx, bool skipDirectives)
 {
     if (ctx.CurrentHasPreconstructionPropertyValuesDictionary)
     {
         Dictionary<XamlMember, object> currentPreconstructionPropertyValues = ctx.CurrentPreconstructionPropertyValues;
         object obj2 = null;
         foreach (XamlMember member in currentPreconstructionPropertyValues.Keys)
         {
             if (!skipDirectives || !member.IsDirective)
             {
                 obj2 = currentPreconstructionPropertyValues[member];
                 MarkupExtension me = obj2 as MarkupExtension;
                 if ((me != null) && !member.IsDirective)
                 {
                     this.Logic_PushAndPopAProvideValueStackFrame(ctx, member, me, true);
                 }
                 else
                 {
                     this.Logic_ApplyPropertyValue(ctx, member, obj2, false);
                 }
             }
         }
     }
 }
 private bool Logic_PendAssignmentToParentCollection(ObjectWriterContext ctx, object key, bool keyIsSet)
 {
     object parentCollection = ctx.ParentCollection;
     object currentInstance = ctx.CurrentInstance;
     NameFixupToken token = key as NameFixupToken;
     NameFixupToken token2 = currentInstance as NameFixupToken;
     List<PendingCollectionAdd> list = null;
     if (this._pendingCollectionAdds != null)
     {
         this.PendingCollectionAdds.TryGetValue(parentCollection, out list);
     }
     if ((list == null) && (((token != null) || (token2 != null)) || (this.HasUnresolvedChildren(key) || this.HasUnresolvedChildren(currentInstance))))
     {
         list = new List<PendingCollectionAdd>();
         this.PendingCollectionAdds.Add(parentCollection, list);
     }
     if (token != null)
     {
         token.Target.KeyHolder = null;
         token.Target.TemporaryCollectionIndex = list.Count;
     }
     if (token2 != null)
     {
         this.PendCurrentFixupToken_SetValue(token2);
         token2.Target.TemporaryCollectionIndex = list.Count;
     }
     if (list == null)
     {
         return false;
     }
     PendingCollectionAdd item = new PendingCollectionAdd {
         Key = key,
         KeyIsSet = keyIsSet,
         KeyIsUnconverted = ctx.CurrentKeyIsUnconverted,
         Item = currentInstance,
         ItemType = ctx.CurrentType,
         LineNumber = this._lineNumber,
         LinePosition = this._linePosition
     };
     list.Add(item);
     if (item.KeyIsUnconverted && !this.PendingKeyConversionContexts.ContainsKey(parentCollection))
     {
         XamlSavedContext savedContext = ctx.GetSavedContext(SavedContextType.ReparseMarkupExtension);
         this.PendingKeyConversionContexts.Add(parentCollection, new ObjectWriterContext(savedContext, null, null, this.Runtime));
     }
     return true;
 }
 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);
             }
         }
     }
 }