public static void Write(this BinaryWriter writer, RelationshipMapping mapping) { writer.Write(mapping.NumEntries); writer.Write(mapping.MinId); writer.Write(mapping.MaxId); for (int i = 0; i < mapping.NumEntries; i++) { writer.Write(mapping.Entries[i]); } }
public static RelationshipMapping ReadRelationshipMapping(this BinaryReader reader) { var mapping = new RelationshipMapping(); mapping.NumEntries = reader.ReadUInt32(); mapping.MinId = reader.ReadUInt32(); mapping.MaxId = reader.ReadUInt32(); mapping.Entries = new RelationshipEntry[mapping.NumEntries]; for (int i = 0; i < mapping.NumEntries; i++) { mapping.Entries[i] = reader.ReadRelationshipEntry(); } return(mapping); }
private IConfiguration CreateConfiguration() { var mapping = new ResourceMapping <SampleClass, DummyController>(c => c.Id); mapping.ResourceType = "sampleClasses"; mapping.AddPropertyGetter("someValue", c => c.SomeValue); mapping.AddPropertyGetter("date", c => c.DateTime); var mappingWithMeta = new ResourceMapping <SampleClassWithObjectMetadata, DummyController>(c => c.Id); mappingWithMeta.ResourceType = "sampleClassesWithMeta"; mappingWithMeta.AddPropertyGetter("someValue", c => c.SomeValue); var mappingWithRelationshipMeta = new ResourceMapping <SampleClassWithRelationshipMetadata, DummyController>(c => c.Id); mappingWithRelationshipMeta.ResourceType = "sampleClassWithRelationshipMetadata"; mappingWithRelationshipMeta.AddPropertyGetter("someValue", c => c.SomeValue); var mappingWithRelatedClassesWithRelationshipMeta = new ResourceMapping <SampleClassWithRelatedClassesWithRelationshipMetadata, DummyController>(c => c.Id); mappingWithRelatedClassesWithRelationshipMeta.ResourceType = "sampleClassWithRelatedClassesWithRelationshipMetadata"; var relMapSingle = new RelationshipMapping <SampleClassWithRelatedClassesWithRelationshipMetadata, SampleClassWithRelationshipMetadata>(); relMapSingle.RelationshipName = "relatedObject"; relMapSingle.IsCollection = false; relMapSingle.RelatedProperty = new PropertyHandle <SampleClassWithRelatedClassesWithRelationshipMetadata, SampleClassWithRelationshipMetadata>(o => o.RelatedObject); relMapSingle.ResourceGetter = o => o.RelatedObject; relMapSingle.ResourceMapping = mappingWithRelationshipMeta; mappingWithRelatedClassesWithRelationshipMeta.Relationships.Add(relMapSingle); var relMapCollection = new RelationshipMapping <SampleClassWithRelatedClassesWithRelationshipMetadata, IList <SampleClassWithRelationshipMetadata> >(); relMapCollection.RelationshipName = "relatedObjects"; relMapCollection.IsCollection = true; relMapCollection.RelatedProperty = new PropertyHandle <SampleClassWithRelatedClassesWithRelationshipMetadata, IList <SampleClassWithRelationshipMetadata> >(o => o.RelatedObjects); relMapCollection.ResourceGetter = o => o.RelatedObjects; relMapCollection.ResourceMapping = mappingWithRelationshipMeta; mappingWithRelatedClassesWithRelationshipMeta.Relationships.Add(relMapCollection); var config = new NJsonApi.Configuration(); config.AddMapping(mapping); config.AddMapping(mappingWithMeta); config.AddMapping(mappingWithRelationshipMeta); config.AddMapping(mappingWithRelatedClassesWithRelationshipMeta); return(config); }
private IConfiguration CreateConfiguration() { var conf = new NJsonApi.Configuration(); var sampleClassMapping = new ResourceMapping <SampleClass, DummyController>(c => c.Id); sampleClassMapping.ResourceType = "sampleClasses"; sampleClassMapping.AddPropertyGetter("someValue", c => c.SomeValue); sampleClassMapping.AddPropertyGetter("date", c => c.DateTime); sampleClassMapping.AddPropertyGetter("complexAttribute", c => c.ComplexAttribute); sampleClassMapping.AddPropertyGetter("listAttribute", c => c.ListAttribute); var nestedClassMapping = new ResourceMapping <NestedClass, DummyController>(c => c.Id); nestedClassMapping.ResourceType = "nestedClasses"; nestedClassMapping.AddPropertyGetter("nestedText", c => c.NestedText); var deeplyNestedMapping = new ResourceMapping <DeeplyNestedClass, DummyController>(c => c.Id); deeplyNestedMapping.ResourceType = "deeplyNestedClasses"; deeplyNestedMapping.AddPropertyGetter("value", c => c.Value); var linkMapping = new RelationshipMapping <SampleClass, NestedClass>() { IsCollection = true, RelationshipName = "nestedValues", ResourceMapping = nestedClassMapping, ResourceGetter = c => c.NestedClass, }; var deepLinkMapping = new RelationshipMapping <NestedClass, DeeplyNestedClass>() { RelationshipName = "deeplyNestedValues", ResourceMapping = deeplyNestedMapping, ResourceGetter = c => c.DeeplyNestedClass }; sampleClassMapping.Relationships.Add(linkMapping); nestedClassMapping.Relationships.Add(deepLinkMapping); conf.AddMapping(sampleClassMapping); conf.AddMapping(nestedClassMapping); conf.AddMapping(deeplyNestedMapping); return(conf); }
private IConfiguration CreateConfiguration() { var conf = new NJsonApi.Configuration(); var sampleClassMapping = new ResourceMapping<SampleClass, DummyController>(c => c.Id, "http://sampleClass/{id}"); sampleClassMapping.ResourceType = "sampleClasses"; sampleClassMapping.AddPropertyGetter("someValue", c => c.SomeValue); sampleClassMapping.AddPropertyGetter("date", c => c.DateTime); var nestedClassMapping = new ResourceMapping<NestedClass, DummyController>(c => c.Id, "http://nestedclass/{id}"); nestedClassMapping.ResourceType = "nestedClasses"; nestedClassMapping.AddPropertyGetter("nestedText", c => c.NestedText); var deeplyNestedMapping = new ResourceMapping<DeeplyNestedClass, DummyController>(c => c.Id, "http://deep/{id}"); deeplyNestedMapping.ResourceType = "deeplyNestedClasses"; deeplyNestedMapping.AddPropertyGetter("value", c => c.Value); var linkMapping = new RelationshipMapping<SampleClass, NestedClass>() { IsCollection = true, RelationshipName = "nestedValues", ResourceMapping = nestedClassMapping, ResourceGetter = c => c.NestedClass, }; var deepLinkMapping = new RelationshipMapping<NestedClass, DeeplyNestedClass>() { RelationshipName = "deeplyNestedValues", ResourceMapping = deeplyNestedMapping, ResourceGetter = c => c.DeeplyNestedClass }; sampleClassMapping.Relationships.Add(linkMapping); nestedClassMapping.Relationships.Add(deepLinkMapping); conf.AddMapping(sampleClassMapping); conf.AddMapping(nestedClassMapping); conf.AddMapping(deeplyNestedMapping); return conf; }