/// <summary> /// Gets a unique key for the collection. /// </summary> /// <param name="classType"></param> /// <returns></returns> private static string GetKey(TypeViewModel type) { if (type.Wrapper is Wrappers.ReflectionTypeWrapper) { return(GetKey(((ReflectionTypeWrapper)(type.Wrapper)).Info)); } else { return(GetKey((INamedTypeSymbol)(((SymbolTypeWrapper)(type.Wrapper)).Symbol))); } }
public static ClassViewModel GetClassViewModel(TypeViewModel classType, string controllerName = null, string apiName = null, bool hasDbSet = false, string area = "") { if (classType.Wrapper is ReflectionTypeWrapper) { return(GetClassViewModel(classType.Wrapper.Info, controllerName, apiName, hasDbSet, area)); } else { return(GetClassViewModel((INamedTypeSymbol)classType.Wrapper.Symbol, controllerName, apiName, hasDbSet, area)); } }
public ClassViewModel(TypeViewModel type, string controllerName, string apiName, bool hasDbSet) : this(controllerName, apiName, hasDbSet) { if (type.Wrapper is Wrappers.ReflectionTypeWrapper) { Wrapper = new ReflectionClassWrapper(((ReflectionTypeWrapper)(type.Wrapper)).Info); } else { Wrapper = new SymbolClassWrapper((INamedTypeSymbol)(((SymbolTypeWrapper)(type.Wrapper)).Symbol)); } }
private bool AddCrudStrategy( Type iface, TypeViewModel strategyType, HashSet <CrudStrategyTypeUsage> set, ClassViewModel declaredFor = null ) { if (!strategyType.IsA(iface)) { return(false); } var servedType = strategyType.GenericArgumentsFor(iface).Single(); if (!servedType.HasClassViewModel) { throw new InvalidOperationException($"{servedType} is not a valid type argument for a {iface}."); } var servedClass = Cache(servedType.ClassViewModel); // See if we were expecting that the strategy be declared for a particular type // by virtue of its nesting. If this type has been overridden to something else by an attribute, then that's wrong. var explicitlyDeclaredFor = strategyType.GetAttributeValue <DeclaredForAttribute>(a => a.DeclaredFor)?.ClassViewModel; if (explicitlyDeclaredFor != null && declaredFor != null && !explicitlyDeclaredFor.Equals(declaredFor)) { throw new InvalidOperationException( $"Expected that {strategyType} is declared for {declaredFor}, but it was explicitly declared for {explicitlyDeclaredFor} instead."); } // Any explicit declaration is OK. Use that, // or the passed in value if no explicit value is given via attribute, // or just the type that is served if neither are present. declaredFor = explicitlyDeclaredFor ?? declaredFor ?? servedClass; if (declaredFor.IsDto && !servedClass.Equals(declaredFor.DtoBaseViewModel)) { throw new InvalidOperationException($"{strategyType} is not a valid {iface} for {declaredFor} - " + $"{strategyType} must satisfy {iface} with type parameter <{declaredFor.DtoBaseViewModel}>."); } set.Add(new CrudStrategyTypeUsage(Cache(strategyType.ClassViewModel), servedClass, declaredFor)); return(true); }
// TODO: maybe retire this in favor of plain .Equals? Make sure that ReflectionTypeViewModel.FullyQualifiedName is correct, first. public abstract bool EqualsType(TypeViewModel b);
public override bool EqualsType(TypeViewModel b) => b is ReflectionTypeViewModel r ? Info == r.Info : false;