Giter Site home page Giter Site logo

Comments (6)

WojciechNagorski avatar WojciechNagorski commented on May 21, 2024

I like your changes in Configuration, but I don't know what you want to do in this issue .

from home.

Mike-E-angelo avatar Mike-E-angelo commented on May 21, 2024

So Markup Extensions are an awesome feature of Xaml that allow you to provide runtime values for a property while the object is being serialized. They also allow you to tie into the object that is being serialized so that you can do cool things with it as time goes on (like binding).

Super simple example here:

public class MyMarkupExtension : IMarkupExtension
{
	public object ProvideValue(IServices services) => "Hello World"; // <-- could be from a web service or anywhere.
}
class Instance
{
	public string PropertyValue { get; }
}

<Instance PropertyValue="{x:MyMarkup}" />
var serializer = new ExtendedConfiguration().Create();
var actual = serializer.Deserialize<Instance>();
Assert.Equal( actual.PropertyValue, "Hello World!");

Another scenario could be how we use references. Instead of using custom attributes (exs:reference/identity), we could use markup extensions instead. That's how Xaml does it. :)

from home.

Mike-E-angelo avatar Mike-E-angelo commented on May 21, 2024

OK this took a little longer than expected, but we now have a very simple implementation of markup extensions with core support for default framework markup extensions such as Null, Type, and Static. Basically got done in one week what the entire UWP group has taken nearly seven years to do. ;)

Example of the static extension (and others) can be seen here.

Please note that in addition to specifying strings for values within a markup extension, I took it one step further so that you can use actual .NET/C# expressions within it. So let's say you have an extension like this:

sealed class NumberExtension : IMarkupExtension
{
	readonly int _number;

	public NumberExtension(int number)
	{
		_number = number;
	}

	public object ProvideValue(IServiceProvider serviceProvider) => _number;
}

sealed class Subject
{
	public int Number { get; set; }
}

You are able to use it in your markup as such:

<?xml version="1.0" encoding="utf-8"?>
<Subject xmlns="clr-namespace:YourNamespace;assembly=YourAssembly" PropertyName="{Number 3 * 4}" />
var subject = new ExtendedConfiguration().EnableMarkupExtensions()
			                 .Create()
			                 .Deserialize<Subject>(xml);
subject.Number.Should().Be(12);

Cool huh! Unfortunately (or fortunately, depending on your perspective :) ), in order to do this, we had to take on a dependency. Currently, it is using the very powerful and handy Eval-Expression.NET. It is free for the first 50 characters. I am in communication with @JonathanMagnan in regards to this to see if we can somehow get a pro version if we give it special mention/thanks in our README. Jonathan has said that they should have something together by Monday to discuss.

Also a consideration here Jonathan (and feel free to reply here): currently we are using all of our dependencies inline. So we currently have two dependencies in Sprache and LightInject. Both of them have been placed in our Core folder with licenses provided for both.

Will this be OK for your project as well?

I will be closing this issue to mark as done for now to get it off our list towards the milestone. Please feel free to continue to comment.

from home.

WojciechNagorski avatar WojciechNagorski commented on May 21, 2024

Build failed ;)

There is log: https://ci.appveyor.com/project/wojtpl2/extendedxmlserializer/build/72

from home.

Mike-E-angelo avatar Mike-E-angelo commented on May 21, 2024

Hah! It sure did. Is there a notification for this, perhaps? Seems like an important one to know. :)

The break is actually due to Eval-Expression.NET. It looks for a new package at the start of every month. I believe this is what Jonathan and team are looking for in our case here.

I just committed a fix. HERE GOES NOTHING!! 😆

from home.

Mike-E-angelo avatar Mike-E-angelo commented on May 21, 2024

OK this looks like this is working as expected now. Let me know if it is otherwise.

from home.

Related Issues (20)

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.