コード例 #1
0
        private void AddConfigToMetadata(DisplayMetadata modelMetaData)
        {
            if (!string.IsNullOrEmpty(ConfigFilePath))
            {
                ValidateFilePathSource();

                modelMetaData.AdditionalValues.Add("ConfigPath", ConfigFilePath);
            }

            if (ConfigSource == null)
            {
                return;
            }

            if (ConfigSource.GetConstructor(Type.EmptyTypes) == null)
            {
                var msg = $"ConfigSource type '{ConfigSource.FullName}'does not have a public parameterless constructor.";
                throw new InvalidOperationException(msg);
            }

            var source = Activator.CreateInstance(ConfigSource);

            if (source is IHtmlEditorConfigSource configSource)
            {
                modelMetaData.AdditionalValues.Add("Options", configSource.Create());
            }
            else
            {
                var msg = $"ConfigSource type '{ConfigSource.FullName}' is not a valid config type. Valid types inherit from {typeof(IHtmlEditorConfigSource).Name}";
                throw new InvalidOperationException(msg);
            }
        }