Esempio n. 1
0
        /// <summary>
        /// Create a new instance with copied values.
        /// </summary>
        /// <param name="copy">The base instance to copy from.</param>
        protected DependencyInfo(IDependencyInfo copy) : this()
        {
            if (copy == null)
            {
                return;
            }

            Key   = copy.Key;
            Scope = copy.Scope;

            foreach (var resolvedType in copy.ResolvedTypes)
            {
                ResolvedTypes.Add(resolvedType);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Used to try to get and cache the tree type
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        internal static Type TryGetType(string type)
        {
            try
            {
                return(ResolvedTypes.GetOrAdd(type, s =>
                {
                    var result = System.Type.GetType(type);
                    if (result != null)
                    {
                        return result;
                    }

                    //we need to implement a bit of a hack here due to some trees being renamed and backwards compat
                    var parts = type.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (parts.Length == 2)
                    {
                        if (parts[1].Trim() == "umbraco" && parts[0].StartsWith("Umbraco.Web.Trees") && parts[0].EndsWith("Controller") == false)
                        {
                            //if it's one of our controllers but it's not suffixed with "Controller" then add it and try again
                            var tempType = parts[0] + "Controller, umbraco";

                            result = System.Type.GetType(tempType);
                            if (result != null)
                            {
                                return result;
                            }
                        }
                    }

                    throw new InvalidOperationException("Could not resolve type");
                }));
            }
            catch (InvalidOperationException)
            {
                //swallow, this is our own exception, couldn't find the type
                return(null);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Overridden ToString describing the class properties.
 /// </summary>
 /// <returns></returns>
 public override string ToString()
 {
     return($"Dependency Info: Key={Key}, Scope={Scope}, ResolveTypes={ResolvedTypes.ToArray()}");
 }
Esempio n. 4
0
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="requestType">Specify the request type.</param>
 /// <param name="instance">The instance that is always returned.</param>
 public DependencyInstanceInfo(Type requestType, object instance) : base(scope: DependyBuilderScope.Singleton)
 {
     Instance = instance ?? throw new ArgumentNullException(nameof(instance));
     Validate(requestType, instance);
     ResolvedTypes.Add(requestType);
 }