private static IList <string> GetPropertyDifferences(Table table, dynamic instance, bool doTypeConversion = true) { var tableHeadersAsPropertyNames = table.Header.Select(CreatePropertyName); IEnumerable <string> instanceMembers = Impromptu.GetMemberNames(instance); return(GetPropertyNameDifferences(tableHeadersAsPropertyNames, instanceMembers)); }
private static IList <string> GetPropertyDifferences(Table table, dynamic instance, Options options) { var tableHeadersAsPropertyNames = table.Header.Select(x => CreatePropertyName(x, options)); IEnumerable <string> instanceMembers = Impromptu.GetMemberNames(instance); return(GetPropertyNameDifferences(tableHeadersAsPropertyNames, instanceMembers)); }
private static List <string> GetSetValueDifferences(Table table, IList <object> set, bool doTypeConversion = true) { var memberNames = Impromptu.GetMemberNames(set[0]); var valueDifference = new List <string>(); for (var i = 0; i < set.Count; i++) { foreach (var memberName in memberNames) { var currentHeader = string.Empty; var rowValue = GetRowValue(i, table, memberName, out currentHeader, doTypeConversion); var rowType = rowValue.GetType().Name; var instanceValue = Impromptu.InvokeGet(set[i], memberName); var instanceType = instanceValue.GetType().Name; if (!instanceValue.Equals(rowValue)) { var difference = string.Format(ERRORMESS_SET_VALUES_DIFFERS, i + 1, currentHeader, memberName, instanceValue, instanceType, rowValue, rowType); valueDifference.Add(difference); } } } return(valueDifference); }
public static IPropertyValueGetter CreateDynamicObjectValueGetter(dynamic instance, string propertyName) { List <string> memberNames = Impromptu.GetMemberNames(instance, true); string matchedName = memberNames.Find( s => s.Equals(propertyName, StringComparison.OrdinalIgnoreCase)); return(matchedName == null ? null : new DynamicPropertyValueGetter(matchedName)); }
/// <summary> /// Returns the enumeration of all dynamic member names. /// </summary> /// <returns> A sequence that contains dynamic member names. </returns> public override IEnumerable <string> GetDynamicMemberNames() { if (!KnownInterfaces.Any()) { var tDyanmic = Impromptu.GetMemberNames(CallTarget, dynamicOnly: true); if (!tDyanmic.Any()) { return(Impromptu.GetMemberNames(CallTarget)); } } return(base.GetDynamicMemberNames()); }
public void GetComDisplayNames() { var wordApp = new Word.Application(); var docs = wordApp.Documents; var names = Impromptu.GetMemberNames(docs); Assert.AreEqual(4, names.Count()); wordApp.Quit(); }
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[] listAccessors) { IEnumerable <string> tList = new string[] {}; if (OverrideGettingItemMethodNames != null) { tList = OverrideGettingItemMethodNames(this); } else { tList = Impromptu.GetMemberNames(GetRepresentedItem(), dynamicOnly: true); } return(new PropertyDescriptorCollection(tList.Select(it => new ImpromptuPropertyDescriptor(it)).ToArray())); }
public static bool AreEqual(dynamic source, dynamic target) { IEnumerable <string> list1 = Impromptu.GetMemberNames(source); list1 = list1.OrderBy(m => m); IEnumerable <string> list2 = Impromptu.GetMemberNames(target); list2 = list2.OrderBy(m => m); if (!list1.SequenceEqual(list2)) { return(false); } return(list1.All(memberName => Impromptu.InvokeGet(source, memberName).Equals(Impromptu.InvokeGet(target, memberName)))); }
public static T ToStatic <T>(dynamic source) { var entity = Activator.CreateInstance <T>(); var properties = Impromptu.GetMemberNames(source); if (properties == null) { return(entity); } foreach (var entry in properties) { var value = Impromptu.InvokeGet(source, entry); Impromptu.InvokeSet(entity, entry, value); } return(entity); }
private static List <string> GetSetValueDifferences(Table table, IList <object> set, Options options) { var memberNames = Impromptu.GetMemberNames(set[0]); var valueDifference = new List <string>(); for (var i = 0; i < set.Count; i++) { foreach (var memberName in memberNames) { var currentHeader = string.Empty; var rowValue = GetRowValue(i, table, memberName, out currentHeader, options); if ((rowValue.GetType() == typeof(string)) && ((string)rowValue == "NULL")) { rowValue = null; } var instanceValue = Impromptu.InvokeGet(set[i], memberName); if (((instanceValue != null) || (rowValue != null)) && !instanceValue.Equals((dynamic)rowValue)) { var rowType = rowValue.GetType().Name; var instanceType = instanceValue.GetType().Name; var difference = string.Format(ERRORMESS_SET_VALUES_DIFFERS, i + 1, currentHeader, memberName, instanceValue, instanceType, rowValue, rowType); valueDifference.Add(difference); } } } return(valueDifference); }
public void TestDynamicMemberNamesImpromput() { ImpromptuDictionary tDict = Build.NewObject(Two: 2); Assert.AreEqual("Two", Impromptu.GetMemberNames(tDict, dynamicOnly: true).Single()); }
public void TestDynamicMemberNamesExpando() { ExpandoObject tExpando = Build <ExpandoObject> .NewObject(One : 1); Assert.AreEqual("One", Impromptu.GetMemberNames(tExpando, dynamicOnly: true).Single()); }