/// <summary> /// Resolves the lookup but may not fail if missing. /// </summary> /// <param name="context">Frontend compiler containing all the objects that may satisfy the resolution.</param> /// <param name="allowUnresolved">Flag specifying whether to allow unresolved items to be returned.</param> /// <returns>Item resolved.</returns> public PackageItem Resolve(FrontendCompiler context, bool allowUnresolved) { if (this.ResolvedItem == null) { string targetPropertyName = this.targetProperty == null ? String.Empty : this.targetProperty.Name; CompilerMessage message = null; PackageItem item = null; if (context.TryGetItemById(this.Lookup, out item)) { if (this.targetType.IsInstanceOfType(item)) { if (this.targetProperty != null) { this.SetTarget(context, item); } } else if (!allowUnresolved) { message = CompilerMessage.InvalidIdResolution( targetPropertyName, this.Lookup, this.targetType.Name, item.GetType().Name); } } else if (this.targetType.IsSubclassOf(typeof(FileSystemResource)) || this.targetType == typeof(IFileReference)) { Resource resource; FileSystemResourceManager manager = (FileSystemResourceManager)context.GetService(typeof(FileSystemResourceManager)); if (manager.TryFindResourceByPath(context, this.Lookup, out resource)) { if (this.targetType.IsInstanceOfType(resource)) { if (this.targetProperty != null) { item = this.SetTarget(context, resource); } else { item = resource; } } else { message = CompilerMessage.InvalidIdResolution( targetPropertyName, this.Lookup, this.targetType.Name, resource.GetType().Name); } } else if (!allowUnresolved) { message = CompilerMessage.UnknownFileSystemResolution( targetPropertyName, this.Lookup, this.targetType.Name); } } else if (!allowUnresolved) { message = CompilerMessage.UnknownIdResolution( targetPropertyName, this.Lookup, this.targetType.Name); } if (message != null) { context.OnMessage(new CompilerMessageEventArgs(message, this.targetItem)); } this.ResolvedItem = item; } return(this.ResolvedItem); }