예제 #1
0
        /// <summary>
        /// 设置source源
        /// </summary>
        private void EnumerateMetaSourceAttributes(Type classType, List <MetaSourceData> MetaSourceList)
        {
            #region PropertySource

            var metaSourceAttributes = classType.GetCustomAttributes <PropertySource>().ToList();
            if (metaSourceAttributes.Any())
            {
                metaSourceAttributes = metaSourceAttributes.OrderByDescending(r => r.OrderIndex).ToList();
                foreach (var metaSourceAttribute in metaSourceAttributes)
                {
                    MetaSourceData metaSource = new MetaSourceData
                    {
                        Origin         = metaSourceAttribute.Path,
                        Embedded       = metaSourceAttribute.Embedded,
                        MetaSourceType = metaSourceAttribute.MetaSourceType,
                        Order          = metaSourceAttribute.OrderIndex
                    };

                    if (string.IsNullOrEmpty(metaSourceAttribute.Path))
                    {
                        MetaSourceList.Add(GetDefaultMetaSource());
                        continue;
                    }


                    if (metaSourceAttribute.Embedded)
                    {
                        metaSource.Path = metaSource.Origin;
                    }
                    else
                    {
                        metaSource.Path = metaSource.Origin.StartsWith("/")
                            ? Path.Combine(GetAssemblyLocation(), metaSource.Origin.Substring(1, metaSource.Origin.Length - 1))
                            : metaSource.Origin;
                    }

                    metaSource.Configuration = EmbeddedConfiguration.Load(classType, metaSource.Path, metaSource.MetaSourceType,
                                                                          metaSourceAttribute.Embedded);

                    MetaSourceList.Add(metaSource);
                }
            }
            else
            {
                MetaSourceData metaSource = new MetaSourceData
                {
                    Origin         = "appsettings.json",
                    Embedded       = false,
                    MetaSourceType = MetaSourceType.JSON,
                    Order          = 0
                };
                metaSource.Path          = Path.Combine(GetAssemblyLocation(), metaSource.Origin);
                metaSource.Configuration = EmbeddedConfiguration.Load(null, metaSource.Path, metaSource.MetaSourceType, metaSource.Embedded);
                MetaSourceList.Add(metaSource);
            }

            #endregion
        }
예제 #2
0
        private static MetaSourceData GetDefaultMetaSource()
        {
            MetaSourceData metaSource = new MetaSourceData();

            metaSource.Origin         = "appsettings.json";
            metaSource.Embedded       = false;
            metaSource.MetaSourceType = MetaSourceType.JSON;
            metaSource.Path           = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, metaSource.Origin);
            metaSource.Configuration  = EmbeddedConfiguration.Load(null, metaSource.Path, metaSource.MetaSourceType, metaSource.Embedded);
            return(metaSource);
        }
예제 #3
0
        /// <summary>
        /// 设置source源
        /// </summary>
        /// <param name="componentModel"></param>
        private void EnumerateMetaSourceAttributes(ComponentModel componentModel)
        {
            #region PropertySource

            componentModel.MetaSourceList = new List <MetaSourceData>();
            var metaSourceAttributes = componentModel.CurrentType.GetCustomAttributes <PropertySource>().ToList();
            if (metaSourceAttributes.Any())
            {
                metaSourceAttributes = metaSourceAttributes.OrderBy(r => r.Order).ToList();
                foreach (var metaSourceAttribute in metaSourceAttributes)
                {
                    MetaSourceData metaSource = new MetaSourceData
                    {
                        Origin         = metaSourceAttribute.Path,
                        Embedded       = metaSourceAttribute.Embedded,
                        MetaSourceType = metaSourceAttribute.MetaSourceType,
                        Order          = metaSourceAttribute.Order
                    };

                    if (string.IsNullOrEmpty(metaSourceAttribute.Path))
                    {
                        metaSource.Origin         = "appsettings.json";
                        metaSource.Embedded       = false;
                        metaSource.MetaSourceType = MetaSourceType.JSON;
                        metaSource.Path           = Path.Combine(GetAssemblyLocation(), metaSource.Origin);
                        metaSource.Configuration  = EmbeddedConfiguration.Load(null, metaSource.Path, metaSource.MetaSourceType, metaSource.Embedded);
                        componentModel.MetaSourceList.Add(metaSource);
                        continue;
                    }


                    if (metaSourceAttribute.Embedded)
                    {
                        metaSource.Path = metaSource.Origin;
                    }
                    else
                    {
                        metaSource.Path = metaSource.Origin.StartsWith("/")
                            ? Path.Combine(GetAssemblyLocation(), metaSource.Origin.Substring(1, metaSource.Origin.Length - 1))
                            : metaSource.Origin;
                    }

                    metaSource.Configuration = EmbeddedConfiguration.Load(componentModel.CurrentType, metaSource.Path, metaSource.MetaSourceType,
                                                                          metaSourceAttribute.Embedded);

                    componentModel.MetaSourceList.Add(metaSource);
                }
            }
            else
            {
                MetaSourceData metaSource = new MetaSourceData
                {
                    Origin         = "appsettings.json",
                    Embedded       = false,
                    MetaSourceType = MetaSourceType.JSON,
                    Order          = 0
                };
                metaSource.Path          = Path.Combine(GetAssemblyLocation(), metaSource.Origin);
                metaSource.Configuration = EmbeddedConfiguration.Load(null, metaSource.Path, metaSource.MetaSourceType, metaSource.Embedded);
                componentModel.MetaSourceList.Add(metaSource);
            }

            #endregion
        }