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); } }
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) } ); }
internal static void AddPropertyUris <T, TId>(this OdataObject <T, TId> obj, string[] properties) { if (properties != null) { foreach (var prop in properties) { obj.AddProperty(prop); } } }
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); }
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); }
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); }
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); }
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); }
public RelatedEntityOneToMany(string relatedIdProperty, OdataObject obj) : this(relatedIdProperty) { obj.AsRelatedEntity(this); }
public bool Remove(OdataObject <TEntity, TId> item) => Entities.Remove(item);
public bool Contains(OdataObject <TEntity, TId> item) => Entities.Contains(item);
public void Insert(int index, OdataObject <TEntity, TId> item) { Entities.Insert(index, item); item.Parent = this; }
public int IndexOf(OdataObject <TEntity, TId> item) => Entities.IndexOf(item);
public void Add(OdataObject <TEntity, TId> item) { Entities.Add(item); item.Parent = this; }