private void InitEmployees() { Employees = new List <Employee> { new Employee() { ID = 1, Name = "Name1", SkillSet = new List <Skill> { Skill.CSharp, Skill.Sql }, Gender = Gender.Female, AccessLevel = AccessLevel.Execute, FavoriteSports = new FavoriteSports() { LikeMost = Sport.Pingpong, Like = new List <Sport> { Sport.Pingpong, Sport.Basketball } } }, new Employee() { ID = 2, Name = "Name2", SkillSet = new List <Skill>(), Gender = Gender.Female, AccessLevel = AccessLevel.Read, FavoriteSports = new FavoriteSports() { LikeMost = Sport.Pingpong, Like = new List <Sport> { Sport.Pingpong, Sport.Basketball } } }, new Employee() { ID = 3, Name = "Name3", SkillSet = new List <Skill> { Skill.Web, Skill.Sql }, Gender = Gender.Female, AccessLevel = AccessLevel.Read | AccessLevel.Write, FavoriteSports = new FavoriteSports() { LikeMost = Sport.Pingpong | Sport.Basketball, Like = new List <Sport> { Sport.Pingpong, Sport.Basketball } } }, }; var instanceAnnot = new ODataInstanceAnnotationContainer(); instanceAnnot.AddResourceAnnotation("NS.Test2", 2); Employees[1].InstanceAnnotations = instanceAnnot; }
public static IODataInstanceAnnotationContainer GetAnnotationContainer(PropertyInfo propertyInfo, object resource) { IDelta delta = resource as IDelta; object value; if (delta != null) { delta.TryGetPropertyValue(propertyInfo.Name, out value); } else { value = propertyInfo.GetValue(resource); } IODataInstanceAnnotationContainer instanceAnnotationContainer = value as IODataInstanceAnnotationContainer; if (instanceAnnotationContainer == null) { try { if (propertyInfo.PropertyType == typeof(ODataInstanceAnnotationContainer) || propertyInfo.PropertyType == typeof(IODataInstanceAnnotationContainer)) { instanceAnnotationContainer = new ODataInstanceAnnotationContainer(); } else { instanceAnnotationContainer = Activator.CreateInstance(propertyInfo.PropertyType) as IODataInstanceAnnotationContainer; } if (delta != null) { delta.TrySetPropertyValue(propertyInfo.Name, instanceAnnotationContainer); } else { propertyInfo.SetValue(resource, instanceAnnotationContainer); } } catch (Exception ex) { throw new ODataException(Error.Format(SRResources.CannotCreateInstanceForProperty, propertyInfo.Name), ex); } } return(instanceAnnotationContainer); }