private PropNodeCollectionIntInterface ClonePropNodes(PropNodeCollectionIntInterface sourcePNC, BagNode targetParent) { PropNodeCollectionIntInterface result; List <PropNode> newPropNodeColl = new List <PropNode>(); foreach (PropNode propNode in sourcePNC.GetPropNodes()) { PropNode newPropNode = propNode.CloneForNewParent(targetParent, useExistingValues: true); newPropNodeColl.Add(newPropNode); } if (sourcePNC.IsFixed) { System.Diagnostics.Debug.Assert(!sourcePNC.PropItemSetKey.IsEmpty, "We found a fixed PropSetCollection that has an empty PropItemSetKey."); // Create a Fixed PropNodeCollection. result = new PropNodeCollectionFixed(newPropNodeColl, sourcePNC.PropItemSetKey, sourcePNC.MaxPropsPerObject); } else { // Create an open PropNodeCollection. result = new PropNodeCollection(newPropNodeColl, sourcePNC.PropItemSetKey, sourcePNC.MaxPropsPerObject); } return(result); }
public PropNode CreateAndAdd(IPropDataInternal propData_Internal, PropNameType propertyName, BagNode parent) { PropIdType nextPropId = GetNextPropId(); PropNode newPropNode = new PropNode(nextPropId, propData_Internal, parent); Add(newPropNode); return(newPropNode); }
public bool TryGetPropNode(ExKeyT compKey, out PropNode propNode) { bool result; lock (_sync) { result = _children.TryGetValue(compKey, out propNode); } return(result); }
public bool Contains(PropNode propNode) { foreach (PropNode x in _children.Values) { if (ReferenceEquals(x, propNode)) { return(true); } } return(false); }
public void Add(PropNode propNode) { lock (_sync) { _children.Add(propNode.PropId, propNode); if (_propItemsByName != null) { _propItemsByName.Add(propNode.PropertyName, propNode); } } }
public bool TryGetPropNode(PropNameType propertyName, out PropNode propNode) { if (PropItemsByName.TryGetValue(propertyName, out propNode)) { return(true); } else { propNode = null; return(false); } }
public bool TryGetPropNode(PropIdType propId, out PropNode propNode) { if (_children.TryGetValue(propId, out propNode)) { return(true); } else { propNode = null; return(false); } }
public bool TryGetPropNode(PropIdType propId, out PropNode propNode) { lock (_sync) { if (Contains(propId)) { propNode = _children[propId - 1]; // Our Array begin at index 0; PropIds start at 1. (0 is reserved for none or all Properties.) return(true); } } propNode = null; return(false); }
private PropNode[] PopulateChildren(IEnumerable <PropNode> propNodes) { long maxPropId = propNodes.Max(pn => pn.PropId); CheckChildCount(maxPropId - 1); PropNode[] result = new PropNode[maxPropId]; foreach (PropNode pn in propNodes) { result[pn.PropId - 1] = pn; // PropIds start at 1, our array's first index is 0. } return(result); }
private bool TryGetDataFromProp(WeakReference <PSAccessServiceInternalInterface> storeAccessor_wr, PropIdType propId, out object data) { if (storeAccessor_wr.TryGetTarget(out PSAccessServiceInternalInterface storeAccessor)) { PropNode propNode = storeAccessor.GetChild(propId); IPropDataInternal propDataHolder = propNode.PropData_Internal; IProp typedProp = propDataHolder.TypedProp; data = typedProp.TypedValueAsObject; return(true); } else { data = null; return(false); } }
private bool SetPropValue(IPropBag component, PropNode child, PropIdType propId, object value) { try { IProp typedProp = child.PropData_Internal.TypedProp; string propertyName = typedProp.PropertyName; DoSetDelegate dsd = typedProp.PropTemplate.DoSetDelegate; bool result = dsd(component, propId, propertyName, typedProp, value); return(result); } catch { throw; } }
/// <summary> /// Creates a new PropNode using this PropNode as a 'template.' /// If useExistingValues is set to True, exceptions will be thrown if /// the PropItem's value cannot be cloned. /// </summary> /// <param name="parent"></param> /// <param name="useExistingValues"> /// If True, the current values are cloned, /// If False the default values are used.</param> /// <returns></returns> public PropNode CloneForNewParent(BagNode parent, bool useExistingValues) { IProp newTypeProp; if (useExistingValues) { newTypeProp = (IProp)PropData_Internal.TypedProp.Clone(); } else { throw new NotImplementedException("CloneForNewParent only supports useExistingValues = true."); } IPropDataInternal newPropData_Internal = new PropGen(newTypeProp); PropNode newPropNode = new PropNode(PropId, newPropData_Internal, parent); return(newPropNode); }
public bool TryRemove(PropIdType propId, out PropNode propNode) { lock (_sync) { if (_children.TryGetValue(propId, out propNode)) { _children.Remove(propId); if (_propItemsByName != null) { _propItemsByName.Remove(propNode.PropertyName); } return(true); } } propNode = null; return(false); }
private BagNode GetBagAndChild(WeakRefKey <IPropBag> propBag_wrKey, PropItemSetKeyType propItemSetKey, PropIdType propId, out PropNode child) { if (!TryGetPropBagNode(propBag_wrKey, out BagNode propBagNode)) { throw new InvalidOperationException("The store has lost this node."); } if (!propBag_wrKey.TryGetTarget(out IPropBag target)) { throw new InvalidOperationException("IPropBag target has been Garbage Collected."); } if (propItemSetKey != propBagNode.PropItemSetKey) { throw new InvalidOperationException("Bad PropModel."); } //if (!propItemSetId.Value.TryGetTarget(out PropModelType testModel)) //{ // throw new InvalidOperationException("The specified PropItemSetId has been Garbage Collected."); //} //if (!propBagNode.PropItemSetId.Value.TryGetTarget(out PropModelType testModel_fromBagNode)) //{ // throw new InvalidOperationException("The PropItemSetId on our BagNode has been Garbage Collected."); //} //if(!ReferenceEquals(testModel, testModel_fromBagNode)) //{ // throw new InvalidOperationException("PropItemSet do not match."); //} if (!propBagNode.TryGetChild(propId, out child)) { throw new InvalidOperationException("Could not retrieve PropNode for that compKey."); } return(propBagNode); }
public bool TryRemove(PropIdType propId, out PropNode propNode) { throw new InvalidOperationException("PropItems cannot be removed from a fixed PropItemSet."); }
public void Add(PropNode propNode) { throw new InvalidOperationException("Cannot Add PropItems to a Fixed PropItemSet."); }