Ejemplo n.º 1
0
 private static void SetUri <T, TId>(this OdataObject <T, TId> obj, string leftPartOfUrl, UriKind uriKind, bool addIdToUrl)
 {
     if (!string.IsNullOrWhiteSpace(leftPartOfUrl))
     {
         obj.Uri = addIdToUrl
                 ? new Uri(string.Format(ObjectUrl, leftPartOfUrl, obj.Id), uriKind)
                 : new Uri(leftPartOfUrl, uriKind);
     }
 }
Ejemplo n.º 2
0
 internal static void AddProperty <T, TId>(this OdataObject <T, TId> obj, string prop)
 {
     obj.PropertyUris.Add(
         new OdataUri
     {
         PropertyName = prop,
         Uri          = new Uri("/" + prop, UriKind.Relative)
     }
         );
 }
Ejemplo n.º 3
0
 internal static void AddPropertyUris <T, TId>(this OdataObject <T, TId> obj, string[] properties)
 {
     if (properties != null)
     {
         foreach (var prop in properties)
         {
             obj.AddProperty(prop);
         }
     }
 }
Ejemplo n.º 4
0
        public static OdataObject <T, TId> AsOdata <T, TId>(this T t, string leftPartOfUrl, bool addIdToUrl, UriKind uriKind = UriKind.Relative, params string[] properties)
        {
            var obj = new OdataObject <T, TId> {
                Object = t, PropertyUris = new List <OdataUri>()
            };

            obj.SetUri(leftPartOfUrl, uriKind, addIdToUrl);
            // Uncomment below if we decide to publish all Entity property uris
            //if (properties == null || properties.Length == 0)
            //    properties = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => !p.CustomAttributes.Any(a => a.AttributeType == typeof(IgnoreDataMemberAttribute)))?.Select(p=>p.Name).ToArray();
            obj.AddPropertyUris(properties);
            return(obj);
        }
Ejemplo n.º 5
0
        public static OdataObject ToOdataObject(this OdataObject <JRaw, string> obj)
        {
            if (obj == null)
            {
                return(null);
            }
            var retObj = new OdataObject();

            retObj.Id                      = obj.Id;
            retObj.IdProperty              = obj.IdProperty;
            retObj.Object                  = obj.Object;
            retObj.PropertyUris            = obj.PropertyUris;
            retObj.RelatedEntityCollection = obj.RelatedEntityCollection;
            retObj.Uri                     = obj.Uri;
            return(retObj);
        }
Ejemplo n.º 6
0
 public static RelatedEntity AsRelatedEntity(this OdataObject <JRaw, string> o, RelatedEntity re = null)
 {
     if (o == null)
     {
         return(null);
     }
     re                         = re ?? new RelatedEntity();
     re.Id                      = o.Id?.ToString();
     re.IdProperty              = o.IdProperty;
     re.Object                  = o.Object;
     re.Parent                  = re.Parent;
     re.PropertyUris            = o.PropertyUris;
     re.RelatedEntityCollection = o.RelatedEntityCollection;
     re.Uri                     = o.Uri;
     return(re);
 }
Ejemplo n.º 7
0
        public static OdataObject <TEntity, TId> ToOdataObject <TEntity, TId>(this OdataObject <JRaw, string> obj)
            where TId : IComparable <TId>, IComparable, IEquatable <TId>
        {
            if (obj == null)
            {
                return(null);
            }
            var retObj = new OdataObject <TEntity, TId>();

            retObj.Id                      = obj.Id.To <TId>();
            retObj.IdProperty              = obj.IdProperty;
            retObj.Object                  = JsonConvert.DeserializeObject <TEntity>(obj.Object.ToString());
            retObj.PropertyUris            = obj.PropertyUris;
            retObj.RelatedEntityCollection = obj.RelatedEntityCollection;
            retObj.Uri                     = obj.Uri;
            return(retObj);
        }
Ejemplo n.º 8
0
        public static RelatedEntity AsRelatedEntity <TEntity, TId>(this OdataObject <TEntity, TId> obj, RelatedEntity re = null)
        {
            if (obj == null)
            {
                return(null);
            }
            JRaw rawObj = obj.Object == null ? null : new JRaw(JsonConvert.SerializeObject(obj.Object));

            re                         = re ?? new RelatedEntity();
            re.Id                      = obj.Id?.ToString();
            re.IdProperty              = obj.IdProperty;
            re.Object                  = rawObj;
            re.Parent                  = re.Parent;
            re.PropertyUris            = obj.PropertyUris;
            re.RelatedEntityCollection = obj.RelatedEntityCollection;
            re.Uri                     = obj.Uri;
            return(re);
        }
Ejemplo n.º 9
0
 public RelatedEntityOneToMany(string relatedIdProperty, OdataObject obj) : this(relatedIdProperty)
 {
     obj.AsRelatedEntity(this);
 }
Ejemplo n.º 10
0
 public bool Remove(OdataObject <TEntity, TId> item) => Entities.Remove(item);
Ejemplo n.º 11
0
 public bool Contains(OdataObject <TEntity, TId> item) => Entities.Contains(item);
Ejemplo n.º 12
0
 public void Insert(int index, OdataObject <TEntity, TId> item)
 {
     Entities.Insert(index, item);
     item.Parent = this;
 }
Ejemplo n.º 13
0
 public int IndexOf(OdataObject <TEntity, TId> item) => Entities.IndexOf(item);
Ejemplo n.º 14
0
 public void Add(OdataObject <TEntity, TId> item)
 {
     Entities.Add(item);
     item.Parent = this;
 }