domysee / pather.csharp Goto Github PK
View Code? Open in Web Editor NEWPather.CSharp - A Path Resolution Library for C#
License: MIT License
Pather.CSharp - A Path Resolution Library for C#
License: MIT License
if the current class has an abstract base class, the property does not get resolved:
File: Property.cs
Line of Code: PropertyInfo p = target.GetType().GetTypeInfo().GetDeclaredProperty(property);
It will get resolved with
PropertyInfo p = target.GetType().GetTypeInfo().GetProperty(property);
NullReferenceException
happens if you try to Resolve a indexer path on an object which does not implement IEnumerable
Test code:
public class IndexerClassNoIEnumerable
{
private readonly string value;
public IndexerClassNoIEnumerable(string value)
{
this.value = value;
}
public string this[int index] => value + index;
}
[TestMethod]
public void Resolver_IndexerClassNoIEnumerable_ThrowsException()
{
var target = new IndexerClassNoIEnumerable("Test");
var resolver = new Resolver();
var path = "[123456]";
var res = resolver.Resolve(target, path);
// throws
// System.NullReferenceException: Object reference not set to an instance of an object.
// at Pather.CSharp.PathElements.EnumerableAccess.Apply(Object target)
// at Pather.CSharp.Resolver.Resolve(Object target, IList`1 pathElements)
// at Pather.CSharp.Resolver.Resolve(Object target, String path)
res.Should().Be("Test123456");
}
Inevitably, when using the path through an object, you come across the case where an object in the path is null. As expected this causes an exception. Is there any way to deal with this in a similar way to the c#6 syntax e.g. myproperty?.mySubproperty
Really handy little library by the way :)
I like your work.
One thing I noticed is the dependency to the .Net Standard Library.
When I install the nuget package for Pather.CSharp I end up with over 2000 changed files.
Is the .Net Standard Library really required as a dependency?
Is there any way to get the property's Sum or the Count of the List ?
For example:
users.Select(user=>user. Orders).SelectMany(order=>order. Prices).Sum(price=>price.AnyProperty);
This is a feature recommendation: supporting Environment Variable resolution. This could search for a match in the natural progression from process => user => computer level environment settings.
Good library. Works great.
However, this is one small issue.
When I have a solution that targets .NET Standard 1.4 and I add your package, it adds a reference to System.Runtime.InteropServices
version 4.3. When I compile I get the 'found conflicts between two different versions'. This is caused by your library combined with the the above reference.
If I change my target to .NET Standard 1.6, the warnings go away.
I think the issue is you have targeted .NET Standard 1.0, PLUS a package from .NET Standard 1.1. I think instead, you should simply target 1.1 and nothing else extra.
Thoughts?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.