internal static bool CanBeResolvedGloballySafe(this DependencySource source, [NotNull] Type type, out DependencySource actualSource) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (!source.Includes(DependencySource.Global)) { actualSource = default; return(false); } var containers = Object.FindObjectsOfType <RootDependencyContainer>(); var canBeResolved = false; foreach (var container in containers) { if (container.CanBeResolvedSafe(type)) { canBeResolved = true; break; } } actualSource = canBeResolved ? DependencySource.Global : default; return(canBeResolved); }
internal override void HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args) { DependencyProperty dp = args.Property; if (TraceData.IsExtendedTraceEnabled(this, TraceDataLevel.Events)) { TraceData.Trace(TraceEventType.Warning, TraceData.GotPropertyChanged( TraceData.Identify(this), TraceData.Identify(d), dp.Name)); } for (int i = 0; i < AttentiveBindingExpressions; ++i) { BindingExpressionBase bindExpr = MutableBindingExpressions[i]; DependencySource[] sources = bindExpr.GetSources(); if (sources != null) { for (int j = 0; j < sources.Length; ++j) { DependencySource source = sources[j]; if (source.DependencyObject == d && source.DependencyProperty == dp) { bindExpr.OnPropertyInvalidation(d, args); break; } } } } }
private static bool TryResolveInGameObject(this DependencySource source, ResolutionContext context, Type type, out object result, out DependencySource dependencySource) { if (CanBeResolvedInGameObject(type)) { if (TryResolveLocally(source, context, type, out result)) { dependencySource = DependencySource.Local; return(true); } if (TryResolveInChildren(source, context, type, out result)) { dependencySource = DependencySource.Children; return(true); } if (TryResolveInParent(source, context, type, out result)) { dependencySource = DependencySource.Parent; return(true); } } result = default; dependencySource = default; return(false); }
public CachedComponentResolver(GameObject gameObject, DependencySource dependencySource) { GameObject = gameObject; DependencySource = dependencySource; _resolutionFunction = Resolve; _bakedIsAffectedExtraCondition = IsAffectedExtraCondition; }
public bool CanBeResolvedSafe(MonoBehaviour component, Type type, out DependencySource actualSource) { var resolver = RentResolver(); var canBeResolvedSafe = resolver.CanBeResolvedSafe(component, type, out actualSource); ResolverPool.Return(resolver); return(canBeResolvedSafe); }
private static bool CanBeResolvedGloballySafe(this DependencySource source, Type type) { if (!source.Includes(Global)) { return(false); } var container = Object.FindObjectOfType <RootDependencyContainer>(); return(container && container.CanBeResolvedSafe(type)); }
private static bool TryResolveLocally(DependencySource source, Context context, Type type, out object result) { if (source.Includes(Local) && context.Component.TryGetComponent(type, out var foundComponent)) { result = foundComponent; return(true); } result = default; return(false); }
private static bool TryResolveGlobally(this DependencySource source, Type type, out object result) { var container = RootDependencyContainer.Instance; if (source.Includes(Global) && container && container.TryResolve(type, out result)) { return(true); } result = default; return(false); }
private static bool TryResolveInParent(DependencySource source, Context context, Type type, out object result) { if (source.Includes(Parent)) { var foundComponent = context.Resolver.GetComponentInParent(type); if (foundComponent != null) { result = foundComponent; return(true); } } result = default; return(false); }
/// <summary> /// Inject dependencies into components of the provided Game Object (from the specified sources). /// </summary> /// <param name="gameObject">Injected Game Object.</param> /// <param name="sources">Sources to get dependencies from.</param> /// <exception cref="ArgumentNullException">If <paramref name="gameObject"/> is null.</exception> public static void Inject([NotNull] GameObject gameObject, DependencySource sources) { if (gameObject == null) { throw new ArgumentNullException(nameof(gameObject)); } var resolver = ResolverPool.Rent(gameObject, sources); try { resolver.Resolve(); } finally { ResolverPool.Return(resolver); } }
private static string GetDependencySourceIndicator(DependencySource source) { switch (source) { case DependencySource.Local: return("L"); case DependencySource.Children: return("C"); case DependencySource.Parent: return("P"); case DependencySource.Global: return("G"); default: throw new ArgumentOutOfRangeException(nameof(source), source, null); } }
internal static bool TryResolveGlobally(this DependencySource source, [NotNull] Type type, out object result, out DependencySource actualSource) { if (type == null) { throw new ArgumentNullException(nameof(type)); } for (var index = RootDependencyContainer.InstancesCount - 1; index >= 0; index--) { var container = RootDependencyContainer.GetInstance(index); if (source.TryResolveGlobally(container, type, out result, out actualSource)) { return(true); } } result = default; actualSource = default; return(false); }
public static CachedComponentResolver Rent([NotNull] GameObject gameObject, DependencySource dependencySource) { if (gameObject == null) { throw new ArgumentNullException(nameof(gameObject)); } if (FreeResolvers.Count == 0) { return(new CachedComponentResolver(gameObject, dependencySource)); } var lastIndex = FreeResolvers.Count - 1; var resolver = FreeResolvers[lastIndex]; FreeResolvers.RemoveAt(lastIndex); FreeResolversSet.Remove(resolver); resolver.Clear(); resolver.GameObject = gameObject; resolver.DependencySource = dependencySource; return(resolver); }
private static bool TryResolveGlobally(this DependencySource source, [NotNull] RootDependencyContainer container, [NotNull] Type type, out object result, out DependencySource actualSource) { if (container == null) { throw new ArgumentNullException(nameof(container)); } if (type == null) { throw new ArgumentNullException(nameof(type)); } if (source.Includes(DependencySource.Global) && container && container.TryResolve(type, out result)) { actualSource = DependencySource.Global; return(true); } result = default; actualSource = default; return(false); }
public static bool CanBeResolvedSafe(this DependencySource source, ResolutionContext context, Type type, out DependencySource actualSource) => source.TryResolveInGameObject(context, type, out _, out actualSource) || source.CanBeResolvedGloballySafe(type, out actualSource);
public bool CanBeResolvedSafe(MonoBehaviour component, Type type, out DependencySource actualSource) { var context = new ResolutionContext(GameObject, component); return(DependencySource.CanBeResolvedSafe(context, type, out actualSource)); }
private static bool Includes(this DependencySource source, DependencySource other) => (source & other) != 0;
public static bool TryResolve(this DependencySource source, ResolutionContext context, Type type, out object result, out DependencySource actualSource) => source.TryResolveInGameObject(context, type, out result, out actualSource) || source.TryResolveGlobally(type, out result, out actualSource);
public static bool TryResolve(this DependencySource source, Context context, Type type, out object result) => source.TryResolveInGameObject(context, type, out result) || source.TryResolveGlobally(type, out result);