private void Assign() { try { var canBeNull = !collectionItemType.GetTypeInfo().IsValueType || (Nullable.GetUnderlyingType(collectionItemType) != null); var listType = typeof(List <>); var constructedListType = listType.MakeGenericType(collectionItemType); var list = (IList)Activator.CreateInstance(constructedListType); foreach (var item in collection) { if (!canBeNull && item.Value == null) { continue; } list.Add(item.Value == NullEntry ? null : Convert.ChangeType(item.Value, collectionItemType ?? typeof(object))); } ValueStore.SetValue(list); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Assignment error: " + ex.Message); //System.Windows.MessageBox.Show("Assignment error: " + ex.Message); } }
public void Captured() { var x = new object(); ValueStore store = new ValueStore(); Action action = () => store.SetValue(x); Func <Object> f = () => store.GetValue(); //Implicitly capture closure: x }
private void Assign() { Error = string.Empty; try { var canBeNull = !collectionItemType.GetTypeInfo().IsValueType || (Nullable.GetUnderlyingType(collectionItemType) != null); var listType = typeof(List <>); var constructedListType = listType.MakeGenericType(collectionItemType); var list = (IList)Activator.CreateInstance(constructedListType); foreach (var item in collection) { if (item.ValueChanged == null) { item.ValueChanged = Assign; } if (!canBeNull && item.Value == null) { continue; } list.Add(Convert.ChangeType(item.Value, collectionItemType ?? typeof(object))); } ValueStore.SetValue(list); } catch (Exception ex) { Error = ex.Message; } Changed(() => Error); }
internal virtual void SetValue(ParserFieldFormatSpecifier aFormat, ParserFieldFormatValue aValue) { ValueStore vs = GetValueStore(this); if (vs == null) { // Make a new "store internally" value store iValueStore = new ValueStore(); vs = iValueStore; } // vs.SetValue(aFormat, aValue); }