strip out debugging lines
because dotnet test doesn't give me a good way to hit a breakpoint grumble grumble. or maybe it does but idk it.
This commit is contained in:
parent
85c58cafc0
commit
675bb9824f
@ -43,93 +43,44 @@ namespace greyn.Deployment
|
||||
internal static void populateExpando<T>(T config, ref ExpandoObject fromFile)
|
||||
{
|
||||
if (config == null) return;
|
||||
Console.WriteLine("config is not null");
|
||||
|
||||
Console.WriteLine($"fromfile null: {fromFile == null}");
|
||||
if (fromFile == null)
|
||||
{
|
||||
fromFile = new ExpandoObject();
|
||||
// var expandoPopulated = new ExpandoObject();
|
||||
// var dictionaryFromExpandoPopulated = (IDictionary<string, object?>)expandoPopulated;
|
||||
// foreach (var memberInfo in config.GetType().GetMembers())
|
||||
// {
|
||||
// switch (memberInfo.MemberType)
|
||||
// {
|
||||
// case MemberTypes.Field:
|
||||
// dictionaryFromExpandoPopulated.Add(memberInfo.Name, ((FieldInfo)memberInfo).GetValue(config));
|
||||
// break;
|
||||
// case MemberTypes.Property:
|
||||
// dictionaryFromExpandoPopulated.Add(memberInfo.Name, ((PropertyInfo)memberInfo).GetValue(config));
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// expandoPopulated = (ExpandoObject)dictionaryFromExpandoPopulated;
|
||||
// fromFile = expandoPopulated;
|
||||
// return;
|
||||
}
|
||||
var dictionaryFromExpandoFromFile = (IDictionary<string, object?>)fromFile;
|
||||
Console.WriteLine($"{config.GetType().GetMembers().Count()} members on {config.GetType()}");
|
||||
|
||||
foreach (var memberInfo in config.GetType().GetMembers())
|
||||
{
|
||||
Console.WriteLine($"checking property: {memberInfo.Name}");
|
||||
|
||||
if(memberInfo.DeclaringType == typeof(System.Object))
|
||||
{
|
||||
Console.WriteLine($"junk from system.object, don't care");
|
||||
continue;
|
||||
}
|
||||
if(memberInfo.MemberType != MemberTypes.Field && memberInfo.MemberType != MemberTypes.Property)
|
||||
{
|
||||
Console.WriteLine($"type I don't know how to handle ({memberInfo.MemberType})");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dictionaryFromExpandoFromFile.TryGetValue(memberInfo.Name, out object? valueFromDict))
|
||||
{
|
||||
Console.WriteLine($"dictionary has it - {valueFromDict}");
|
||||
if (valueFromDict != null)
|
||||
{
|
||||
Console.WriteLine($"value from configuration file is not null");
|
||||
|
||||
switch (memberInfo.MemberType)
|
||||
{
|
||||
case MemberTypes.Field:
|
||||
var asField = (FieldInfo)memberInfo;
|
||||
|
||||
//if ((asField.FieldType.GetMembers(BindingFlags.DeclaredOnly)?.Count() ?? 0) > 0)
|
||||
if (dictionaryFromExpandoFromFile[asField.Name] is ExpandoObject childMemberField)
|
||||
{
|
||||
Console.WriteLine($"{asField.Name} (as field) has {asField.FieldType.GetMembers() .Count()} members.");
|
||||
Console.WriteLine($"{dictionaryFromExpandoFromFile[asField.Name]}");
|
||||
|
||||
var childMember = dictionaryFromExpandoFromFile[asField.Name] as ExpandoObject;
|
||||
if(childMember != null)
|
||||
{
|
||||
populateExpando(asField.GetValue(config), ref childMember);
|
||||
//asField.SetValue(fromFile, childMember); //you don't have to set it back. the expandoobject *implements* IDictionary
|
||||
// so when you cast it, it's not a copy; you just access it as a dictionary. So you can change it dynamically.
|
||||
// and we ref'd it so it got the underlying one.
|
||||
//https://stackoverflow.com/questions/4938397/dynamically-adding-properties-to-an-expandoobject
|
||||
}
|
||||
populateExpando(asField.GetValue(config), ref childMemberField);
|
||||
}
|
||||
break;
|
||||
case MemberTypes.Property:
|
||||
var asProperty = (PropertyInfo)memberInfo;
|
||||
//if ((asProperty.PropertyType.GetMembers(BindingFlags.DeclaredOnly)?.Count() ?? 0) > 0)
|
||||
if (dictionaryFromExpandoFromFile[asProperty.Name] is ExpandoObject childMemberProperty)
|
||||
{
|
||||
Console.WriteLine($"{asProperty.Name} (as property) has {asProperty.PropertyType.GetMembers() .Count()} members.");
|
||||
Console.WriteLine($"{dictionaryFromExpandoFromFile[asProperty.Name]}");
|
||||
var childMember = dictionaryFromExpandoFromFile[asProperty.Name] as ExpandoObject; // (ExpandoObject)asProperty.GetValue(fromFile);
|
||||
if(childMember != null)
|
||||
{
|
||||
populateExpando(asProperty.GetValue(config), ref childMember);
|
||||
//asProperty.SetValue(fromFile, childMember);
|
||||
}
|
||||
populateExpando(asProperty.GetValue(config), ref childMemberProperty);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"membertype unhanlded. {memberInfo.MemberType}");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -137,24 +88,19 @@ namespace greyn.Deployment
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"dictionary didn't have it. so let's add to fromFile");
|
||||
switch (memberInfo.MemberType)
|
||||
{
|
||||
case MemberTypes.Field:
|
||||
var addTry = fromFile.TryAdd(memberInfo.Name, ((FieldInfo)memberInfo).GetValue(config));
|
||||
Console.WriteLine($"ostensibly, succeeded? {addTry}");
|
||||
fromFile.TryAdd(memberInfo.Name, ((FieldInfo)memberInfo).GetValue(config));
|
||||
break;
|
||||
case MemberTypes.Property:
|
||||
var addTry2 = fromFile.TryAdd(memberInfo.Name, ((PropertyInfo)memberInfo).GetValue(config));
|
||||
Console.WriteLine($"ostensibly, succeeded? {addTry2}");
|
||||
fromFile.TryAdd(memberInfo.Name, ((PropertyInfo)memberInfo).GetValue(config));
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"type I don't know how to handle ({memberInfo.MemberType})");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
Console.WriteLine($"{memberInfo.Name} handled");
|
||||
}
|
||||
}
|
||||
internal static void readFromExpando<T>(ref T config, ExpandoObject readFromFile)
|
||||
|
Loading…
Reference in New Issue
Block a user