/// <summary> /// Creates a known element registration for the specified type. /// </summary> /// <param name="type">The type for which to create a registration.</param> /// <param name="attr">The attribute that marks the type as a known type.</param> /// <returns>The <see cref="KnownType"/> registration that was created.</returns> private KnownType CreateKnownElementRegistration(Type type, UvmlKnownTypeAttribute attr) { var defaultPropertyAttr = (UvmlDefaultPropertyAttribute)type.GetCustomAttributes(typeof(UvmlDefaultPropertyAttribute), true).SingleOrDefault(); var defaultProperty = default(String); if (defaultPropertyAttr != null) { defaultProperty = defaultPropertyAttr.Name; } var ctor = type.GetConstructor(new[] { typeof(UltravioletContext), typeof(String) }); if (ctor == null && !type.IsAbstract) { throw new InvalidOperationException(PresentationStrings.UIElementInvalidCtor.Format(type.Name)); } RuntimeHelpers.RunClassConstructor(type.TypeHandle); var registration = new KnownElement(attr.Name ?? type.Name, type, defaultProperty); RegisterDefaultComponentTemplate(type, attr); return(registration); }
/// <summary> /// Registers the specified type's default component template, if it has one. /// </summary> /// <param name="type">The type that represents the element for which to register a component template.</param> /// <param name="uiElementAttr">The <see cref="UvmlKnownTypeAttribute"/> instance which is associated with the element type.</param> private void RegisterDefaultComponentTemplate(Type type, UvmlKnownTypeAttribute uiElementAttr) { if (String.IsNullOrEmpty(uiElementAttr.ComponentTemplate)) { return; } var asm = type.Assembly; using (var stream = asm.GetManifestResourceStream(uiElementAttr.ComponentTemplate)) { if (stream == null) { return; } var template = XDocument.Load(stream, LoadOptions.SetBaseUri | LoadOptions.SetLineInfo); ComponentTemplates.SetDefault(type, template); } }
/// <summary> /// Creates a known type registration for the specified type. /// </summary> /// <param name="type">The type for which to create a registration.</param> /// <param name="attr">The attribute that marks the type as a known type.</param> /// <returns>The <see cref="KnownType"/> registration that was created.</returns> private KnownType CreateKnownTypeRegistration(Type type, UvmlKnownTypeAttribute attr) { var registration = new KnownType(attr.Name ?? type.Name, type); return(registration); }