//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using Windows.UI.Xaml.Markup;
using Windows.UI.Xaml;
using Flashcard.XamlTypeInfo;

namespace Flashcard
{
    public partial class App : IXamlMetadataProvider
    {
        private XamlTypeInfoProvider _provider;

        public IXamlType GetXamlType(String typeName)
        {
            if(_provider == null)
            {
                _provider = new XamlTypeInfoProvider();
            }
            return _provider.GetXamlTypeByName(typeName);
        }

        public XmlnsDefinition[] GetXmlnsDefinitions()
        {
            return new XmlnsDefinition[0];
        }
    }
}

namespace Flashcard.XamlTypeInfo
{
    internal partial class XamlTypeInfoProvider
    {
        public IXamlType GetXamlTypeByName(string typeName)
        {
            if (String.IsNullOrEmpty(typeName))
            {
                return null;
            }
            IXamlType xamlType;
            if (_xamlTypes.TryGetValue(typeName, out xamlType))
            {
                return xamlType;
            }
            xamlType = CreateXamlType(typeName);
            if (xamlType != null)
            {
                _xamlTypes.Add(typeName, xamlType);
            }
            return xamlType;
        }

        public IXamlMember GetMemberByLongName(string longMemberName)
        {
            if (String.IsNullOrEmpty(longMemberName))
            {
                return null;
            }
            IXamlMember xamlMember;
            if (_xamlMembers.TryGetValue(longMemberName, out xamlMember))
            {
                return xamlMember;
            }
            xamlMember = CreateXamlMember(longMemberName);
            if (xamlMember != null)
            {
                _xamlMembers.Add(longMemberName, xamlMember);
            }
            return xamlMember;
        }

        Dictionary<string, IXamlType> _xamlTypes = new Dictionary<string, IXamlType>();
        Dictionary<string, IXamlMember> _xamlMembers = new Dictionary<string, IXamlMember>();


        private object Activate_0_GoToStateServices() { return new ReflectionIT.Windows8.Helpers.GoToStateServices(); }


        private object Activate_1_AnswerButton() { return new Flashcard.Views.AnswerButton(); }


        private object Activate_2_MainPage() { return new Flashcard.Views.MainPage(); }



        private IXamlType CreateXamlType(string typeName)
        {
            XamlSystemBaseType xamlType = null;
            XamlUserType userType;

            switch (typeName)
            {
            case "Windows.Foundation.Object":
                xamlType = new XamlSystemBaseType(typeName, typeof(System.Object));
                break;

            case "Windows.UI.Xaml.DependencyObject":
                xamlType = new XamlSystemBaseType(typeName, typeof(Windows.UI.Xaml.DependencyObject));
                break;

            case "Windows.UI.Xaml.Controls.UserControl":
                xamlType = new XamlSystemBaseType(typeName, typeof(Windows.UI.Xaml.Controls.UserControl));
                break;

            case "ReflectionIT.Windows8.Helpers.GoToStateServices":
                userType = new XamlUserType(this, typeName, typeof(ReflectionIT.Windows8.Helpers.GoToStateServices), GetXamlTypeByName("Windows.Foundation.Object"));
                userType.Activator = Activate_0_GoToStateServices;
                userType.AddMemberName("Binding", "ReflectionIT.Windows8.Helpers.GoToStateServices.Binding");
                userType.AddMemberName("BindingType", "ReflectionIT.Windows8.Helpers.GoToStateServices.BindingType");
                xamlType = userType;
                break;
            case "Flashcard.Views.AnswerButton":
                userType = new XamlUserType(this, typeName, typeof(Flashcard.Views.AnswerButton), GetXamlTypeByName("Windows.UI.Xaml.Controls.UserControl"));
                userType.Activator = Activate_1_AnswerButton;
                xamlType = userType;
                break;
            case "Flashcard.Views.MainPage":
                userType = new XamlUserType(this, typeName, typeof(Flashcard.Views.MainPage), GetXamlTypeByName("Windows.UI.Xaml.Controls.UserControl"));
                userType.Activator = Activate_2_MainPage;
                xamlType = userType;
                break;
            }
            return xamlType;
        }


        private object get_0_GoToStateServices_Binding(object instance)
        {
            return ReflectionIT.Windows8.Helpers.GoToStateServices.GetBinding((Windows.UI.Xaml.DependencyObject)instance);
        }
        private void set_0_GoToStateServices_Binding(object instance, object Value)
        {
            ReflectionIT.Windows8.Helpers.GoToStateServices.SetBinding((Windows.UI.Xaml.DependencyObject)instance, (System.Object)Value);
                    }
        private object get_1_GoToStateServices_BindingType(object instance)
        {
            return ReflectionIT.Windows8.Helpers.GoToStateServices.GetBindingType((Windows.UI.Xaml.DependencyObject)instance);
        }
        private void set_1_GoToStateServices_BindingType(object instance, object Value)
        {
            ReflectionIT.Windows8.Helpers.GoToStateServices.SetBindingType((Windows.UI.Xaml.DependencyObject)instance, (System.Object)Value);
                    }

        private IXamlMember CreateXamlMember(string longMemberName)
        {
            XamlMember xamlMember = null;
            XamlUserType userType;

            switch (longMemberName)
            {
            case "ReflectionIT.Windows8.Helpers.GoToStateServices.Binding":
                userType = (XamlUserType)GetXamlTypeByName("ReflectionIT.Windows8.Helpers.GoToStateServices");
                xamlMember = new XamlMember(this, "Binding", "Windows.Foundation.Object");
                xamlMember.SetTargetTypeName("Windows.UI.Xaml.DependencyObject");
                xamlMember.SetIsAttachable();
                xamlMember.Getter = get_0_GoToStateServices_Binding;
                xamlMember.Setter = set_0_GoToStateServices_Binding;
                break;
            case "ReflectionIT.Windows8.Helpers.GoToStateServices.BindingType":
                userType = (XamlUserType)GetXamlTypeByName("ReflectionIT.Windows8.Helpers.GoToStateServices");
                xamlMember = new XamlMember(this, "BindingType", "Windows.Foundation.Object");
                xamlMember.SetTargetTypeName("Windows.UI.Xaml.DependencyObject");
                xamlMember.SetIsAttachable();
                xamlMember.Getter = get_1_GoToStateServices_BindingType;
                xamlMember.Setter = set_1_GoToStateServices_BindingType;
                break;
            }
            return xamlMember;
        }

    }

    internal class XamlSystemBaseType : IXamlType
    {
        string _fullName;
        Type _underlyingType;

        public XamlSystemBaseType(string fullName, Type underlyingType)
        {
            _fullName = fullName;
            _underlyingType = underlyingType;
        }

        virtual public bool IsSystemType { get { return true; } }
        public string FullName { get { return _fullName; } }

        public string Name
        {
            get
            {
                int idx = _fullName.LastIndexOf('.');
                if (idx == -1)
                {
                    return _fullName;
                }
                return _fullName.Substring(idx + 1);
            }
        }

        public Type UnderlyingType
        {
            get
            {
                return _underlyingType;
            }
        }

        virtual public IXamlType BaseType { get { throw new NotImplementedException(); } }
        virtual public IXamlMember ContentProperty { get { throw new NotImplementedException(); } }
        virtual public IXamlMember GetMember(string name) { throw new NotImplementedException(); }
        virtual public bool IsArray { get { throw new NotImplementedException(); } }
        virtual public bool IsCollection { get { throw new NotImplementedException(); } }
        virtual public bool IsConstructible { get { throw new NotImplementedException(); } }
        virtual public bool IsDictionary { get { throw new NotImplementedException(); } }
        virtual public bool IsMarkupExtension { get { throw new NotImplementedException(); } }
        virtual public IXamlType ItemType { get { throw new NotImplementedException(); } }
        virtual public IXamlType KeyType { get { throw new NotImplementedException(); } }
        virtual public object ActivateInstance() { throw new NotImplementedException(); }
        virtual public void AddToMap(object instance, object key, object item)  { throw new NotImplementedException(); }
        virtual public void AddToVector(object instance, object item)  { throw new NotImplementedException(); }
        virtual public void RunInitializer()   { throw new NotImplementedException(); }
    }
    
    internal delegate object Activator();
    internal delegate void AddToCollection(object instance, object item);
    internal delegate void AddToDictionary(object instance, object key, object item);

    internal class XamlUserType : XamlSystemBaseType
    {
        XamlTypeInfoProvider _provider;
        IXamlType _baseType;
        bool _isArray;
        bool _isMarkupExtension;

        string _contentPropertyName;
        string _itemTypeName;
        string _keyTypeName;
        Dictionary<string, string> _memberNames;

        public XamlUserType(XamlTypeInfoProvider provider, string fullName, Type fullType, IXamlType baseType)
            :base(fullName, fullType)
        {
            _provider = provider;
            _baseType = baseType;
        }

        override public bool IsSystemType { get { return false; } }
        override public IXamlType BaseType { get { return _baseType; } }

        public Activator Activator { get; set; }
        public AddToCollection CollectionAdd { get; set; }
        public AddToDictionary DictionaryAdd { get; set; }

        public void SetContentPropertyName(string contentPropertyName)
        {
            _contentPropertyName = contentPropertyName;
        }
        override public IXamlMember ContentProperty
        {
            get { return _provider.GetMemberByLongName(_contentPropertyName); }
        }

        public void SetIsArray() { _isArray = true; }
        override public bool IsArray { get { return _isArray; } }

        override public bool IsCollection { get { return (CollectionAdd != null); } }
        override public bool IsConstructible { get { return (Activator != null); } }
        override public bool IsDictionary { get { return (DictionaryAdd != null); } }

        public void SetIsMarkupExtension() { _isMarkupExtension = true; }
        override public bool IsMarkupExtension { get { return _isMarkupExtension; } }

        public void SetItemTypeName(string itemTypeName)
        {
            _itemTypeName = itemTypeName;
        }
        override public IXamlType ItemType
        {
            get { return _provider.GetXamlTypeByName(_itemTypeName); }
        }

        public void SetKeyTypeName(string keyTypeName)
        {
            _keyTypeName = keyTypeName;
        }
        override public IXamlType KeyType
        {
            get { return _provider.GetXamlTypeByName(_keyTypeName); }
        }

        public void AddMemberName(string shortName, string longName)
        {
            if(_memberNames == null)
            {
                _memberNames =  new Dictionary<string,string>();
            }
            _memberNames.Add(shortName, longName);
        }

        override public IXamlMember GetMember(string name)
        {
            if (_memberNames == null)
            {
                return null;
            }
            string longName;
            if (_memberNames.TryGetValue(name, out longName))
            {
                return _provider.GetMemberByLongName(longName);
            }
            return null;
        }

        override public object ActivateInstance()
        {
            return Activator(); 
        }

        override public void AddToMap(object instance, object key, object item) 
        {
            DictionaryAdd(instance, key, item);
        }

        override public void AddToVector(object instance, object item)
        {
            CollectionAdd(instance, item);
        }

        override public void RunInitializer() 
        {
            System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(UnderlyingType.TypeHandle);
        }
    }

    internal delegate object Getter(object instance);
    internal delegate void Setter(object instance, object value);

    internal class XamlMember : IXamlMember
    {
        XamlTypeInfoProvider _provider;
        string _name;
        bool _isAttachable;
        bool _isDependencyProperty;
        bool _isReadOnly;

        string _typeName;
        string _targetTypeName;

        public XamlMember(XamlTypeInfoProvider provider, string name, string typeName)
        {
            _name = name;
            _typeName = typeName;
            _provider = provider;
        }

        public string Name { get { return _name; } }

        public IXamlType Type
        {
            get { return _provider.GetXamlTypeByName(_typeName); }
        }

        public void SetTargetTypeName(String targetTypeName)
        {
            _targetTypeName = targetTypeName;
        }
        public IXamlType TargetType
        {
            get { return _provider.GetXamlTypeByName(_targetTypeName); }
        }

        public void SetIsAttachable() { _isAttachable = true; }
        public bool IsAttachable { get { return _isAttachable; } }

        public void SetIsDependencyProperty() { _isDependencyProperty = true; }
        public bool IsDependencyProperty { get { return _isDependencyProperty; } }

        public void SetIsReadOnly() { _isReadOnly = true; }
        public bool IsReadOnly { get { return _isReadOnly; } }

        public Getter Getter { get; set; }
        public object GetValue(object instance)
        {
            if (Getter != null)
                return Getter(instance);
            else
                throw new InvalidOperationException("GetValue");
        }

        public Setter Setter { get; set; }
        public void SetValue(object instance, object value)
        {
            if (Setter != null)
                Setter(instance, value);
            else
                throw new InvalidOperationException("SetValue");
        }
    }
}




