public PropertyRoute Add(MemberInfo member) { using (HeavyProfiler.LogNoStackTrace("PR.Add", () => member.Name)) { if (member is MethodInfo && ((MethodInfo)member).IsInstantiationOf(MixinDeclarations.miMixin)) { member = ((MethodInfo)member).GetGenericArguments()[0]; } if (this.Type.IsIEntity() && PropertyRouteType != PropertyRouteType.Root) { Implementations imp = GetImplementations(); Type?only; if (imp.IsByAll || (only = imp.Types.Only()) == null) { throw new InvalidOperationException("Attempt to make a PropertyRoute on a {0}. Cast first".FormatWith(imp)); } return(new PropertyRoute(Root(only), member)); } return(new PropertyRoute(this, member)); } }
public static Implementations GetImplementations(PropertyRoute route) { if (!typeof(ModelEntity).IsAssignableFrom(route.RootType)) { throw new InvalidOperationException("Route {0} is not rooted on a {1}".FormatWith(route, typeof(ModifiableEntity).Name)); } PropertyRoute fieldRoute = route; if (fieldRoute.PropertyRouteType == PropertyRouteType.LiteEntity) { fieldRoute = fieldRoute.Parent; } if (fieldRoute.PropertyRouteType == PropertyRouteType.MListItems) { fieldRoute = fieldRoute.Parent; } return(Implementations.FromAttributes( route.Type.CleanType(), route, fieldRoute.FieldInfo.GetCustomAttribute <ImplementedByAttribute>(), fieldRoute.FieldInfo.GetCustomAttribute <ImplementedByAllAttribute>())); }