| | 1 | | using Microsoft.Xrm.Sdk.Metadata; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Text; |
| | 5 | | using System.Linq; |
| | 6 | |
|
| | 7 | | namespace FakeXrmEasy.Extensions |
| | 8 | | { |
| | 9 | | public static class EntityMetadataExtensions |
| | 10 | | { |
| | 11 | | public static void SetAttributeCollection(this EntityMetadata entityMetadata, AttributeMetadata[] attributes) |
| 24 | 12 | | { |
| | 13 | | //AttributeMetadata is internal set in a sealed class so... just doing this |
| | 14 | |
|
| 24 | 15 | | entityMetadata.GetType().GetProperty("Attributes").SetValue(entityMetadata, attributes, null); |
| 24 | 16 | | } |
| | 17 | |
|
| | 18 | | public static void SetAttribute(this EntityMetadata entityMetadata, AttributeMetadata attribute) |
| 38 | 19 | | { |
| 38 | 20 | | var currentAttributes = entityMetadata.Attributes; |
| 38 | 21 | | if (currentAttributes == null) |
| 14 | 22 | | { |
| 14 | 23 | | currentAttributes = new AttributeMetadata[0]; |
| 14 | 24 | | } |
| 62 | 25 | | var newAttributesList = currentAttributes.Where(a => a.LogicalName != attribute.LogicalName).ToList(); |
| 38 | 26 | | newAttributesList.Add(attribute); |
| 38 | 27 | | var newAttributesArray = newAttributesList.ToArray(); |
| | 28 | |
|
| 38 | 29 | | entityMetadata.GetType().GetProperty("Attributes").SetValue(entityMetadata, newAttributesArray, null); |
| 38 | 30 | | } |
| | 31 | |
|
| | 32 | | public static void SetAttributeCollection(this EntityMetadata entityMetadata, IEnumerable<AttributeMetadata> att |
| 36 | 33 | | { |
| 36 | 34 | | entityMetadata.GetType().GetProperty("Attributes").SetValue(entityMetadata, attributes.ToList().ToArray(), n |
| 36 | 35 | | } |
| | 36 | |
|
| | 37 | | public static void SetSealedPropertyValue(this EntityMetadata entityMetadata, string sPropertyName, object value |
| 8497 | 38 | | { |
| 8497 | 39 | | entityMetadata.GetType().GetProperty(sPropertyName).SetValue(entityMetadata, value, null); |
| 8497 | 40 | | } |
| | 41 | |
|
| | 42 | | public static void SetSealedPropertyValue(this AttributeMetadata attributeMetadata, string sPropertyName, object |
| 3625 | 43 | | { |
| 3625 | 44 | | attributeMetadata.GetType().GetProperty(sPropertyName).SetValue(attributeMetadata, value, null); |
| 3625 | 45 | | } |
| | 46 | |
|
| | 47 | | public static void SetSealedPropertyValue(this ManyToManyRelationshipMetadata manyToManyRelationshipMetadata, st |
| 6 | 48 | | { |
| 6 | 49 | | manyToManyRelationshipMetadata.GetType().GetProperty(sPropertyName).SetValue(manyToManyRelationshipMetadata, |
| 6 | 50 | | } |
| | 51 | |
|
| | 52 | | public static void SetSealedPropertyValue(this OneToManyRelationshipMetadata oneToManyRelationshipMetadata, stri |
| 6 | 53 | | { |
| 6 | 54 | | oneToManyRelationshipMetadata.GetType().GetProperty(sPropertyName).SetValue(oneToManyRelationshipMetadata, v |
| 6 | 55 | | } |
| | 56 | | } |
| | 57 | | } |