コード例 #1
0
        /// <summary>
        /// Get the name of the model on the left side of the relationship.
        /// </summary>
        /// <param name="schema"></param>
        /// <returns></returns>
        public static IEnumerable <RelationshipSettings> GetRelationshipSettings(this JsonSchema4 schema)
        {
            Object val = null;
            IEnumerable <RelationshipSettings> settings = null;

            if (schema.ExtensionData?.TryGetValue(RelatedToAttribute.Name, out val) == true)
            {
                settings = val as IEnumerable <RelationshipSettings>;
            }
            if (settings == null)
            {
                settings = new RelationshipSettings[0];
            }
            return(settings.Select(i =>
            {
                i.IsLeftModel = i.LeftModelName == schema.Title;
                return i;
            }));
        }
        public static Dictionary <String, Object> CopyExtensions(this RelationshipSettings attribute)
        {
            var dictionary = default(Dictionary <string, object>);

            if (attribute.OriginalPropertyDefinition != null)
            {
                if (attribute.OriginalPropertyDefinition.ExtensionData != null)
                {
                    dictionary = new Dictionary <string, object>(attribute.OriginalPropertyDefinition.ExtensionData);
                    if (attribute.OriginalPropertyDefinition.Type == JsonObjectType.Object && attribute.OriginalPropertyDefinition.ActualTypeSchema?.ExtensionData != null)
                    {
                        //If this is an object, add any properties from the "ActualTypeSchema" which often has extras
                        foreach (var item in attribute.OriginalPropertyDefinition.ActualTypeSchema.ExtensionData)
                        {
                            dictionary[item.Key] = item.Value;
                        }
                    }
                }
            }
            return(dictionary);
        }