public static ResolverResult Resolve(MultiTargetingSupportService multiTargetingService, Type type) { SharedFx.Assert(multiTargetingService != null, "multiTargetingService should not be null"); SharedFx.Assert(type != null, "type should not be null"); if (!multiTargetingService.IsSupportedType(type)) { return ResolverResult.Unknown; } ResolverResult result; Type reflectionType = multiTargetingService.GetReflectionType(type); PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty); PropertyInfo[] targetProperties = reflectionType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty); List<string> newProperties = new List<string>(); // Assume we don't remove properties in newer framework // We only compare property name here if (properties.Length > targetProperties.Length) { foreach (PropertyInfo propertyInfo in properties) { bool found = false; foreach (PropertyInfo targetProperty in targetProperties) { if (targetProperty.Name == propertyInfo.Name) { found = true; break; } } if (!found) { newProperties.Add(propertyInfo.Name); } } result = new ResolverResult(newProperties); } else { result = ResolverResult.FullySupported; } return result; }
public void Update(Type type, ResolverResult result) { SharedFx.Assert(type != null, "type should not be null"); SharedFx.Assert(result != null, "result should not be null"); if (this.cache.ContainsKey(type)) { this.cache[type] = new WeakReference(result); } else { this.cache.Add(type, new WeakReference(result)); } }
public static ResolverResult Resolve(MultiTargetingSupportService multiTargetingService, Type type) { SharedFx.Assert(multiTargetingService != null, "multiTargetingService should not be null"); SharedFx.Assert(type != null, "type should not be null"); if (!multiTargetingService.IsSupportedType(type)) { return(ResolverResult.Unknown); } ResolverResult result; Type reflectionType = multiTargetingService.GetReflectionType(type); PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty); PropertyInfo[] targetProperties = reflectionType.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty); List <string> newProperties = new List <string>(); // Assume we don't remove properties in newer framework // We only compare property name here if (properties.Length > targetProperties.Length) { foreach (PropertyInfo propertyInfo in properties) { bool found = false; foreach (PropertyInfo targetProperty in targetProperties) { if (targetProperty.Name == propertyInfo.Name) { found = true; break; } } if (!found) { newProperties.Add(propertyInfo.Name); } } result = new ResolverResult(newProperties); } else { result = ResolverResult.FullySupported; } return(result); }
public static XamlType GetXamlType(ResolverResult resolverResult, XamlType oldXamlType) { SharedFx.Assert(oldXamlType != null, "oldXamlType should not be null"); switch (resolverResult.Kind) { case XamlTypeKind.FullySupported: return oldXamlType; case XamlTypeKind.PartialSupported: return new XamlTypeWithExtraPropertiesRemoved(oldXamlType.UnderlyingType, oldXamlType.SchemaContext, resolverResult.NewProperties); default: SharedFx.Assert(resolverResult.Kind == XamlTypeKind.Unknown, "resolverResult.Kind should be XamlTypeKind.Unknown."); return null; } }
public static XamlType GetXamlType(ResolverResult resolverResult, XamlType oldXamlType) { SharedFx.Assert(oldXamlType != null, "oldXamlType should not be null"); switch (resolverResult.Kind) { case XamlTypeKind.FullySupported: return(oldXamlType); case XamlTypeKind.PartialSupported: return(new XamlTypeWithExtraPropertiesRemoved(oldXamlType.UnderlyingType, oldXamlType.SchemaContext, resolverResult.NewProperties)); default: SharedFx.Assert(resolverResult.Kind == XamlTypeKind.Unknown, "resolverResult.Kind should be XamlTypeKind.Unknown."); return(null); } }
protected override XamlType GetXamlType(string xamlNamespace, string name, params XamlType[] typeArguments) { if (!string.IsNullOrEmpty(this.localAssemblyNsPostfix) && IsClrNamespaceWithNoAssembly(xamlNamespace)) { xamlNamespace = AddLocalAssembly(xamlNamespace); } var xamlType = base.GetXamlType(xamlNamespace, name, typeArguments); if (xamlType == null && environmentAssembliesLoaded == false && editingContext != null) { // Failed to find the type, this might because the namespace is a custom namespace // and the dependent assembly hasn't been loaded yet. Load all dependent assemblies // and try to load the same xaml type again. AssemblyContextControlItem assemblyItem = this.editingContext.Items.GetValue <AssemblyContextControlItem>(); var environmentAssemblies = assemblyItem.GetEnvironmentAssemblies(null); if (assemblyItem.LocalAssemblyName != null) { AssemblyContextControlItem.GetAssembly(assemblyItem.LocalAssemblyName, null); } environmentAssembliesLoaded = true; xamlType = base.GetXamlType(xamlNamespace, name, typeArguments); } if (xamlType == null || xamlType.UnderlyingType == null || this.editingContext == null) { return(xamlType); } MultiTargetingSupportService multiTargetingService = editingContext.Services.GetService <IMultiTargetingSupportService>() as MultiTargetingSupportService; DesignerConfigurationService config = editingContext.Services.GetService <DesignerConfigurationService>(); if (multiTargetingService == null || config == null) { return(xamlType); } // do not filter out new types and new properties if targeting to current framework and it's a full SKU if (config.TargetFrameworkName.Version == CurrentFramework.Version && config.TargetFrameworkName.IsFullProfile()) { return(xamlType); } // Filter out new types and new properties if (this.resolverCache == null) { this.resolverCache = new ResolverCache(); } if (supportedTypes.Contains(xamlType.UnderlyingType)) { return(xamlType); } // only check if conversion is needed when target framework is less than 4.5 if (config.TargetFrameworkName.Version < CurrentFramework.Version) { if (conversionRequiredTypes.Contains(xamlType.UnderlyingType)) { this.ContainsConversionRequiredType = true; return(xamlType); } } ResolverResult resolverResult = this.resolverCache.Lookup(xamlType.UnderlyingType); if (resolverResult == null) { resolverResult = MultiTargetingTypeResolver.Resolve(multiTargetingService, xamlType.UnderlyingType); this.resolverCache.Update(xamlType.UnderlyingType, resolverResult); } return(MultiTargetingTypeResolver.GetXamlType(resolverResult, xamlType)); }