Skip to content

Commit

Permalink
1.2.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Jurioli committed Sep 3, 2021
1 parent 4fc26d1 commit 224dbd8
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 12 deletions.
Binary file removed Applied.1.2.1.5.nupkg
Binary file not shown.
Binary file added Applied.1.2.1.6.nupkg
Binary file not shown.
16 changes: 15 additions & 1 deletion Applied/ComponentModel/DictionaryPropertyDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ internal class DictionaryPropertyDescriptor : PropertyDescriptor
{
private readonly string _key;
private readonly Type _type;
private readonly bool _valuesNull;
public override Type ComponentType
{
get
Expand Down Expand Up @@ -34,11 +35,24 @@ public override string DisplayName
return string.Empty;
}
}
internal bool ValuesNull
{
get
{
return _valuesNull;
}
}
public DictionaryPropertyDescriptor(string key, Type type)
: base(key.ToString(), null)
: this(key, type, false)
{

}
public DictionaryPropertyDescriptor(string key, Type type, bool valuesNull)
: base(key, null)
{
_key = key;
_type = type;
_valuesNull = valuesNull;
}
public override bool CanResetValue(object component)
{
Expand Down
16 changes: 13 additions & 3 deletions Applied/Properties.GetProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,24 @@ private static PropertyDescriptor[] GetPropertyDescriptors<TDictionary>(string[]
{
return GetDictionaryPropertyDescriptors(keys, dictionaries).ToArray();
}
private static PropertyDescriptor[] GetPropertyDescriptors<TDictionary>(string[] keys, TDictionary[] dictionaries, out bool[] dictionaryNullProperties)
where TDictionary : IDictionary
{
DictionaryPropertyDescriptor[] properties = GetDictionaryPropertyDescriptors(keys, dictionaries).ToArray();
dictionaryNullProperties = properties.Select(a => a.ValuesNull).ToArray();
return properties;
}
private static IEnumerable<DictionaryPropertyDescriptor> GetDictionaryPropertyDescriptors<TDictionary>(string[] keys, TDictionary[] dictionaries)
where TDictionary : IDictionary
{
foreach (string key in keys)
{
Type valueType = GetDictionaryPropertyDescriptorValueType(key, dictionaries);
yield return new DictionaryPropertyDescriptor(key, valueType);
bool valuesNull;
Type valueType = GetDictionaryPropertyDescriptorValueType(key, dictionaries, out valuesNull);
yield return new DictionaryPropertyDescriptor(key, valueType, valuesNull);
}
}
private static Type GetDictionaryPropertyDescriptorValueType<TDictionary>(string key, TDictionary[] dictionaries)
private static Type GetDictionaryPropertyDescriptorValueType<TDictionary>(string key, TDictionary[] dictionaries, out bool valuesNull)
where TDictionary : IDictionary
{
foreach (TDictionary dictionary in dictionaries)
Expand All @@ -85,10 +93,12 @@ private static Type GetDictionaryPropertyDescriptorValueType<TDictionary>(string
object value = dictionary[key];
if (value != null)
{
valuesNull = false;
return value.GetType();
}
}
}
valuesNull = true;
return typeof(object);
}
private static PropertyDescriptor[] GetPropertyDescriptors(Type componentType)
Expand Down
30 changes: 25 additions & 5 deletions Applied/Properties.JoinMatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,21 @@ private static IEnumerable<MatchProperty> JoinMatches(PropertyDescriptorsInfo le
{
PropertyKey[] rightKeys = new PropertyKey[right.Properties.Length];
List<int> list = new List<int>();
for (int i = 0; i < rightKeys.Length; i++)
if (right.Kind == PropertyDescriptorKind.Dictionary && right.DictionaryNullProperties != null)
{
rightKeys[i] = GetPropertyKey(right.Properties[i]);
list.Add(i);
for (int i = 0; i < rightKeys.Length; i++)
{
rightKeys[i] = GetPropertyKey(right.Properties[i], right.DictionaryNullProperties[i]);
list.Add(i);
}
}
else
{
for (int i = 0; i < rightKeys.Length; i++)
{
rightKeys[i] = GetPropertyKey(right.Properties[i]);
list.Add(i);
}
}
if (!ignoreCaseName)
{
Expand Down Expand Up @@ -103,18 +114,27 @@ private static PropertyKey GetPropertyKey(PropertyDescriptor property)
{
return new PropertyKey() { Name = property.Name, Type = GetMatchType(property.PropertyType) };
}
private static PropertyKey GetPropertyKey(PropertyDescriptor property, bool valuesNull)
{
return new PropertyKey() { Name = property.Name, Type = GetMatchType(property.PropertyType), ValuesNull = valuesNull };
}
private static bool ComparePropertyKey(PropertyKey x, PropertyKey y)
{
return x.Name == y.Name && (x.Type == y.Type || y.Type == typeof(object) || y.Type.IsAssignableFrom(x.Type));
return x.Name == y.Name && (
x.Type == y.Type || y.Type == typeof(object) || y.Type.IsAssignableFrom(x.Type) ||
(x.ValuesNull && (!y.Type.IsValueType || y.Type.IsNullable())));
}
private static bool ComparePropertyKeyIgnoreCase(PropertyKey x, PropertyKey y)
{
return string.Equals(x.Name, y.Name, StringComparison.OrdinalIgnoreCase) && (x.Type == y.Type || y.Type == typeof(object) || y.Type.IsAssignableFrom(x.Type));
return string.Equals(x.Name, y.Name, StringComparison.OrdinalIgnoreCase) && (
x.Type == y.Type || y.Type == typeof(object) || y.Type.IsAssignableFrom(x.Type) ||
(x.ValuesNull && (!y.Type.IsValueType || y.Type.IsNullable())));
}
private class PropertyKey
{
public string Name { get; set; }
public Type Type { get; set; }
public bool ValuesNull { get; set; }
}
}
}
5 changes: 4 additions & 1 deletion Applied/Properties.PropertyDescriptorsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private class PropertyDescriptorsInfo
public PropertyDescriptorKind Kind { get; private set; }
public PropertyDescriptor[] Properties { get; set; }
public Type DictionaryValueType { get; set; }
public bool[] DictionaryNullProperties { get; set; }
public PropertyDescriptorsInfo(Type type, PropertyDescriptorKind kind)
{
this.Type = type;
Expand Down Expand Up @@ -115,7 +116,9 @@ public void LoadProperties(IEnumerable items)
}
else
{
this.Properties = GetPropertyDescriptors(keys, dictionaries);
bool[] dictionaryNullProperties;
this.Properties = GetPropertyDescriptors(keys, dictionaries, out dictionaryNullProperties);
this.DictionaryNullProperties = dictionaryNullProperties;
}
}
catch (InvalidCastException)
Expand Down
4 changes: 2 additions & 2 deletions Applied/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 您可以指定所有的值,或將組建編號或修訂編號設為預設值
//方法是使用 '*',如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.1.5")]
[assembly: AssemblyFileVersion("1.2.1.5")]
[assembly: AssemblyVersion("1.2.1.6")]
[assembly: AssemblyFileVersion("1.2.1.6")]

0 comments on commit 224dbd8

Please sign in to comment.