protected MethodInstance ImplementUsePropertyChangeSupport(PropertyInstance p_propertyChangeTemplate, FieldInstance f_propertyChangeSupport) { MethodInstance m_getPropertyChangeSupport = MethodInstance.FindByTemplate(template_m_usePropertyChangeSupport, true); if (m_getPropertyChangeSupport == null) { // create field that holds propertyChangeSupport f_propertyChangeSupport = ImplementField(f_propertyChangeSupport); IMethodVisitor mg = VisitMethod(template_m_usePropertyChangeSupport); HideFromDebug(mg.Method); Label l_pcsValid = mg.NewLabel(); mg.GetThisField(f_propertyChangeSupport); mg.Dup(); mg.IfNonNull(l_pcsValid); mg.Pop(); // remove 2nd null instance from stack caused by previous dup mg.PutThisField(f_propertyChangeSupport, delegate(IMethodVisitor mg2) { mg.CallThisGetter(p_propertyChangeTemplate); mg.LoadThis(); mg.InvokeVirtual(m_newPropertyChangeSupport); }); mg.GetThisField(f_propertyChangeSupport); mg.Mark(l_pcsValid); mg.ReturnValue(); // return instance already on the stack by both branches mg.EndMethod(); m_getPropertyChangeSupport = mg.Method; } return(m_getPropertyChangeSupport); }
public static void Replace(PropertyInstance propertyInstance, PropertyType newType) { TerrainInstance t = propertyInstance.terrainInstance; Destroy( t.property.gameObject ); t.property = null; Create( t, newType ); }
///-------------------------------------------------------------------------------- /// <summary>This method deletes an instance of PropertyInstance.</summary> /// /// <param name="propertyInstance">The PropertyInstance to delete.</param> ///-------------------------------------------------------------------------------- public void DeletePropertyInstance(PropertyInstance propertyInstance) { bool isItemMatch = false; foreach (PropertyInstanceViewModel item in PropertyInstances.ToList <PropertyInstanceViewModel>()) { if (item.PropertyInstance.PropertyInstanceID == propertyInstance.PropertyInstanceID) { // remove item from tabs, if present WorkspaceEventArgs message = new WorkspaceEventArgs(); message.ItemID = item.PropertyInstance.PropertyInstanceID; Mediator.NotifyColleagues <WorkspaceEventArgs>(MediatorMessages.Command_CloseItemRequested, message); // delete PropertyInstance isItemMatch = true; PropertyInstances.Remove(item); ObjectInstance.PropertyInstanceList.Remove(item.PropertyInstance); Solution.PropertyInstanceList.Remove(item.PropertyInstance); Items.Remove(item); ObjectInstance.ResetModified(true); OnUpdated(this, null); break; } } if (isItemMatch == false) { ShowIssue(DisplayValues.Issue_DeleteItemNotFound); } }
///-------------------------------------------------------------------------------- /// <summary>This method updates an item of PropertyInstance.</summary> /// /// <param name="propertyInstance">The PropertyInstance to update.</param> ///-------------------------------------------------------------------------------- public void UpdateEditPropertyInstance(PropertyInstance propertyInstance) { bool isItemMatch = false; foreach (PropertyInstanceViewModel item in PropertyInstances) { if (item.PropertyInstance.PropertyInstanceID == propertyInstance.PropertyInstanceID) { isItemMatch = true; item.PropertyInstance.TransformDataFromObject(propertyInstance, null, false); if (!item.PropertyInstance.ModelPropertyID.IsNullOrEmpty()) { item.PropertyInstance.ModelProperty = Solution.ModelPropertyList.FindByID((Guid)item.PropertyInstance.ModelPropertyID); } item.OnUpdated(item, null); break; } } if (isItemMatch == false) { // add new PropertyInstance propertyInstance.ObjectInstance = ObjectInstance; PropertyInstanceViewModel newItem = new PropertyInstanceViewModel(propertyInstance, Solution); if (!newItem.PropertyInstance.ModelPropertyID.IsNullOrEmpty()) { newItem.PropertyInstance.ModelProperty = Solution.ModelPropertyList.FindByID((Guid)newItem.PropertyInstance.ModelPropertyID); } newItem.Updated += new EventHandler(Children_Updated); PropertyInstances.Add(newItem); ObjectInstance.PropertyInstanceList.Add(propertyInstance); Solution.PropertyInstanceList.Add(newItem.PropertyInstance); Items.Add(newItem); OnUpdated(this, null); } }
protected void ImplementNotifyPropertyChanged(PropertyInstance p_propertyChangeTemplate, MethodInstance m_getPropertyChangeSupport) { // implement IPropertyChanged foreach (MethodInfo rMethod in typeof(INotifyPropertyChanged).GetMethods()) { MethodInstance existingMethod = MethodInstance.FindByTemplate(rMethod, true); if (existingMethod != null) { continue; } MethodInstance method = new MethodInstance(rMethod); IMethodVisitor mg = VisitMethod(method); mg.CallThisGetter(p_propertyChangeTemplate); // this.propertyChangeSupport mg.CallThisGetter(m_getPropertyChangeSupport); // listener mg.LoadArg(0); if ("add_PropertyChanged".Equals(method.Name)) { // addPropertyChangeListener(propertyChangeSupport, listener) mg.InvokeVirtual(m_addPropertyChangeListener); } else { // removePropertyChangeListener(propertyChangeSupport, listener) mg.InvokeVirtual(m_removePropertyChangeListener); } mg.ReturnValue(); mg.EndMethod(); } }
private bool ShouldReplaceWithCollection(PropertyInstance property, bool isNull, string collectionTypeName) { ExceptionUtilities.CheckArgumentNotNull(property, "property"); // only replace root elements with no null-marker or type name bool shouldReplace = this.isRoot && !isNull && collectionTypeName == null; // only replace if it is from a service operation which returns a collection of complex or primitive types if (shouldReplace) { var functionAnnotation = property.Annotations.OfType <FunctionAnnotation>().SingleOrDefault(); if (functionAnnotation != null) { var dataTypeAnnotation = property.Annotations.OfType <DataTypeAnnotation>().SingleOrDefault(); if (dataTypeAnnotation != null) { ExceptionUtilities.CheckObjectNotNull(dataTypeAnnotation.DataType, "DataType Annotation doesn't contain a DataType"); var collectionType = dataTypeAnnotation.DataType as CollectionDataType; if (collectionType != null) { return(collectionType.ElementDataType is ComplexDataType || collectionType.ElementDataType is PrimitiveDataType); } } } } return(false); }
private void PropertyEditorUpdate() { if (!Input.GetMouseButton(0)) { return; } if (cursorInfo.transform != null && UICamera.hoveredObject == null) { tile = cursorInfo.transform.GetComponent <Tile>(); if (tile != null) { if (chosenPropertyType.gameplayData.altitude != tile.node.terrain.staticData.altitude) { return; } if (tile.node.terrain.property == null) { PropertyInstance.Create(tile.node.terrain, chosenPropertyType); } else if (tile.node.terrain.property.type != chosenPropertyType) { PropertyInstance.Replace(tile.node.terrain.property, chosenPropertyType); } } } }
///-------------------------------------------------------------------------------- /// <summary>This method refreshes the view model.</summary> /// /// <param name="refreshChildren">Flag indicating whether children should be refreshed.</param> ///-------------------------------------------------------------------------------- public void Refresh(bool refreshChildren, int refreshLevel = 0) { if (refreshChildren == true || refreshLevel > 0) { } #region protected #endregion protected HasErrors = !PropertyInstance.IsValid; HasCustomizations = PropertyInstance.IsAutoUpdated == false || PropertyInstance.IsEmptyMetadata(PropertyInstance.ForwardInstance) == false || ChildrenHaveAnyCustomizations(); if (HasCustomizations == false && PropertyInstance.ReverseInstance != null) { // remove customizations if solely due to child customizations no longer present PropertyInstance.IsAutoUpdated = true; PropertyInstance.SpecSourceName = PropertyInstance.ReverseInstance.SpecSourceName; PropertyInstance.ResetModified(PropertyInstance.ReverseInstance.IsModified); PropertyInstance.ResetLoaded(PropertyInstance.ReverseInstance.IsLoaded); if (!PropertyInstance.IsIdenticalMetadata(PropertyInstance.ReverseInstance)) { HasCustomizations = true; PropertyInstance.IsAutoUpdated = false; } } if (HasCustomizations == false) { // clear customizations PropertyInstance.ForwardInstance = null; PropertyInstance.ReverseInstance = null; PropertyInstance.IsAutoUpdated = true; } OnPropertyChanged("Items"); OnPropertyChanged("HasCustomizations"); OnPropertyChanged("HasErrors"); }
public static NodeInstance CreateNodeInstanceFromTemplate(NodeTemplate template) { var instance = new NodeInstance { ObjId = Guid.NewGuid(), Name = template.Name, Description = template.Description, This2NodeTemplateNavigation = template, This2NodeTemplate = template.ObjId, IsWriteable = template.IsWriteable, IsReadable = template.IsReadable }; foreach (var prop in template.PropertyTemplate) { var propertyInstance = new PropertyInstance { ObjId = Guid.NewGuid(), This2NodeInstanceNavigation = instance, This2PropertyTemplateNavigation = prop, This2PropertyTemplate = prop.ObjId, Value = prop.DefaultValue }; instance.PropertyInstance.Add(propertyInstance); } return(instance); }
public override void VisitEnd() { PropertyInstance p_valueHolderContainerTemplate = GetValueHolderContainerTemplatePI(this); PropertyInstance p_relationMembers = ImplementAssignedReadonlyProperty("__RelationMembers", metaData.RelationMembers); PropertyInstance p_targetCache = ImplementTargetCache(p_valueHolderContainerTemplate); if (!EmbeddedEnhancementHint.HasMemberPath(State.Context)) { PropertyInstance p_valueHolderContainerEntry = ImplementAssignedReadonlyProperty("ValueHolderContainerEntry", new ValueHolderContainerEntryValueResolver(valueHolderContainerHelper)); ImplementGetState(p_valueHolderContainerTemplate, p_valueHolderContainerEntry); ImplementSetInitPending(p_valueHolderContainerTemplate, p_valueHolderContainerEntry); ImplementIsInitialized(p_valueHolderContainerTemplate, p_valueHolderContainerEntry); ImplementGetObjRefs(p_valueHolderContainerTemplate, p_valueHolderContainerEntry); ImplementSetObjRefs(p_valueHolderContainerTemplate, p_valueHolderContainerEntry); ImplementGetValueDirect(p_valueHolderContainerTemplate, p_valueHolderContainerEntry); ImplementSetValueDirect(p_valueHolderContainerTemplate, p_valueHolderContainerEntry); ImplementSetUninitialized(p_valueHolderContainerTemplate, p_valueHolderContainerEntry); } ImplementValueHolderCode(p_valueHolderContainerTemplate, p_targetCache, p_relationMembers); ImplementConstructors(); base.VisitEnd(); }
public virtual void CallThisSetter(PropertyInstance property, Script script) { if (mv != null) { mv.CallThisSetter(property, script); } }
public void SetUp() { var property = new Property( "property name", "property type", new VariablePropertyValue( "language code", new[] { new PropertyVariant("en", new FixedPropertyValue("English"), true), new PropertyVariant( "fr", new VariablePropertyValue( "country code", new[] { new PropertyVariant("fr", new FixedPropertyValue("French French")), new PropertyVariant("ca", new FixedPropertyValue("French Canadian")) })) })); var buildContext = new BuildData(new[] { new ContextItem("country code", "ca"), new ContextItem("language code", "fr") }); this.propertyInstance = property.Build(buildContext); }
public override void VisitEnd() { PropertyInstance p_toBeCreated = ImplementToBeCreated(template_p_toBeCreated); PropertyInstance p_toBeUpdated = ImplementToBeUpdated(); // ToBeDeleted FieldInstance f_toBeDeleted = ImplementField(new FieldInstance(FieldAttributes.Private, "toBeDeleted", template_p_toBeDeleted.PropertyType)); PropertyInstance p_toBeDeleted = ImplementProperty(template_p_toBeDeleted, delegate(IMethodVisitor mv) { mv.GetThisField(f_toBeDeleted); mv.ReturnValue(); }, delegate(IMethodVisitor mv) { mv.PutThisField(f_toBeDeleted, delegate(IMethodVisitor mv2) { mv2.LoadArg(0); }); mv.ReturnValue(); }); p_toBeDeleted.AddAnnotation(c_ignoreToBeUpdated); ImplementHasPendingChanges(p_hasPendingChanges, p_toBeUpdated, p_toBeCreated, p_toBeDeleted); base.VisitEnd(); }
public static void CacheModificationInternalUpdate(PropertyInstance p_cacheModification, IMethodVisitor mg, Script script) { LocalVariableInfo loc_cacheModification = mg.NewLocal <ICacheModification>(); LocalVariableInfo loc_oldActive = mg.NewLocal <bool>(); // ICacheModification cacheModification = this.cacheModification; mg.CallThisGetter(p_cacheModification); mg.StoreLocal(loc_cacheModification); // boolean oldInternalUpdate = cacheModification.isInternalUpdate(); mg.LoadLocal(loc_cacheModification); mg.InvokeInterface(new MethodInstance(null, typeof(ICacheModification), typeof(bool), "get_InternalUpdate")); mg.StoreLocal(loc_oldActive); // callModificationInternalUpdate(cacheModification, oldInternalUpdate, true) mg.LoadLocal(loc_cacheModification); mg.LoadLocal(loc_oldActive); mg.Push(true); mg.InvokeStatic(m_callCacheModificationInternalUpdate); mg.TryFinally(script, delegate(IMethodVisitor mv2) { // callModificationInternalUpdate(cacheModification, oldInternalUpdate, false) mv2.LoadLocal(loc_cacheModification); mv2.LoadLocal(loc_oldActive); mv2.Push(false); mv2.InvokeStatic(m_callCacheModificationInternalUpdate); }); }
/// <summary> /// Sets the expected property for the top-level property instance. /// </summary> /// <param name="property">The property instance to set the expected property for.</param> /// <param name="owningType">The type owning the expected property.</param> /// <param name="expectedPropertyName">The name of the property to set as the expected property.</param> /// <returns>The <paramref name="property"/> after its expected property was set.</returns> public static PropertyInstance ExpectedProperty( this PropertyInstance property, NamedStructuralType owningType, string expectedPropertyName) { ExceptionUtilities.CheckArgumentNotNull(property, "property"); ExceptionUtilities.CheckArgumentNotNull(owningType, "owningType"); ExceptionUtilities.CheckStringArgumentIsNotNullOrEmpty(expectedPropertyName, "expectedPropertyName"); ExpectedTypeODataPayloadElementAnnotation annotation = AddExpectedTypeAnnotation(property); annotation.OwningType = owningType; MemberProperty memberProperty = owningType.GetProperty(expectedPropertyName); if (memberProperty != null) { annotation.MemberProperty = memberProperty; annotation.ExpectedType = memberProperty.PropertyType; } else { ExceptionUtilities.Assert(owningType.IsOpen, "For non-declared properties the owning type must be open."); annotation.OpenMemberPropertyName = expectedPropertyName; } return(property); }
/** * public boolean hasPendingChanges() { return isToBeUpdated() || isToBeCreated() || isToBeDeleted(); } */ protected void ImplementHasPendingChanges(PropertyInstance p_hasPendingChanges, PropertyInstance p_ToBeUpdated, PropertyInstance p_ToBeCreated, PropertyInstance p_ToBeDeleted) { IMethodVisitor mg = VisitMethod(p_hasPendingChanges.Getter); p_hasPendingChanges = PropertyInstance.FindByTemplate(p_hasPendingChanges, false); p_hasPendingChanges.AddAnnotation(c_ignoreToBeUpdated); p_hasPendingChanges.AddAnnotation(c_fireThisOPC, p_ToBeCreated.Name); p_hasPendingChanges.AddAnnotation(c_fireThisOPC, p_ToBeUpdated.Name); p_hasPendingChanges.AddAnnotation(c_fireThisOPC, p_ToBeDeleted.Name); Label trueLabel = mg.NewLabel(); mg.LoadThis(); mg.InvokeVirtual(p_ToBeUpdated.Getter); mg.IfZCmp(CompareOperator.NE, trueLabel); mg.LoadThis(); mg.InvokeVirtual(p_ToBeCreated.Getter); mg.IfZCmp(CompareOperator.NE, trueLabel); mg.LoadThis(); mg.InvokeVirtual(p_ToBeDeleted.Getter); mg.IfZCmp(CompareOperator.NE, trueLabel); mg.Push(false); mg.ReturnValue(); mg.Mark(trueLabel); mg.Push(true); mg.ReturnValue(); mg.EndMethod(); }
protected Script CreateEmbeddedObjectInstance(PropertyInstance p_embeddedMemberTemplate, Member firstMember, String memberPath) { PropertyInstance property = PropertyInstance.FindByTemplate(firstMember.Name, firstMember.RealType, false); PropertyInstance p_rootEntity = memberPathSplit == null ? null : EmbeddedTypeVisitor.GetRootEntityProperty(this); return(delegate(IMethodVisitor mg2) { mg2.CallThisSetter(property, delegate(IMethodVisitor mg) { // Object p_embeddedMemberTemplate.createEmbeddedObject(Class<?> embeddedType, Class<?> entityType, Object parentObject, String // memberPath) mg.CallThisGetter(p_embeddedMemberTemplate); mg.Push(firstMember.RealType); // embeddedType if (p_rootEntity != null) { mg.CallThisGetter(p_rootEntity); mg.CheckCast(EntityMetaDataHolderVisitor.m_template_getEntityMetaData.Owner); mg.InvokeInterface(EntityMetaDataHolderVisitor.m_template_getEntityMetaData); } else { mg.CallThisGetter(EntityMetaDataHolderVisitor.m_template_getEntityMetaData); } mg.InvokeInterface(new MethodInstance(null, typeof(IEntityMetaData), typeof(Type), "get_EnhancedType")); mg.LoadThis(); // parentObject mg.Push(memberPath); mg.InvokeVirtual(template_m_createEmbeddedObject); mg.CheckCast(firstMember.RealType); }); }); }
protected void ImplementToStringMethod(PropertyInstance p_entityEqualsTemplate) { { MethodInstance methodTemplate = new MethodInstance(null, typeof(Object), typeof(String), "ToString"); MethodInstance method = MethodInstance.FindByTemplate(methodTemplate, true); if (NewType.GetType(typeof(Object)).Equals(method.Owner) || method.Access.HasFlag(MethodAttributes.Abstract)) { IMethodVisitor mg = VisitMethod(methodTemplate); mg.CallThisGetter(p_entityEqualsTemplate); mg.LoadThis(); mg.LoadThis(); mg.InvokeVirtual(entityEquals_toString_Obj); mg.ReturnValue(); mg.EndMethod(); } } { MethodInstance methodTemplate = new MethodInstance(null, typeof(IPrintable), typeof(void), "ToString", typeof(StringBuilder)); MethodInstance method = MethodInstance.FindByTemplate(methodTemplate, true); if (method == null || method.Access.HasFlag(MethodAttributes.Abstract)) { IMethodVisitor mg = VisitMethod(methodTemplate); mg.CallThisGetter(p_entityEqualsTemplate); mg.LoadThis(); mg.LoadArgs(); mg.InvokeVirtual(entityEquals_toString_Printable); mg.ReturnValue(); mg.EndMethod(); } } }
/// <summary> /// Helper method for visiting null or empty properties /// </summary> /// <param name="payloadElement">The property to visit</param> protected override void VisitEmptyOrNullProperty(PropertyInstance payloadElement) { base.VisitEmptyOrNullProperty(payloadElement); var property = this.MetadataStack.Peek() as MemberProperty; var navigation = this.MetadataStack.Peek() as NavigationProperty; if (property != null) { ExceptionUtilities.Assert(payloadElement.Name == property.Name, "Property name mismatch"); payloadElement.AddAnnotationIfNotExist(new MemberPropertyAnnotation() { Property = property }); } else { ExceptionUtilities.CheckObjectNotNull(navigation, "Expected property or navigation, got '{0}'", this.MetadataStack.Peek()); ExceptionUtilities.Assert(payloadElement.Name == navigation.Name, "Property name mismatch"); payloadElement.AddAnnotationIfNotExist(new NavigationPropertyAnnotation() { Property = navigation }); var emptyCollection = payloadElement as EmptyCollectionProperty; if (emptyCollection != null && emptyCollection.Value != null) { emptyCollection.Value.AddAnnotationIfNotExist(new EntitySetAnnotation() { EntitySet = this.CurrentEntitySet.GetRelatedEntitySet(navigation) }); } } }
private void VisitProperty(PropertyInstance payloadElement, ODataPayloadElement value, Action action) { ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement"); try { var currentType = this.typeStack.Peek(); ExceptionUtilities.CheckObjectNotNull(currentType, "Current type should not be null"); var propertyInfo = currentType.GetProperty(payloadElement.Name); ExceptionUtilities.CheckObjectNotNull(propertyInfo, "Could not find property '{0}' on type '{1}'", payloadElement.Name, currentType); var genericCollectionType = propertyInfo.PropertyType.GetInterfaces().Where(t => t.IsGenericType()).SingleOrDefault(t => typeof(ICollection <>) == t.GetGenericTypeDefinition()); if (genericCollectionType != null) { this.typeStack.Push(genericCollectionType.GetGenericArguments()[0]); } else { this.typeStack.Push(propertyInfo.PropertyType); } base.VisitProperty(payloadElement, value); if (action != null) { action(); } } finally { this.typeStack.Pop(); } }
public virtual void CallThisGetter(PropertyInstance property) { if (mv != null) { mv.CallThisGetter(property); } }
public PropertyInstance GetProperty(String propertyName, NewType propertyType) { PropertyInstance pi = implementedProperties.Get(new PropertyKey(propertyName, propertyType)); if (pi != null) { return(pi); } BindingFlags flags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; PropertyInfo propertyInfo = propertyType != null?CurrentType.GetProperty(propertyName, flags, null, propertyType.Type, Type.EmptyTypes, new ParameterModifier[0]) : CurrentType.GetProperty(propertyName, flags); if (propertyInfo != null) { pi = new PropertyInstance(propertyInfo); } if (pi == null) { MethodInfo m_get = CurrentType.GetMethod("Get" + propertyName, flags); if (m_get == null) { m_get = CurrentType.GetMethod("get" + propertyName, flags); } MethodInfo m_set = CurrentType.GetMethod("Set" + propertyName, flags); if (m_set == null) { m_set = CurrentType.GetMethod("set" + propertyName, flags); } if (m_get != null || m_set != null) { pi = new PropertyInstance(propertyName, m_get != null ? new MethodInstance(m_get) : null, m_set != null ? new MethodInstance(m_set) : null); } } return(pi); }
public void PropertyImplemented(PropertyInstance property) { if (!implementedProperties.PutIfNotExists(new PropertyKey(property.Name, property.PropertyType), property)) { throw new Exception("Property already implemented: " + property); } }
/// <summary> /// Creates a new Propertyinstance. /// </summary> /// <param name="terrainInstance">the terrain instance this property will be attached to</param> /// <param name="propertyType"></param> /// <returns></returns> public static PropertyInstance Create(TerrainInstance terrainInstance, PropertyType propertyType) { if (terrainInstance.property != null) { throw new System.Exception("PropertyInstance.Create() was called on a terrainInstance with a non-null property. Use PropertyInstance.Replace() instead."); } //Debug.Log( terrainType.prefabs.block ); GameObject go = GameObject.Instantiate( propertyType.prefab, terrainInstance.node.position, Quaternion.identity) as GameObject; PropertyInstance propertyInstance = go.AddComponent <PropertyInstance>(); propertyInstance.terrainInstance = terrainInstance; terrainInstance.property = propertyInstance; propertyInstance.type = propertyType; propertyInstance.transform.parent = terrainInstance.transform; //nobody cares //go.name = propertyType.prefab.name; return(propertyInstance); }
private void PopulatePropertiesFromPaths(ComplexInstance instance, IEnumerable <MemberProperty> properties, string propertyPath, IEnumerable <NamedValue> namedValues) { ExceptionUtilities.CheckArgumentNotNull(instance, "instance"); ExceptionUtilities.CheckArgumentNotNull(properties, "properties"); ExceptionUtilities.CheckArgumentNotNull(namedValues, "namedValues"); foreach (MemberProperty property in properties) { string childPropertyPath = property.Name; if (propertyPath != null) { childPropertyPath = propertyPath + "." + property.Name; } CollectionDataType collectionDataType = property.PropertyType as CollectionDataType; PrimitiveDataType primitiveDataType = property.PropertyType as PrimitiveDataType; if (primitiveDataType != null) { NamedValue memberPropertyNamedValue = namedValues.SingleOrDefault(nv => nv.Name == childPropertyPath); if (memberPropertyNamedValue != null) { instance.Add(this.PrimitiveProperty(property, memberPropertyNamedValue.Value)); } } else if (collectionDataType != null) { IEnumerable <NamedValue> bagNamedValues = namedValues.Where(nv => nv.Name.StartsWith(childPropertyPath + ".", StringComparison.Ordinal)).ToList(); if (bagNamedValues.Count() > 0) { this.PopulateMultiValuePropertyFromPaths(instance, property, collectionDataType.ElementDataType, childPropertyPath, bagNamedValues); } else { this.PopulateCollectionPropertyWithNullOrEmpty(instance, property, childPropertyPath, namedValues); } } else { var complexDataType = property.PropertyType as ComplexDataType; ExceptionUtilities.CheckObjectNotNull(complexDataType, "Property '{0}' was not primitive, a collection, or complex", property.Name); IEnumerable <NamedValue> complexInstanceNamedValues = namedValues.Where(nv => nv.Name.StartsWith(childPropertyPath + ".", StringComparison.Ordinal)).ToList(); if (complexInstanceNamedValues.Count() > 0) { PropertyInstance memberPropertyInstance = this.ComplexProperty(property, childPropertyPath, complexInstanceNamedValues); instance.Add(memberPropertyInstance); } else { // Check for null case IEnumerable <NamedValue> exactMatches = namedValues.Where(nv => nv.Name == childPropertyPath).ToList(); ExceptionUtilities.Assert(exactMatches.Count() < 2, "Should only find at most one property path {0} when looking for null value", childPropertyPath); if (exactMatches.Count() == 1) { instance.Add(new ComplexProperty(property.Name, new ComplexInstance(complexDataType.Definition.FullName, true))); } } } } }
public PropertyInstance MultiValuePropertyEmptyOrNull(MemberProperty memberProperty, object value) { var bagPropertyType = memberProperty.PropertyType as CollectionDataType; ExceptionUtilities.CheckObjectNotNull(bagPropertyType, "Expected property to be a BagProperty instead its a '{0}'", memberProperty.PropertyType); DataType elementDataType = bagPropertyType.ElementDataType; if (value == null) { return(new NullPropertyInstance(memberProperty.Name, elementDataType.BuildMultiValueTypeName())); } else { ExceptionUtilities.Assert(value == EmptyData.Value, "value MUST be null or EmptyData.Value"); PropertyInstance collectionProperty = null; if (elementDataType is ComplexDataType) { collectionProperty = new ComplexMultiValueProperty(memberProperty.Name, new ComplexMultiValue(elementDataType.BuildMultiValueTypeName(), false)); } else { ExceptionUtilities.Assert(elementDataType is PrimitiveDataType, "DataType is not a PrimitiveDataType '{0}'", elementDataType); collectionProperty = new PrimitiveMultiValueProperty(memberProperty.Name, new PrimitiveMultiValue(elementDataType.BuildMultiValueTypeName(), false)); } // Add an empty one if specified to return(collectionProperty); } }
public override void VisitEnd() { PropertyInstance p_embeddedMemberTemplate = GetEmbeddedMemberTemplatePI(this); ImplementConstructor(p_embeddedMemberTemplate); base.VisitEnd(); }
protected void ImplementIEntityEqualsCode() { PropertyInstance p_entityEqualsTemplate = GetEntityEqualsTemplateProperty(this); ImplementEqualsMethod(p_entityEqualsTemplate); ImplementHashCodeMethod(p_entityEqualsTemplate); ImplementToStringMethod(p_entityEqualsTemplate); }
/// <summary> /// Normalizes the name of a property instance (JSON Light reports an empty name for top-level properties in requests). /// </summary> /// <param name="payloadElement">The property instance to normalize the name for.</param> private void NormalizePropertyName(PropertyInstance payloadElement) { if (this.IsRootElement(payloadElement)) { // NOTE: in JSON Light we report null property names. payloadElement.Name = null; } }
public virtual PropertyInstance HideFromDebug(PropertyInstance property) { if (cv != null) { return(cv.HideFromDebug(property)); } return(property); }
public virtual PropertyInstance HideFromDebug(PropertyInstance property) { if (HideFromDebugActive) { property.AddAnnotation(c_hideFromDebug, DebuggerBrowsableState.Never); } return(property); }
public bool Equals(PropertyInstance obj) { return Equals(obj.Value, this.Value); }