refactor: Load IDataStreamFactory(s) with dependency injection
So we can create ViewStreams that depend on other services, config, etc. Previously, the PrimitiveManager relied purely on static construction of types through reflection.
This commit is contained in:
1 parent
c839652ea3
commit
f5ecbe8c80
83 files changed
+3777
-212
No files matched your search
@@ -0,0 +1,45 @@
|
||||
#nullable enable
|
||||
namespace Bts.DataStreamCore;
|
||||
|
||||
using BCG;
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
public interface IDataStreamMetadata {
|
||||
public string Name { get; }
|
||||
}
|
||||
|
||||
public class DataStreamMetadata : IDataStreamMetadata {
|
||||
public DataStreamMetadata() { }
|
||||
|
||||
public DataStreamMetadata(string name) =>
|
||||
Name = name;
|
||||
|
||||
public string? Name { get; set; }
|
||||
|
||||
string IDataStreamMetadata.Name => Name ?? string.Empty;
|
||||
|
||||
public static DataStreamMetadata FromType(Type type) {
|
||||
var friendlyName = type.GetCustomAttribute<DataStreamUserRespresentation>()?.friendlyName;
|
||||
var rv = new DataStreamMetadata() {
|
||||
Name = friendlyName ?? type.Name,
|
||||
};
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DataStreamMetadataExtensions {
|
||||
public static bool IsMatch(this IDataStreamMetadata dsm, string name, bool ignoreCase = true, bool ignoreUnderscores = true) {
|
||||
var strComp = ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture;
|
||||
var nameWithoutUnderscores = new Lazy<string>(() => RemoveUnderscores(name));
|
||||
return IsNameMatch(dsm.Name);
|
||||
|
||||
static string RemoveUnderscores(string s) =>
|
||||
s.Replace("_", "");
|
||||
|
||||
bool IsNameMatch(string otherName) =>
|
||||
string.Equals(name, otherName, strComp)
|
||||
|| (ignoreUnderscores && string.Equals(RemoveUnderscores(name), RemoveUnderscores(otherName), strComp));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user