// <summary> // Takes in a JoinTreeNode and a Contition Property Map and creates an BoolExpression // for the Condition Map. // </summary> private static BoolExpression GetConditionExpression(MemberPath member, ConditionPropertyMapping conditionMap) { //Get the member for which the condition is being specified EdmMember conditionMember = (conditionMap.Column != null) ? conditionMap.Column : conditionMap.Property; var conditionMemberNode = new MemberPath(member, conditionMember); //Check if this is a IsNull condition MemberRestriction conditionExpression = null; if (conditionMap.IsNull.HasValue) { // for conditions on scalars, create NodeValue nodes, otherwise NodeType var conditionConstant = conditionMap.IsNull.Value ? Constant.Null : Constant.NotNull; if (MetadataHelper.IsNonRefSimpleMember(conditionMember)) { conditionExpression = new ScalarRestriction(conditionMemberNode, conditionConstant); } else { conditionExpression = new TypeRestriction(conditionMemberNode, conditionConstant); } } else { conditionExpression = new ScalarRestriction(conditionMemberNode, new ScalarConstant(conditionMap.Value)); } Debug.Assert(conditionExpression != null); return(BoolExpression.CreateLiteral(conditionExpression, null)); }
/// <summary> /// A convenience wrapper provided for editor code to turn a list of types into a form that /// matches their existing structure. /// </summary> /// <remarks> /// This is primarily a crutch because of how the inspector code stores parallel arrays of /// objects, rather than just storing an array of objects (i.e. it stores three arrays /// of objects which happen to have matching indices, rather than storing a single array /// of objects which have state relevant within the object). /// </remarks> public static InteractableTypesContainer Find(List <Type> types, TypeRestriction typeRestriction) { #if UNITY_EDITOR return(new InteractableTypesContainer(FindTypes(types, typeRestriction))); #else // Due to other code structure, it's possible that this can still be invoked at runtime, but should // not return anything (because type information should be read from serialized assembly data, rather // than using reflection at runtime). return(new InteractableTypesContainer(new List <InteractableType>())); #endif }
protected virtual List <System.Type> GetValidationTypes(TypeRestriction validationShema) { switch (validationShema) { case TypeRestriction.ValidateForbiddenTypes: return(GetForbiddenTypes()); case TypeRestriction.ValidateAllowedTypes: return(GetAllowedTypes()); } return(null); }
/// <summary> /// Ensures a cache entry is setup for all types in the InteractableType enum. /// </summary> /// <remarks> /// Note that this is not invoked at runtime and is assumed to be invoked from a single /// threaded UI context, and is thus not locked. /// </remarks> private static void EnsureCacheForTypes(List <Type> types, TypeRestriction typeRestriction) { HashSet <Type> cacheMisses = new HashSet <Type>(); foreach (Type type in types) { if (!cache.ContainsKey(type)) { cacheMisses.Add(type); } } var assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Type type in cacheMisses) { cache[type] = GetTypesFromAssemblies(type, typeRestriction, assemblies); } }
/// <summary> /// Loads the classes that derive from the given type by looking through all of the assemblies. /// </summary> private static List <InteractableType> GetTypesFromAssemblies(Type type, TypeRestriction typeRestriction, Assembly[] assemblies) { List <InteractableType> interactableTypes = new List <InteractableType>(); if (typeRestriction == TypeRestriction.AllowBase) { InteractableType interactableType = new InteractableType(type); interactableTypes.Add(interactableType); } foreach (Assembly assembly in assemblies) { foreach (Type assemblyType in assembly.GetTypes()) { TypeInfo info = assemblyType.GetTypeInfo(); if (info.IsSubclassOf(type)) { InteractableType interactableType = new InteractableType(assemblyType); interactableTypes.Add(interactableType); } } } return(interactableTypes); }
/// <summary> /// Gets the list of InteractableType objects for classes that support the specified types. /// </summary> private static List <InteractableType> FindTypes(List <Type> types, TypeRestriction typeRestriction) { EnsureCacheForTypes(types, typeRestriction); return(GetTypesFromCache(types)); }