public MetadataFieldDescriptor(MetadataClassDescriptor declaringClassDescriptor, FieldDescriptor wrappedFD, String wrapperTag)
     : base(declaringClassDescriptor, wrappedFD, wrapperTag)
 {
     //MmName = DeriveMmName();
 }
 public MetadataFieldDescriptor(MetadataClassDescriptor classDescriptor, FieldInfo fieldInfo, Int16 annotationType) : base(classDescriptor, fieldInfo, annotationType)
 {
     MmName = DeriveMmName();
 }
 public MetadataFieldDescriptor(MetadataClassDescriptor declaringClassDescriptor, FieldDescriptor wrappedFD, String wrapperTag)
     : base(declaringClassDescriptor, wrappedFD, wrapperTag)
 {
     //MmName = DeriveMmName();
 }
        /**
         * bind metadata field descriptors to sub-fields of this nested field, with field names as keys,
         * but without mixins field.
         * <p>
         * sub-fields that lack corresponding field descriptors will be removed from this nested field.
         * <p>
         * note that this field no longer uses a boolean flag to prevent multiple invocation. this should
         * have been done by the bindClassDescriptor() method.
         *
         * @param metadataTScope
         *          the translation scope of (generated) metadata classes.
         * @param metadataClassDescriptor
         *          the metadata class descriptor where field descriptors can be found.
         */
        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);
                    }
                }
            }
        }
 public MetadataFieldDescriptor(MetadataClassDescriptor classDescriptor, FieldInfo fieldInfo, Int16 annotationType)
     : base(classDescriptor, fieldInfo, annotationType)
 {
     MmName = DeriveMmName();
 }