SIL.FieldWorks.XWorks.DictionaryPublicationDecorator.get_VecSize C# (CSharp) Method

get_VecSize() public method

public get_VecSize ( int hvo, int tag ) : int
hvo int
tag int
return int
		public override int get_VecSize(int hvo, int tag)
		{
			// Enhance JohnT: might be more efficient to call base if not a modified property?
			return VecProp(hvo, tag).Length;
		}

Usage Example

コード例 #1
0
        public void SimpleFiltering()
        {
            // Try all the variants of retrieving a vector property.
            var sensesOfHot = m_decorator.VecProp(m_hot.Hvo, LexEntryTags.kflidSenses);

            Assert.That(sensesOfHot.Length, Is.EqualTo(2), "one bad sense should be eliminated.");
            Assert.That(sensesOfHot[0], Is.EqualTo(m_hot.SensesOS[0].Hvo));
            Assert.That(sensesOfHot[1], Is.EqualTo(m_desirable.Hvo));

            Assert.That(m_decorator.get_VecSize(m_hot.Hvo, LexEntryTags.kflidSenses), Is.EqualTo(2));
            Assert.That(m_decorator.get_VecItem(m_hot.Hvo, LexEntryTags.kflidSenses, 1), Is.EqualTo(m_desirable.Hvo));

            // This test is perhaps redundant here: DictionaryPublicationDecorator does not have to do anything to get this behavior.
            using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative <int>(2))
            {
                int chvo;
                m_decorator.VecProp(m_hot.Hvo, LexEntryTags.kflidSenses, 2, out chvo, arrayPtr);
                var values = MarshalEx.NativeToArray <int>(arrayPtr, 2);
                Assert.That(values[0], Is.EqualTo(m_hot.SensesOS[0].Hvo));
                Assert.That(values[1], Is.EqualTo(m_desirable.Hvo));
            }

            // This verifies both that examples are included in the bad objects, and that properties
            // that point at examples are automatically excluded.
            var hotTempExamples = m_decorator.VecProp(m_hotTemp.Hvo, LexSenseTags.kflidExamples);

            Assert.That(hotTempExamples.Length, Is.EqualTo(1));
            Assert.That(hotTempExamples[0], Is.EqualTo(m_goodHot.Hvo));

            // They should be filtered also from certain properties with CmObject signatures.
            var hotWaterComponents = m_decorator.VecProp(m_hotWaterComponents.Hvo, LexEntryRefTags.kflidComponentLexemes);

            Assert.That(hotWaterComponents.Length, Is.EqualTo(1));
            Assert.That(hotWaterComponents[0], Is.EqualTo(m_waterH2O.Hvo));
            // More cursory checks...there are many of these.
            Assert.That(m_decorator.VecProp(m_hotWaterComponents.Hvo, LexEntryRefTags.kflidPrimaryLexemes).Length, Is.EqualTo(1));
            // As well as checking that LexReference.Targets is filtered, this checks that we filter senses of excluded entries,
            // and that it really is possible for more than one thing to pass the filter.
            Assert.That(m_decorator.VecProp(m_blankSynonyms.Hvo, LexReferenceTags.kflidTargets).Length, Is.EqualTo(2));

            // They should be filtered from the top-level list of entries managed by the wrapped decorator
            var mainEntryList = m_decorator.VecProp(Cache.LangProject.LexDbOA.Hvo, ObjectListPublisher.OwningFlid);

            Assert.That(mainEntryList.Length,
                        Is.EqualTo(Cache.LangProject.LexDbOA.Entries.Where(
                                       le => le.DoNotPublishInRC.Count == 0 &&
                                       le.DoNotShowMainEntryInRC.Count == 0).Count()));
        }