Ecologylab.BigSemantics.MetaMetadataNS.MetaMetadataNestedField.BindMetadataFieldDescriptors C# (CSharp) Метод

BindMetadataFieldDescriptors() защищенный Метод

protected BindMetadataFieldDescriptors ( SimplTypesScope metadataTScope, MetadataClassDescriptor metadataClassDescriptorToBind ) : void
metadataTScope Simpl.Serialization.SimplTypesScope
metadataClassDescriptorToBind Ecologylab.BigSemantics.MetadataNS.MetadataClassDescriptor
Результат void
        protected void BindMetadataFieldDescriptors(SimplTypesScope metadataTScope,
            MetadataClassDescriptor metadataClassDescriptorToBind)
        {
            bool needCloneKids = false;

            // check if the class's base class is genereic typed, and make sure itself is not generic.
            MetadataClassDescriptor metadataCd = MetadataClassDescriptor;
            MetaMetadata baseMmd = TypeMmd;
            while(baseMmd != null && metadataCd != null)
            {
                if (metadataCd.GetGenericTypeVars().Count == 0 && baseMmd.GenericTypeVars != null)
                {
                    needCloneKids = true;
                    break;
                }
                metadataCd = baseMmd.MetadataClassDescriptor;
                baseMmd = baseMmd.TypeMmd;
            }

            if (needCloneKids)
            {
                DictionaryList<string, MetaMetadataField> clonedKids = new DictionaryList<string, MetaMetadataField>();
                foreach (KeyValuePair<string, MetaMetadataField> entry in Kids)
                {
                    string key = entry.Key;
                    MetaMetadataField field = entry.Value;

                    // look up to see if the field is declared in a generic typed class. If not, it does not need to clone it.
                    MetaMetadata declaringMmd = field.DeclaringMmd;
                    if (declaringMmd != null && declaringMmd.GenericTypeVars != null && declaringMmd.IsGenericMetadata)
                    {
                        // clone the field
                        field = field.Clone();
                        // remove the inherited field descriptor
                        field.MetadataFieldDescriptor = null;
                    }
                    clonedKids.Put(key, field);
                }
                Kids = clonedKids;
            }

            // copy the kids collection first to prevent modification to the collection during iteration (which may invalidate the iterator).
            List<MetaMetadataField> fields = new List<MetaMetadataField>(Kids.Values);

            foreach (MetaMetadataField thatChild in fields)
            {
                // look up by field name and bind
                MetadataFieldDescriptor metadataFd = thatChild.BindMetadataFieldDescriptor(metadataTScope, metadataClassDescriptorToBind);
                if (metadataFd == null)
                {
                    Debug.WriteLine("Cannot bind metadata field descriptor for " + thatChild);
                    Kids.Remove(thatChild.Name);
                    continue;
                }

                // set defininig mmdfield

                // process hide and shadows
                var isImage = thatChild is MetaMetadataCompositeField && "image".Equals(((MetaMetadataCompositeField) thatChild).Type);
                HashSet<String> nonDisplayedFieldNames = NonDisplayedFieldNames;
                if (thatChild.Hide && !isImage)
                    nonDisplayedFieldNames.Add(thatChild.Name);
                if (thatChild.Shadows != null)
                    nonDisplayedFieldNames.Add(thatChild.Shadows);

                // recursively process sub-fields
                Int32 fieldType = metadataFd.FdType;
                if (fieldType == FieldTypes.CompositeElement || fieldType == FieldTypes.CollectionElement)
                {
                    // bind class descriptor for nested sub-fields
                    MetaMetadataNestedField nested = (MetaMetadataNestedField) thatChild;
                    MetadataFieldDescriptor fd = nested.MetadataFieldDescriptor;
                    if (fd.IsPolymorphic)
                    {
                        Debug.WriteLine("Polymorphic field: " + nested + ", not binding an element class descriptor.");
                    }
                    else
                    {
                        MetadataClassDescriptor elementClassDescriptor =
                            ((MetaMetadataNestedField) thatChild).BindMetadataClassDescriptor(metadataTScope);
                        if (elementClassDescriptor != null)
                        {
                            MetaMetadata mmdForThatChild = nested.TypeMmd;
                            if (mmdForThatChild != null && mmdForThatChild.MetadataClassDescriptor == null)
                                //							mmdForThatChild.setMetadataClassDescriptor(elementClassDescriptor);
                                mmdForThatChild.BindMetadataClassDescriptor(metadataTScope);
                        }
                        else
                        {
                            Debug.WriteLine("Cannot determine elementClassDescriptor for " + thatChild);
                            Kids.Remove(thatChild.Name);
                        }
                    }
                }

                if (this is MetaMetadata)
                {
                    MetaMetadata mmd = (MetaMetadata) this;
                    String naturalId = thatChild.AsNaturalId;
                    if (naturalId != null)
                    {
                        mmd.NaturalIds.Put(naturalId, thatChild);
                    }
                }
            }
        }