Fragment

Namespace: Protogame
We found 10 examples in language CSharp for this search. You will see 38 fragments of code.

        protected IEnumerable<Fragment> GetCurrentCacheableFragments()
        {
            var currentFragments = SupportFragmentManager.Fragments ?? Enumerable.Empty<Fragment>();

            return currentFragments
                .Where(fragment => fragment != null)
                // we are not interested in fragments which are not supposed to cache!
                .Where(fragment => fragment.GetType().IsFragmentCacheable());
        }

        protected string GetTagFromFragment(Fragment fragment)
        {
            var mvxFragmentView = fragment as IMvxFragmentView;

            // ReSharper disable once PossibleNullReferenceException
            // Fragment can never be null because registered fragment has to inherit from IMvxFragmentView
            return mvxFragmentView.UniqueImmutableCacheTag;
        }


		protected IEnumerable<Fragment> GetCurrentCacheableFragments()
		{
			var currentFragments = SupportFragmentManager.Fragments ?? Enumerable.Empty<Fragment>();

			return currentFragments
				.Where(fragment => fragment != null)
				// we are not interested in fragments which are not supposed to cache!
				.Where(fragment => fragment.GetType().IsFragmentCacheable());
		}

		protected string GetTagFromFragment(Fragment fragment)
		{
			var mvxFragmentView = fragment as IMvxFragmentView;

			// ReSharper disable once PossibleNullReferenceException
			// Fragment can never be null because registered fragment has to inherit from IMvxFragmentView
			return mvxFragmentView.UniqueImmutableCacheTag;
		}

        public static void AddEventListeners(this IMvxEventSourceFragment fragment)
        {
            if (fragment is IMvxFragmentView)
            {
                var adapter = new MvxBindingFragmentAdapter(fragment);
            }
        }

        public static Fragment ToFragment(this IMvxFragmentView fragmentView)
        {
            var activity = fragmentView as Fragment;
            if (activity == null)
                throw new MvxException("ToFragment called on an IMvxFragmentView which is not an Android Fragment: {0}", fragmentView);
            return activity;
        }

        public static void EnsureSetupInitialized(this IMvxFragmentView fragmentView)
        {
            var fragment = fragmentView.ToFragment();
            var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(fragment.Activity.ApplicationContext);
            setupSingleton.EnsureInitialized();
        }


        public abstract Fragment GetItem(int position, Fragment.SavedState fragmentSavedState = null);

        public override bool IsViewFromObject(View view, Object objectValue)
        {
            return ((Fragment)objectValue).View == view;
        }


        public abstract Fragment GetItem(int position, Fragment.SavedState fragmentSavedState = null);

        public override bool IsViewFromObject(View view, Object objectValue)
        {
            return ((Fragment)objectValue).View == view;
        }


		[Test]
		public void Constructor ()
		{
			XmlDocument d = new XmlDocument ();
			XmlDocumentFragment df = d.CreateDocumentFragment ();
			Assert.AreEqual ("#document-fragment", df.Name, "#Constructor.NodeName");
			Assert.AreEqual (XmlNodeType.DocumentFragment, df.NodeType, "#Constructor.NodeType");
		}

		[Test]
		public void AppendChildToFragment ()
		{
			document = new XmlDocument ();
			fragment = document.CreateDocumentFragment ();
			document.LoadXml ("<html><head></head><body></body></html>");
			XmlElement el = document.CreateElement ("p");
			el.InnerXml = "Test Paragraph";

			// appending element to fragment
			fragment.AppendChild (el);
			Assert.IsNotNull (fragment.FirstChild, "#AppendChildToFragment.Element");
			Assert.IsNotNull (fragment.FirstChild.FirstChild, "#AppendChildToFragment.Element.Children");
			Assert.AreEqual ("Test Paragraph", fragment.FirstChild.FirstChild.Value, "#AppendChildToFragment.Element.Child.Text");
		}

		[Test]
		public void AppendFragmentToElement ()
		{
			document = new XmlDocument ();
			fragment = document.CreateDocumentFragment ();
			document.LoadXml ("<html><head></head><body></body></html>");
			XmlElement body = document.DocumentElement.LastChild as XmlElement;
			fragment.AppendChild (document.CreateElement ("p"));
			fragment.AppendChild (document.CreateElement ("div"));

			// appending fragment to element
			XmlNode ret = body.AppendChild (fragment);
			Assert.IsNotNull (body.FirstChild, "#AppendFragmentToElement.Exist");
			Assert.AreEqual (XmlNodeType.Element, body.FirstChild.NodeType, "#AppendFragmentToElement.ChildIsElement");
			Assert.AreEqual ("p", body.FirstChild.Name, "#AppendFragmentToElement.FirstChild");
			Assert.AreEqual ("div", body.LastChild.Name, "#AppendFragmentToElement.LastChild");
			Assert.AreEqual ("p", ret.LocalName, "#AppendFragmentToElement.ReturnValue");
		}

		[Test]
		public void GetInnerXml ()
		{
			// this will be also tests of TestWriteTo()/TestWriteContentTo()

			document = new XmlDocument ();
			fragment = document.CreateDocumentFragment ();
			fragment.AppendChild (document.CreateElement ("foo"));
			fragment.AppendChild (document.CreateElement ("bar"));
			fragment.AppendChild (document.CreateElement ("baz"));
			Assert.AreEqual ("<foo /><bar /><baz />", fragment.InnerXml, "#Simple");
		}

		[Test]
		public void SetInnerXml ()
		{
			document = new XmlDocument ();
			fragment = document.CreateDocumentFragment ();
			fragment.InnerXml = "<foo /><bar><child /></bar><baz />";
			Assert.AreEqual ("foo", fragment.FirstChild.Name);
			Assert.AreEqual ("bar", fragment.FirstChild.NextSibling.Name);
			Assert.AreEqual ("child", fragment.FirstChild.NextSibling.FirstChild.Name);
			Assert.AreEqual ("baz", fragment.LastChild.Name);
		}

		[Test]
		public void InnerText ()
		{
			document = new XmlDocument ();
			fragment = document.CreateDocumentFragment ();
			string text = "<foo /><bar><child /></bar><baz />";
			fragment.InnerText = text;
			Assert.AreEqual (text, fragment.InnerText);
		}


        #endregion Properties

        #region IEnumerable Members

        /// <summary>
        /// Gets an enumerator that can iterate through the fragment list.
        /// </summary>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion IEnumerable Members

        #region Public Methods

        /// <summary>
        /// Appends a fragment to the list of fragments.
        /// </summary>
        /// <param name="newFragment">The fragment to append. May not be null.</param>
        public void Append(MixedCodeDocumentFragment newFragment)
        {
            if (newFragment == null)
            {
                throw new ArgumentNullException("newFragment");
            }
            _items.Add(newFragment);
        }

        /// <summary>
        /// Gets an enumerator that can iterate through the fragment list.
        /// </summary>
        public MixedCodeDocumentFragmentEnumerator GetEnumerator()
        {
            return new MixedCodeDocumentFragmentEnumerator(_items);
        }

        /// <summary>
        /// Prepends a fragment to the list of fragments.
        /// </summary>
        /// <param name="newFragment">The fragment to append. May not be null.</param>
        public void Prepend(MixedCodeDocumentFragment newFragment)
        {
            if (newFragment == null)
            {
                throw new ArgumentNullException("newFragment");
            }
            _items.Insert(0, newFragment);
        }

        /// <summary>
        /// Remove a fragment from the list of fragments. If this fragment was not in the list, an exception will be raised.
        /// </summary>
        /// <param name="fragment">The fragment to remove. May not be null.</param>
        public void Remove(MixedCodeDocumentFragment fragment)
        {
            if (fragment == null)
            {
                throw new ArgumentNullException("fragment");
            }
            int index = GetFragmentIndex(fragment);
            if (index == -1)
            {
                throw new IndexOutOfRangeException();
            }
            RemoveAt(index);
        }

        /// <summary>
        /// Remove all fragments from the list.
        /// </summary>
        public void RemoveAll()
        {
            _items.Clear();
        }

        /// <summary>
        /// If you override this method make sure you override ConvertSerializableCachedFragmentInfo and GetObjectToSerializeFromCachedFragmentInfo
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="fragmentType"></param>
        /// <param name="viewModelType"></param>
        /// <param name="cacheFragment"></param>
        /// <param name="addToBackstack"></param>
        /// <returns></returns>
        public virtual IMvxCachedFragmentInfo CreateFragmentInfo(string tag, Type fragmentType, Type viewModelType, bool cacheFragment = true, bool addToBackstack = false)
        {
            if (!typeof(IMvxFragmentView).IsAssignableFrom(fragmentType))
                throw new InvalidOperationException($"Registered fragment isn't an IMvxFragmentView. Received: {fragmentType}");

            if (!typeof(IMvxViewModel).IsAssignableFrom(viewModelType))
                throw new InvalidOperationException($"Registered view model isn't an IMvxViewModel. Received: {viewModelType}");

            return new MvxCachedFragmentInfo(tag, fragmentType, viewModelType, cacheFragment, addToBackstack);
        }

        public virtual SerializableMvxCachedFragmentInfo GetSerializableFragmentInfo(IMvxCachedFragmentInfo objectToSerialize)
        {
            return new SerializableMvxCachedFragmentInfo()
            {
                Tag = objectToSerialize.Tag,
                FragmentType = objectToSerialize.FragmentType,
                ViewModelType = objectToSerialize.ViewModelType,
                CacheFragment = objectToSerialize.CacheFragment,
                ContentId = objectToSerialize.ContentId,
                AddToBackStack = objectToSerialize.AddToBackStack
            };
        }

        public virtual IMvxCachedFragmentInfo ConvertSerializableFragmentInfo(
            SerializableMvxCachedFragmentInfo fromSerializableMvxCachedFragmentInfo)
        {
            return new MvxCachedFragmentInfo(fromSerializableMvxCachedFragmentInfo.Tag,
                           fromSerializableMvxCachedFragmentInfo.FragmentType,
                           fromSerializableMvxCachedFragmentInfo.ViewModelType,
                           fromSerializableMvxCachedFragmentInfo.CacheFragment,
                           fromSerializableMvxCachedFragmentInfo.AddToBackStack)
            {
                ContentId = fromSerializableMvxCachedFragmentInfo.ContentId
            };
        }


        #endregion

        #region IEnumerable Members

        /// <summary>
        /// Gets an enumerator that can iterate through the fragment list.
        /// </summary>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Appends a fragment to the list of fragments.
        /// </summary>
        /// <param name="newFragment">The fragment to append. May not be null.</param>
        public void Append(MixedCodeDocumentFragment newFragment)
        {
            if (newFragment == null)
            {
                throw new ArgumentNullException("newFragment");
            }
            _items.Add(newFragment);
        }

        /// <summary>
        /// Gets an enumerator that can iterate through the fragment list.
        /// </summary>
        public MixedCodeDocumentFragmentEnumerator GetEnumerator()
        {
            return new MixedCodeDocumentFragmentEnumerator(_items);
        }

        /// <summary>
        /// Prepends a fragment to the list of fragments.
        /// </summary>
        /// <param name="newFragment">The fragment to append. May not be null.</param>
        public void Prepend(MixedCodeDocumentFragment newFragment)
        {
            if (newFragment == null)
            {
                throw new ArgumentNullException("newFragment");
            }
            _items.Insert(0, newFragment);
        }

        /// <summary>
        /// Remove a fragment from the list of fragments. If this fragment was not in the list, an exception will be raised.
        /// </summary>
        /// <param name="fragment">The fragment to remove. May not be null.</param>
        public void Remove(MixedCodeDocumentFragment fragment)
        {
            if (fragment == null)
            {
                throw new ArgumentNullException("fragment");
            }
            int index = GetFragmentIndex(fragment);
            if (index == -1)
            {
                throw new IndexOutOfRangeException();
            }
            RemoveAt(index);
        }

        /// <summary>
        /// Remove all fragments from the list.
        /// </summary>
        public void RemoveAll()
        {
            _items.Clear();
        }


        public static EdmProperty GetDefaultDiscriminator(
            this MappingFragment entityTypeMapppingFragment)
        {
            DebugCheck.NotNull(entityTypeMapppingFragment);

            return
                (EdmProperty)
                entityTypeMapppingFragment.Annotations.GetAnnotation(DefaultDiscriminatorAnnotation);
        }

        public static void SetDefaultDiscriminator(
            this MappingFragment entityTypeMappingFragment, EdmProperty discriminator)
        {
            DebugCheck.NotNull(entityTypeMappingFragment);

            entityTypeMappingFragment.Annotations.SetAnnotation(DefaultDiscriminatorAnnotation, discriminator);
        }

        public static void RemoveDefaultDiscriminatorAnnotation(
            this MappingFragment entityTypeMappingFragment)
        {
            DebugCheck.NotNull(entityTypeMappingFragment);

            entityTypeMappingFragment.Annotations.RemoveAnnotation(DefaultDiscriminatorAnnotation);
        }

        public static void RemoveDefaultDiscriminator(
            this MappingFragment entityTypeMappingFragment, EntitySetMapping entitySetMapping)
        {
            DebugCheck.NotNull(entityTypeMappingFragment);

            var discriminatorColumn = entityTypeMappingFragment.RemoveDefaultDiscriminatorCondition();
            if (discriminatorColumn != null)
            {
                var table = entityTypeMappingFragment.Table;

                table.Properties
                     .Where(c => c.Name.Equals(discriminatorColumn.Name, StringComparison.Ordinal))
                     .ToList()
                     .Each(table.RemoveMember);
            }

            if (entitySetMapping != null
                && entityTypeMappingFragment.IsConditionOnlyFragment()
                &&
                !entityTypeMappingFragment.ColumnConditions.Any())
            {
                var entityTypeMapping =
                    entitySetMapping.EntityTypeMappings.Single(
                        etm => etm.MappingFragments.Contains(entityTypeMappingFragment));

                entityTypeMapping.RemoveFragment(entityTypeMappingFragment);

                if (entityTypeMapping.MappingFragments.Count == 0)
                {
                    entitySetMapping.RemoveTypeMapping(entityTypeMapping);
                }
            }
        }

        public static EdmProperty RemoveDefaultDiscriminatorCondition(
            this MappingFragment entityTypeMappingFragment)
        {
            DebugCheck.NotNull(entityTypeMappingFragment);

            var discriminatorColumn = entityTypeMappingFragment.GetDefaultDiscriminator();

            if (discriminatorColumn != null
                && entityTypeMappingFragment.ColumnConditions.Any())
            {
                Debug.Assert(entityTypeMappingFragment.ColumnConditions.Count() == 1);

                entityTypeMappingFragment.ClearConditions();
            }

            entityTypeMappingFragment.RemoveDefaultDiscriminatorAnnotation();

            return discriminatorColumn;
        }

        public static void AddDiscriminatorCondition(
            this MappingFragment entityTypeMapppingFragment,
            EdmProperty discriminatorColumn,
            object value)
        {
            DebugCheck.NotNull(entityTypeMapppingFragment);
            DebugCheck.NotNull(discriminatorColumn);
            DebugCheck.NotNull(value);

            entityTypeMapppingFragment
                .AddConditionProperty(
                    new ValueConditionMapping(discriminatorColumn, value));
        }

Protogame.Fragment : Object

Constructors :

public Fragment(Byte[] data = , FragmentStatus status = )

Methods :

public Byte[] get_Data()
public Void set_Data(Byte[] value = )
public FragmentStatus get_Status()
public Void set_Status(FragmentStatus value = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()