示例#1
0
 public FunctionalTypeChecker(TypeInferred typeInferred, TypeNotFound typeNotFound, TypeMismatch typeMismatch,
                              TypeNotRelevant typeNotRelevant)
 {
     TypeInferred    = typeInferred;
     TypeNotFound    = typeNotFound;
     TypeMismatch    = typeMismatch;
     TypeNotRelevant = typeNotRelevant;
 }
        public Type BindToType(string assemblyName, [Required] string typeName)
        {
            Type result;

            try
            {
                if (_knownTypes.ContainsKey(typeName))
                {
                    result = _knownTypes[typeName];
                }
                else
                {
#if NETCOREAPP
                    if (string.CompareOrdinal(assemblyName, "mscorlib") == 0)
                    {
                        assemblyName = "System.Private.CoreLib";
                    }
#else
                    if (string.CompareOrdinal(assemblyName, "System.Private.CoreLib") == 0)
                    {
                        assemblyName = "mscorlib";
                    }
#endif
                    var assembly = Assembly.Load(assemblyName);
                    result = GetGenericType(typeName, assembly);

                    if (result == null)
                    {
                        if (typeName.EndsWith("[]"))
                        {
                            int length = typeName.IndexOf('[');
                            if (length >= 0)
                            {
                                string name = typeName.Substring(0, length);
                                if (_knownTypes.ContainsKey(name))
                                {
                                    result = assembly.GetType(typeName);
                                    if (result != null)
                                    {
                                        _knownTypes.Add(typeName, result);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                result          = typeof(object);
                HasUnknownTypes = true;
                TypeNotFound?.Invoke(assemblyName, typeName);
            }

            return(result);
        }
示例#3
0
        public Type BindToType(string assemblyName, [Required] string typeName)
        {
            Type result;

            try
            {
                if (_knownTypes.ContainsKey(typeName))
                {
                    result = _knownTypes[typeName];
                }
                else
                {
                    var assembly = Assembly.Load(assemblyName);
                    result = GetGenericType(typeName, assembly);

                    if (result == null)
                    {
                        if (typeName.EndsWith("[]"))
                        {
                            int length = typeName.IndexOf('[');
                            if (length >= 0)
                            {
                                string name = typeName.Substring(0, length);
                                if (_knownTypes.ContainsKey(name))
                                {
                                    result = assembly.GetType(typeName);
                                    if (result != null)
                                    {
                                        _knownTypes.Add(typeName, result);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                result = typeof(object);
                TypeNotFound?.Invoke(assemblyName, typeName);
            }

            return(result);
        }
示例#4
0
 /// <inheritdoc/>
 public TResult GetValue <TResult>() where TResult : V
 {
     try
     {
         if (!_dictionary.TryGetValue(typeof(TResult), out V result))
         {
             var args = new TypeNotFoundEventArgs <V>(typeof(TResult));
             TypeNotFound?.Invoke(this, args);
             if (args.Value is TResult newResult)
             {
                 Add(newResult);
                 return(newResult);
             }
         }
         return((TResult)result);
     }
     catch (KeyNotFoundException ex)
     {
         throw new TypeNotFoundException(Properties.Resources.TypeDictionary_TypeNotFound.FormatString(typeof(TResult).FullName), ex);
     }
 }