GithubHelp home page GithubHelp logo

pascaleschbach / xf.bindableproperty Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 1.0 148 KB

Turns your auto properties into Xamarin.Forms BindableProperties.

License: MIT License

C# 100.00%
bindable-properties c-sharp fody fodyweavers xamarin xamarin-forms

xf.bindableproperty's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

nearhuscarl

xf.bindableproperty's Issues

Fody: An unhandled exception occurred in VS 2019 Version 16.7.1

After updating Visual Studio a strange error message started to show up in my project.

I created a new Xamarin.Forms project to investigate and I found that whenever I implement Xamarin.Forms.BindableObject (or its superclass) , I cannot add any [Bindable] attributes.

public class MyClass : BindableObject
{
    [Bindable]
    public float MyProperty { get; set; }
}

Detailed error message:

Error		Fody: An unhandled exception occurred:
Exception:
Failed to execute weaver C:\Users\Alari\.nuget\packages\xf.bindableproperty.fody\1.2.1\build\..\weaver\XF.BindableProperty.Fody.dll
Type:
System.Exception
StackTrace:
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 202
   at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 109
Source:
FodyIsolated
TargetSite:
Void ExecuteWeavers()
Could not load file or assembly 'System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
Type:
System.IO.FileNotFoundException
StackTrace:
   at BindableProperty.Weave()
   at ModuleWeaver.Execute()
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 174
Source:
XF.BindableProperty.Fody
TargetSite:
Void Weave()
Could not load file or assembly 'System.ValueTuple, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.
Type:
System.IO.FileNotFoundException
	XFBindablePropertyTest		1	

Race condition when running multiple tests

I'm writing some test cases for this library before extending it for my internal usage. Right now if you try to run multiple tests, the tests are all failed except one with the error message like below

Member ** is declared in another module and needs to be imported

**: Usually one of these types.

However, they all pass if executed individually. The reason (I believe) is because the WeaverTypes class is static so the TypeReferences are imported from multiple assemblies when running

weavingTask.ExecuteTestRun("AssemblyToTestxX.dll")

In multiple test cases. I implemented a fix by making WeaverTypes non-static and instantiate it as a member of ModuleWeaver and reference it from there instead of globally. If you decide to write unit tests some day, be aware of that pitfall in your code.

TypeInitializationException when auto property type is not string

When defining a string auto property I can do:

[Bindable]
public string Name { get; set; } = "John";

When I try to create a bindable property with a type anything other than a string

[Bindable]
int Age { get; set; } = 30;

I get the following error

System.TypeInitializationException: The type initializer for 'TestFody.Views.TestView' threw an exception. ---> System.InvalidProgramException: Invalid IL code in TestFody.Views.TestView:.cctor (): IL_0095: call      0x0a000034

To get it to work, I have to type

[Bindable(OnCreateValue = nameof(CreateAge))]
public int Age { get; set; }
private static object CreateAge(BindableObject bindable) => 30;

It's of course A LOT better than the alternative.
Since PropertyChanged.Fody seems to handle different types automatically, Im guessing it could be done here also.

Awesome package by the way! :)

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.