private void MergeBehaviorOverrides(DictionaryAdapterMeta meta)
		{
			if (Descriptor == null) return;

			var typeDescriptor = Descriptor as DictionaryDescriptor;

			if (typeDescriptor != null)
			{
				Initializers = Initializers.Prioritize(typeDescriptor.Initializers).ToArray();
			}

			Properties = new Dictionary<string, PropertyDescriptor>();

			foreach (var property in meta.Properties)
			{
				var propertyDescriptor = property.Value;

				var propertyOverride = new PropertyDescriptor(propertyDescriptor, false)
					.AddKeyBuilders(propertyDescriptor.KeyBuilders.Prioritize(Descriptor.KeyBuilders))
					.AddGetters(propertyDescriptor.Getters.Prioritize(Descriptor.Getters))
					.AddSetters(propertyDescriptor.Setters.Prioritize(Descriptor.Setters));

				Properties.Add(property.Key, propertyOverride);
			}
		}
Example #2
0
		void IDictionaryMetaInitializer.Initialize(IDictionaryAdapterFactory factory, DictionaryAdapterMeta dictionaryMeta)
		{
			var type = dictionaryMeta.Type;
			bool? qualified = null;
			bool? isNullable = null;
			string defaultNamespace = null;
			XmlTypeAttribute xmlType = null;
			XmlRootAttribute xmlRoot = null;
			List<Type> xmlIncludes = null;

			new BehaviorVisitor()
				.OfType<XmlTypeAttribute>(attrib => xmlType = attrib)
				.OfType<XmlRootAttribute>(attrib => xmlRoot = attrib)
				.OfType<XmlDefaultsAttribute>(attrib =>
				{
					qualified = attrib.Qualified;
					isNullable = attrib.IsNullable;
				})
				.OfType<XmlNamespaceAttribute>(attrib =>
				{
					if (attrib.Default)
					{
						defaultNamespace = attrib.NamespaceUri;
					}
				})
				.OfType<XmlIncludeAttribute>(attrib =>
				{
					xmlIncludes = xmlIncludes ?? new List<Type>();
					if (type != attrib.Type && type.IsAssignableFrom(attrib.Type))
					{
						xmlIncludes.Add(attrib.Type);
					}
				})
				.Apply(dictionaryMeta.Behaviors);

			if (xmlType == null)
			{
				xmlType = new XmlTypeAttribute();
			}

			if (string.IsNullOrEmpty(xmlType.TypeName))
			{
				xmlType.TypeName = type.Name;
				if (xmlType.TypeName.StartsWith("I"))
				{
					xmlType.TypeName = xmlType.TypeName.Substring(1);
				}
			}

			if (xmlType.Namespace == null)
			{
				xmlType.Namespace = defaultNamespace;
			}

			dictionaryMeta.SetXmlMeta(new XmlMetadata(type, qualified, isNullable, xmlType, xmlRoot, xmlIncludes));
		}
		public DictionaryAdapterInstance(IDictionary dictionary, DictionaryAdapterMeta meta,
										 PropertyDescriptor descriptor, IDictionaryAdapterFactory factory)
		{
			Dictionary = dictionary;
			Descriptor = descriptor;
			Factory = factory;

			Properties = meta.Properties;
			Initializers = meta.Initializers;
			MergeBehaviorOverrides(meta);
		}
		void IDictionaryMetaInitializer.Initialize(IDictionaryAdapterFactory factory, DictionaryAdapterMeta dictionaryMeta)
		{
			var type = dictionaryMeta.Type;
			string defaultNamespace = null;
			XmlTypeAttribute xmlType = null;
			XmlRootAttribute xmlRoot = null;
			List<Type> xmlIncludes = null;

			new BehaviorVisitor()
				.OfType<XmlTypeAttribute>(attrib =>
				{
					xmlType = attrib;
				})
				.OfType<XmlRootAttribute>(attrib =>
				{
					xmlRoot = attrib;
				})
				.OfType<XmlNamespaceAttribute>(attrib =>
				{
					if (attrib.Default)
						defaultNamespace = attrib.NamespaceUri;
				})
				.OfType<XmlIncludeAttribute>(attrib =>
				{
					xmlIncludes = xmlIncludes ?? new List<Type>();
					if (type != attrib.Type && type.IsAssignableFrom(attrib.Type))
					{
						xmlIncludes.Add(attrib.Type);
					}
				})
				.Apply(dictionaryMeta.Behaviors);

			if (xmlType == null)
			{
				xmlType = new XmlTypeAttribute
				{
					TypeName = type.Name,
					Namespace = defaultNamespace
				};
				if (xmlType.TypeName.StartsWith("I"))
				{
					xmlType.TypeName = xmlType.TypeName.Substring(1);
				}
			}
			else if (xmlType.Namespace == null)
				xmlType.Namespace = defaultNamespace;

			dictionaryMeta.SetXmlMeta(new XmlMetadata(type, xmlType, xmlRoot, xmlIncludes));
		}
		public DictionaryAdapterInstance(IDictionary dictionary, DictionaryAdapterMeta meta,
										 PropertyDescriptor descriptor, IDictionaryAdapterFactory factory)
		{
			Dictionary = dictionary;
			Descriptor = descriptor;
			Factory    = factory;

			List<IDictionaryBehavior> behaviors;

			if (null == descriptor || null == (behaviors = descriptor.BehaviorsInternal))
			{
				Initializers = meta.Initializers;
				Properties   = MergeProperties(meta.Properties);
			}
			else
			{
				Initializers = MergeInitializers(meta.Initializers, behaviors);
				Properties   = MergeProperties(meta.Properties, behaviors);
			}
		}