public static List <TargetedReferenceStep> GetPropertiesFromSelection(IEnumerable <SceneNode> selectedSceneNodes) { List <TargetedReferenceStep> properties = new List <TargetedReferenceStep>(); ProjectXamlContext projectXamlContext = (ProjectXamlContext)Enumerable.First <SceneNode>(selectedSceneNodes).ProjectContext; PropertyMerger.GetMergedPropertiesForSelection(selectedSceneNodes, properties); PropertyMerger.ReferenceStepComparer referenceStepComparer = new PropertyMerger.ReferenceStepComparer(); int count = properties.Count; using (IAttachedPropertiesAccessToken propertiesAccessToken = projectXamlContext.AttachedProperties.Access()) { if (!projectXamlContext.AttachedProperties.IsFinished) { projectXamlContext.AttachedProperties.FinishedScanning += new EventHandler(PropertyMerger.OnAttachedPropertiesFinishedScanning); } foreach (IAttachedPropertyMetadata propertyMetadata in propertiesAccessToken.AllAttachedProperties()) { IType type = projectXamlContext.GetType(propertyMetadata.OwnerType); if (type != null) { DependencyPropertyReferenceStep propertyReferenceStep = type.GetMember(MemberType.AttachedProperty, propertyMetadata.Name, MemberAccessTypes.Public) as DependencyPropertyReferenceStep; if (propertyReferenceStep != null) { TargetedReferenceStep targetedReferenceStep = new TargetedReferenceStep((ReferenceStep)propertyReferenceStep, propertyReferenceStep.DeclaringType); if (properties.BinarySearch(0, count, targetedReferenceStep, (IComparer <TargetedReferenceStep>)referenceStepComparer) < 0) { properties.Add(targetedReferenceStep); } } } } } return(properties); }
public IEnumerable <ICodeAidTypeInfo> GetAttachedPropertyTypesInClrNamespace(string assembly, string namespaceName) { IProjectContext project = this.ProjectContext; if (string.IsNullOrEmpty(assembly)) { assembly = this.ProjectContext.ProjectAssembly.Name; } IAttachedPropertiesProvider propertiesProvider = this.AttachedPropertiesProvider; if (propertiesProvider == null) { throw new NotSupportedException(); } using (IAttachedPropertiesAccessToken propertiesAccessToken = propertiesProvider.AttachedProperties.Access()) return(Enumerable.Select <IGrouping <Type, IAttachedPropertyMetadata>, ICodeAidTypeInfo>(Enumerable.GroupBy <IAttachedPropertyMetadata, Type>((IEnumerable <IAttachedPropertyMetadata>)propertiesAccessToken.AttachedPropertiesForAssemblyAndNamespace(assembly, namespaceName), (Func <IAttachedPropertyMetadata, Type>)(property => property.OwnerType)), (Func <IGrouping <Type, IAttachedPropertyMetadata>, ICodeAidTypeInfo>)(typeGroup => (ICodeAidTypeInfo) new CodeAidTypeInfo(this, project.GetType(typeGroup.Key))))); }
private IEnumerable <IType> GetAllAttachedPropertyTypesInProject() { IProjectContext project = this.ProjectContext; IAttachedPropertiesProvider propertiesProvider = this.AttachedPropertiesProvider; if (propertiesProvider == null) { throw new NotSupportedException(); } using (IAttachedPropertiesAccessToken token = propertiesProvider.AttachedProperties.Access()) { CodeAidProvider.EnsurePreloadKnownAttachedProperties(token, project); return((IEnumerable <IType>)Enumerable.ToArray <IType>(Enumerable.Select(Enumerable.Where(Enumerable.Select(Enumerable.GroupBy <IAttachedPropertyMetadata, Type>((IEnumerable <IAttachedPropertyMetadata>)token.AllAttachedProperties(), (Func <IAttachedPropertyMetadata, Type>)(property => property.OwnerType)), typeGroup => new { typeGroup = typeGroup, type = project.GetType(typeGroup.Key) }), param0 => param0.type != null), param0 => param0.type))); } }
public IEnumerable <ICodeAidMemberInfo> FilteredAttachedProperties(ICodeAidTypeInfo parentTypeInfo, IEnumerable <ICodeAidTypeInfo> ancestorTypeInfos) { if (parentTypeInfo == null) { return(Enumerable.Empty <ICodeAidMemberInfo>()); } IAttachedPropertiesProvider propertiesProvider = this.AttachedPropertiesProvider; if (propertiesProvider == null) { throw new NotSupportedException(); } using (IAttachedPropertiesAccessToken propertiesAccessToken = propertiesProvider.AttachedProperties.Access()) { CodeAidTypeInfo realParentTypeInfo = parentTypeInfo as CodeAidTypeInfo; IEnumerable <Type> realAncestorTypeInfos = ancestorTypeInfos != null?Enumerable.Select <CodeAidTypeInfo, Type>(Enumerable.Cast <CodeAidTypeInfo>((IEnumerable)ancestorTypeInfos), (Func <CodeAidTypeInfo, Type>)(ti => ti.type.RuntimeType)) : (IEnumerable <Type>)null; return(Enumerable.Cast <ICodeAidMemberInfo>((IEnumerable)Enumerable.Select <IAttachedPropertyMetadata, CodeAidAttachedPropertyInfo>(Enumerable.Where <IAttachedPropertyMetadata>((IEnumerable <IAttachedPropertyMetadata>)propertiesAccessToken.AttachedPropertiesForType(this.type), (Func <IAttachedPropertyMetadata, bool>)(property => property.IsBrowsable(realParentTypeInfo.type.RuntimeType, realAncestorTypeInfos))), (Func <IAttachedPropertyMetadata, CodeAidAttachedPropertyInfo>)(property => new CodeAidAttachedPropertyInfo(this.owner, property.Name, property.PropertyType))))); } }
private IEnumerable <IType> AllXamlRelevantTypesInAssembly(IAssembly assembly) { IProjectContext project = this.ProjectContext; bool supportInternal = assembly.Equals((object)project.ProjectAssembly); Type[] assemblyTypes = Type.EmptyTypes; try { assemblyTypes = AssemblyHelper.GetTypes(assembly); } catch (ReflectionTypeLoadException ex) { assemblyTypes = Type.EmptyTypes; } IAttachedPropertiesProvider attachedPropertiesProvider = this.AttachedPropertiesProvider; if (attachedPropertiesProvider == null) { throw new NotSupportedException(); } Type[] allTypesWithAttachedProperties = (Type[])null; using (IAttachedPropertiesAccessToken token = attachedPropertiesProvider.AttachedProperties.Access()) { CodeAidProvider.EnsurePreloadKnownAttachedProperties(token, project); allTypesWithAttachedProperties = Enumerable.ToArray <Type>(Enumerable.Select <IGrouping <Type, IAttachedPropertyMetadata>, Type>(Enumerable.GroupBy <IAttachedPropertyMetadata, Type>((IEnumerable <IAttachedPropertyMetadata>)token.AttachedPropertiesForAssembly(assembly.Name), (Func <IAttachedPropertyMetadata, Type>)(property => property.OwnerType)), (Func <IGrouping <Type, IAttachedPropertyMetadata>, Type>)(type => type.Key))); } foreach (Type type3 in assemblyTypes) { IType yieldedTypeId = (IType)null; try { if (!type3.IsGenericType) { if (type3.IsVisible) { if (!type3.IsNested) { if (!typeof(Attribute).IsAssignableFrom(type3)) { if (!typeof(Exception).IsAssignableFrom(type3)) { if (type3.IsPublic) { if (TypeUtilities.HasDefaultConstructor(type3, supportInternal) && TypeUtilities.CanCreateTypeInXaml((ITypeResolver)project, type3)) { IType type1 = project.GetType(type3); if (JoltHelper.TypeSupported((ITypeResolver)project, (ITypeId)type1)) { yieldedTypeId = type1; } } else if (allTypesWithAttachedProperties != null) { if (OrderedListExtensions.GenericBinarySearch <Type, Type>(allTypesWithAttachedProperties, type3, (Func <Type, Type, int>)((type1, type2) => type1.Name.CompareTo(type2.Name))) >= 0) { yieldedTypeId = project.GetType(type3); } } } } } } } } } catch (FileNotFoundException ex) { } if (yieldedTypeId != null) { yield return(yieldedTypeId); } } }
private static void EnsurePreloadKnownAttachedProperties(IAttachedPropertiesAccessToken token, IProjectContext project) { token.PreloadType(project.ResolveType(PlatformTypes.Canvas)); token.PreloadType(project.ResolveType(PlatformTypes.Grid)); }