Exemplo n.º 1
0
        protected void BindAnyMeta(IAnyMapping anyMapping, Any model)
        {
            if (string.IsNullOrEmpty(anyMapping.MetaType))
            {
                return;
            }
            model.MetaType = anyMapping.MetaType;
            var metaValues = anyMapping.MetaValues;

            if (metaValues.Count == 0)
            {
                return;
            }
            IDictionary <object, string> values = new Dictionary <object, string>();
            IType metaType = TypeFactory.HeuristicType(model.MetaType);

            foreach (var metaValue in metaValues)
            {
                try
                {
                    object value      = ((IDiscriminatorType)metaType).StringToObject(metaValue.value);
                    string entityName = GetClassName(metaValue.@class, mappings);
                    values[value] = entityName;
                }
                catch (InvalidCastException ice)
                {
                    throw new MappingException("meta-type was not an IDiscriminatorType: " + metaType.Name, ice);
                }
                catch (HibernateException he)
                {
                    throw new MappingException("could not interpret meta-value", he);
                }
                catch (TypeLoadException cnfe)
                {
                    throw new MappingException("meta-value class not found", cnfe);
                }
            }
            model.MetaValues = values.Count > 0 ? values : null;
        }
		protected void BindAnyMeta(IAnyMapping anyMapping, Any model)
		{
			if(string.IsNullOrEmpty(anyMapping.MetaType))
			{
				return;
			}
				model.MetaType = anyMapping.MetaType;
			var metaValues = anyMapping.MetaValues;
			if (metaValues.Count == 0)
			{
				return;
			}
			IDictionary<object, string> values = new Dictionary<object, string>();
			IType metaType = TypeFactory.HeuristicType(model.MetaType);

			foreach (var metaValue in metaValues)
			{
				try
				{
					object value = ((IDiscriminatorType)metaType).StringToObject(metaValue.value);
					string entityName = GetClassName(metaValue.@class, mappings);
					values[value] = entityName;
				}
				catch (InvalidCastException)
				{
					throw new MappingException("meta-type was not an IDiscriminatorType: " + metaType.Name);
				}
				catch (HibernateException he)
				{
					throw new MappingException("could not interpret meta-value", he);
				}
				catch (TypeLoadException cnfe)
				{
					throw new MappingException("meta-value class not found", cnfe);
				}
			}
			model.MetaValues = values.Count > 0 ? values : null;
		}