//internal static bool IsElementAnUIElement(XElement element, ReflectionOnSeparateAppDomainHandler reflectionOnSeparateAppDomain) //{ // string elementLocalName, elementNameSpace, assemblyNameIfAny; // GetClrNamespaceAndLocalName(element.Name, out elementNameSpace, out elementLocalName, out assemblyNameIfAny); // return reflectionOnSeparateAppDomain.IsElementAnUIElement(elementNameSpace, elementLocalName, assemblyNameIfAny); //} internal static bool IsTypeAssignableFrom(XName elementOfTypeToAssignFrom, XName elementOfTypeToAssignTo, ReflectionOnSeparateAppDomainHandler reflectionOnSeparateAppDomain, bool isAttached = false) { string nameOfTypeToAssignFrom, nameSpaceOfTypeToAssignFrom, assemblyNameOfTypeToAssignFrom; GetClrNamespaceAndLocalName(elementOfTypeToAssignFrom, out nameSpaceOfTypeToAssignFrom, out nameOfTypeToAssignFrom, out assemblyNameOfTypeToAssignFrom); string nameOfTypeToAssignTo, nameSpaceOfTypeToAssignTo, assemblyNameOfTypeToAssignTo; GetClrNamespaceAndLocalName(elementOfTypeToAssignTo, out nameSpaceOfTypeToAssignTo, out nameOfTypeToAssignTo, out assemblyNameOfTypeToAssignTo); return(reflectionOnSeparateAppDomain.IsTypeAssignableFrom(nameSpaceOfTypeToAssignFrom, nameOfTypeToAssignFrom, assemblyNameOfTypeToAssignFrom, nameSpaceOfTypeToAssignTo, nameOfTypeToAssignTo, assemblyNameOfTypeToAssignTo, isAttached)); }
public static void FixSelectorItemsSourceOrder(XElement currentElement, ReflectionOnSeparateAppDomainHandler reflectionOnSeparateAppDomain) { // Check if the current element is an object (rather than a property): bool isElementAnObjectRatherThanAProperty = !currentElement.Name.LocalName.Contains("."); if (isElementAnObjectRatherThanAProperty) { //check if the element has a attribute called ItemsSource: XAttribute itemsSourceAttribute = currentElement.Attribute(XName.Get("ItemsSource")); bool hasItemsSourceProperty = itemsSourceAttribute != null; //if the element has an attribute called ItemsSource, we check if it represents an object of a type that inherits from Selector: if (hasItemsSourceProperty) { // Get the namespace, local name, and optional assembly that correspond to the element: string namespaceName, localTypeName, assemblyNameIfAny; GettingInformationAboutXamlTypes.GetClrNamespaceAndLocalName(currentElement.Name, out namespaceName, out localTypeName, out assemblyNameIfAny); string selectorNamespaceName, selectorLocalTypeName, selectorAssemblyNameIfAny; GettingInformationAboutXamlTypes.GetClrNamespaceAndLocalName("Selector", out selectorNamespaceName, out selectorLocalTypeName, out selectorAssemblyNameIfAny); bool typeInheritsFromSelector = reflectionOnSeparateAppDomain.IsTypeAssignableFrom(namespaceName, localTypeName, assemblyNameIfAny, selectorNamespaceName, selectorLocalTypeName, selectorAssemblyNameIfAny); //Type elementType = reflectionOnSeparateAppDomain.GetCSharpEquivalentOfXamlType(namespaceName, localTypeName, assemblyNameIfAny); //if the type inherits from the element, we want to put the itemsSource attribute to the end: if (typeInheritsFromSelector) { itemsSourceAttribute.Remove(); currentElement.Add(itemsSourceAttribute); } //else we do nothing } //else we do nothing } //else we do nothing //we move on to the children of the element. if (currentElement.HasElements) { foreach (XElement child in currentElement.Elements()) { FixSelectorItemsSourceOrder(child, reflectionOnSeparateAppDomain); } } }