Git Product home page Git Product logo

mxtires.microdata's Introduction

MXTires.Microdata

MXTires.Microdata is framework to correspond schema.org object types to .Net classes with conversion to JSON

Prerequisites

Visual Studio 2008 or higher NuGet

Code example of defining a Product:

https://schema.org/Product

        public void SimpleProduct()
        {
            var product = new Product()
            {
                Name = "T3 REPLICA NISSAN ALTIMA, MAXIMA (PAINTED/SILVER)",
            };
            Review review1 = new Review() { Name = "Review1", ReviewRating = new Rating() { RatingValue = "5" }, ReviewBody = "Best product ever!", Author = new Person() { Name = "Some Guy" } };
            Review review2 = new Review() { Name = "Review2",  ReviewRating = new Rating() { RatingValue = "4" }, ReviewBody = "I've seen better...", Author = new Person() { Name = "Other Guy" } };
            product.Reviews = new List<Review> { review1, review2 };
            System.Diagnostics.Debug.Write(product.ToJson());
        }

Code example of defining an Event:

https://schema.org/Event

        public void EventTest()
        {
            var baseEvent = new Event();
            baseEvent.Attendee = new Person();
            System.Diagnostics.Debug.WriteLine(baseEvent.ToIndentedJson());
        
        }

Code example for image:

        [TestMethod]
        public void TestImageObject()
        {
            var blogPosting = new BlogPosting();
            blogPosting.Image = new ImageObject()
            {
                Url = "http://whatever.com/image.png",
                Width = new QuantitativeValue() { Value = 500 },
                Height = new QuantitativeValue() { Value = 500 }
            };

            System.Diagnostics.Debug.Write(blogPosting.ToIndentedJson());
        }

Output:

<script type="application/ld+json">{
  "image": {
    "height": {
      "value": 500.0,
      "@context": "http://schema.org",
      "@type": "QuantitativeValue"
    },
    "width": {
      "value": 500.0,
      "@context": "http://schema.org",
      "@type": "QuantitativeValue"
    },
    "url": "http://whatever.com/image.png",
    "@context": "http://schema.org",
    "@type": "ImageObject"
  },
  "@context": "http://schema.org",
  "@type": "BlogPosting"
}</script>

Code example with extentions:

        public void TestAtlas()
        {
            var atlas = new Atlas();
            atlas.Context = new List<object>() { "http://schema.org", new Extentions.BibNameSpace(), };
            atlas.Name = "Atlas of the world.";
            System.Diagnostics.Debug.WriteLine(atlas.ToIndentedJson());
        }

Output:

<script type="application/ld+json">{
  "name": "Atlas of the world.",
  "@context": [
    "http://schema.org",
    {
      "bib": "http://bib.schema.org"
    }
  ],
  "@type": "Atlas"
}</script>

Dependencies

Newtonsoft.Json (>= 13.0.3)

License

1010Tires.com. License - License.md

mxtires.microdata's People

Contributors

dandiplo avatar dependabot[bot] avatar git4pras avatar idenys avatar mizzos avatar mortenbock avatar oleksandrk-adorama avatar robertmuehsig avatar stefanochiodino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mxtires.microdata's Issues

cannot add multiple performers to event

Probably a schema.org problem but I don't understand if, or how, it is possible to add multiple performers to an event.
In the class event property performer it says :
/// Organization or Person A performer at the event—for example, a presenter, musician, musical group or actor. Supersedes performers.

But what does "Supersedes performers" mean ? There isn't a property "Performers" so how can multiple performers be added ? For example Siegfried & Roy . #tosoon

The same is true for Attendee/Attendees.

Thanx

Exception when non default contract resolver is used

When serializing to Json, an exception is thrown if the default contract resolver is not used.

Code:

Newtonsoft.Json.JsonConvert.DefaultSettings = () => new JsonSerializerSettings{
	ContractResolver = new CamelCasePropertyNamesContractResolver()
};

Review r = new Review {
	Comment = "fdsdf"
};

r.ToIndentedJson().Dump();

Exception:
A member with the name 'comment' already exists on 'MXTires.Microdata.Review'. Use the JsonPropertyAttribute to specify another name.

The ToJson methods should specify the contract resolver explicitly to avoid this.

How to create collections?

First, great project - it was just what I was looking for and very easy to use. Good job!

Quick question: How do I create collections of entities? For instance, I want to create the JSON-LD for a list of blog posts or a list of events. For instance, Google might want you to create an events listing like this:

<script type="application/ld+json">
[{
  "@context": "http://schema.org",
  "@type": "MusicEvent",
  "name": "Boz Scaggs",
  "startDate": "2014-10-10T19:30",
  "location": {
     "@type": "Place",
     "name": "Warner Theatre",
     "address": "Washington, DC"
  },
  "offers": {
     "@type": "Offer",
     "url": "https://www.etix.com/ticket/1771656"
  }
},
{
  "@context": "http://schema.org",
  "@type": "MusicEvent",
  "name": "Boz Scaggs",
  "startDate": "2015-05-02T20:00",
  "location": {
     "@type": "Place",
     "name": "Coral Springs Center for the Performing Arts",
     "address": "Coral Springs, FL"
  },
  "offers": {
     "@type": "Offer",
     "url": "http://frontgatetickets.com/venue.php?id=11766"
  }
},
{
  "@context": "http://schema.org",
  "@type": "MusicEvent",
  "name": "Boz Scaggs",
  "startDate": "2015-05-03T20:00",
  "location": {
     "@type": "Place",
     "name": "Sunrise Theatre",
     "address": "Fort Pierce, FL"
  },
  "offers": {
     "@type": "Offer",
     "url": "http://frontgatetickets.com/venue.php?id=11767"
  }
},
{
  "@context": "http://schema.org",
  "@type": "MusicEvent",
  "name": "Boz Scaggs",
  "startDate": "2015-05-04T20:00",
  "location": {
     "@type": "Place",
     "name": "Hard Rock Live Orlando",
     "address": "Orlando, FL"
  },
  "offers": {
     "@type": "Offer",
     "url": "http://frontgatetickets.com/venue.php?id=11768"
  }
}]
</script> 

See https://developers.google.com/search/docs/data-types/events

How would I do this? Or for any other collection of "things"? Thanks!

NuGet update available?

Hi idenys,

would you mind updating the NuGet feed of this repository, so the package is in sync with the commits that happend last year? That would be awesome.
Cheers

Updated some data models

I've added some missing data models, and fixed a few things, like with VideoObject.cs.

I don't seem to have permission to create a pull request. Is there a way I can be added to the project to send in the pull request?

Thanks,
Kirk

Duplicate Json property discount in Order.cs

Both Discount and DiscountCode have same Json property in Order.cs

    [JsonProperty("discount")]
    public String Discount { get; set; }

    /// <summary>
    /// Text - Code used to redeem a discount.
    /// </summary>
    [JsonProperty("discount")]
    public String DiscountCode { get; set; }         

naming conflicts when using the CamelCasePropertyNamesContractResolver

Taking Organisation as an example, there is an Address properties and an Addresses properties with [JsonProperty("address")] attached.

If your app use the CamelCasePropertyNamesContractResolveras the ContractResolver then Address and Addresses are both given the name "address" and you get an exception thrown. It would be better if [JsonIgnore] were applied to Address. This is probably not the only issue where this conflict exists.

can't convert "Image" (string) to an ImageObject

var blogPosting = new BlogPosting(){
Image = new ImageObject()
{
    Url = "http://whatever.com/image.png",
    Width = new QuantitativeValue() { Value = 500 },
    Height = new QuantitativeValue() { Value = 500 }
}
}

my problem is that I can't do this, even though it's logical in the schema.org and it's actually documented in the summary of Image: //URL to an image of the item. This can be a URL or a fully described ImageObject.

I need the width and height for it to be a valid google rich snippet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.