public override IEnumerable <IFieldMetadata> GetFieldMetadata(string recordType)
 {
     lock (_lockObject)
     {
         if (!FieldMetadata.ContainsKey(recordType))
         {
             FieldMetadata.Add(recordType, RecordMetadataFactory.GetClassFieldMetadata(Type.GetType(recordType)));
             var fieldMetadata = FieldMetadata[recordType];
         }
         return(FieldMetadata[recordType]);
     }
 }
        public ObjectRecordService(object objectToEnter, IRecordService lookupService,
                                   IDictionary <string, IEnumerable <string> > optionSetLimitedValues, ObjectRecordService parentService, string parentServiceReference, IResolveObject objectResolver, IDictionary <string, Type> objectTypeMaps = null)
        {
            ObjectResolver         = objectResolver;
            ParentServiceReference = parentServiceReference;
            ParentService          = parentService;
            ObjectToEnter          = objectToEnter;
            _lookupService         = lookupService;
            OptionSetLimitedValues = optionSetLimitedValues;
            ObjectTypeMaps         = objectTypeMaps;
            var objectTypeFieldMetadata = new List <FieldMetadata>();

            var type = ObjectToEnter.GetType();

            objectTypeFieldMetadata.AddRange(RecordMetadataFactory.GetClassFieldMetadata(type, ObjectTypeMaps));
            FieldMetadata.Add(type.AssemblyQualifiedName, objectTypeFieldMetadata);
            foreach (var field in objectTypeFieldMetadata.Where(f => f.FieldType == RecordFieldType.Enumerable))
            {
                //need to add the field metadata for any nested types
                var asEnumerable = (EnumerableFieldMetadata)field;
                if (!FieldMetadata.ContainsKey(asEnumerable.EnumeratedTypeQualifiedName))
                {
                    var metadata = RecordMetadataFactory.GetClassFieldMetadata(GetClassType(asEnumerable.EnumeratedTypeQualifiedName), ObjectTypeMaps);
                    FieldMetadata.Add(asEnumerable.EnumeratedTypeQualifiedName, metadata);
                }

                //if the property is an interface we also want to load the metadata for any instance types
                var propertyValue = ObjectToEnter.GetPropertyValue(field.SchemaName);
                if (propertyValue != null)
                {
                    var enumerable = ((IEnumerable)propertyValue);
                    foreach (var item in enumerable)
                    {
                        var instanceType = item.GetType();
                        if (!FieldMetadata.ContainsKey(instanceType.AssemblyQualifiedName))
                        {
                            var metadata = RecordMetadataFactory.GetClassFieldMetadata(instanceType, ObjectTypeMaps);
                            FieldMetadata.Add(instanceType.AssemblyQualifiedName, metadata);
                        }
                    }
                }
            }
        }