Пример #1
0
        DFrameWorkloadCollection(Assembly[] searchAssemblies, bool includesDefault, IServiceProviderIsService isService)
        {
            dframeTypes = new Dictionary <string, DFrameWorkloadTypeInfo>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var asm in searchAssemblies)
            {
                if (asm.FullName !.StartsWith("System") || asm.FullName.StartsWith("Microsoft.Extensions"))
                {
                    continue;
                }

                Type[] types;
                try
                {
                    types = asm.GetTypes();
                }
                catch (ReflectionTypeLoadException ex)
                {
                    types = ex.Types.Where(x => x != null).ToArray() !;
                }

                foreach (var workload in types)
                {
                    if (typeof(Workload).IsAssignableFrom(workload) && !workload.IsAbstract)
                    {
#if !UNITY_2020_1_OR_NEWER
                        var isDefault = workload.GetCustomAttribute <DefaultWorkloadAttribute>(true);
                        if (isDefault != null)
                        {
                            if (!includesDefault)
                            {
                                continue;
                            }
                        }
#endif

                        var attr = workload.GetCustomAttribute <WorkloadAttribute>(false);
                        var name = attr?.Name ?? workload.Name;

                        var t = new DFrameWorkloadTypeInfo(workload, name, isService);
                        if (!dframeTypes.TryAdd(name, t))
                        {
                            throw new InvalidOperationException($"Worker name is duplicate. name:{name}, type:{t.WorkloadType.FullName}");
                        }
                    }
                }
            }
        }
Пример #2
0
 internal static bool TryAdd(this Dictionary <string, DFrameWorkloadTypeInfo> dict, string key, DFrameWorkloadTypeInfo value)
 {
     if (!dict.ContainsKey(key))
     {
         dict.Add(key, value);
         return(true);
     }
     return(false);
 }