csharpi | Repository for the Raspberry Pi C # Bot
kandi X-RAY | csharpi Summary
kandi X-RAY | csharpi Summary
This repository is intended for use with my blog series C# Discord Bot on a Raspberry Pi. Whether or not you use it to follow along with the posts, you can use it to learn how to make a C# Discord bot, and of course the Raspberry Pi part is completely optional.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of csharpi
csharpi Key Features
csharpi Examples and Code Snippets
Community Discussions
Trending Discussions on csharpi
QUESTION
I'm trying to make functions with Linq Expressions arguments and am stuck on a problem.
Here's my test function:
...ANSWER
Answered 2020-Nov-29 at 11:53The error is that you are passing Person
into prop.GetValue
when accessing PersonName.First
. The method tries to get the property First
from Person
but can't any. You need to pass the correct object into prop.GetValue
. I made this generic method which achives what you want. One limitation is that it only checks fields and properties, i will try to add methods in a bit
QUESTION
Let me preface this by saying, I am noob, and I know not what I do. So, if there is a better way of doing this, I am all ears.
Currently, I am working on project for which I need to be able to coerce a data source into a List
, where T
is an anonymous type, and filter it using lambda expressions, or create lambda expressions on the fly, save them to a database. I have already created a static wrapper class for System.Linq.Dynamic.Core
, called RunTimeType
, that has methods which allow me to create an anonymous type from some data source, and then create a List<>
of that anonymous type. After both of the anontype
and List
are created, I am using an existing fluent interface to create an Expression>
. Once I build the Expression
and compile it,
I either want to execute it, or I want to convert it to a string and save it to a database, xml file, etc., for later use.
Case 1:
When compiling and then immediately executing the expression, I am good up until this line:
var testList = anonList.Where(castedExp).ToList();
where i recieve the following error:
Error CS1973 C# has no applicable method named 'Where' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.
This makes sense, because filter
is declared as a dynamic
, which I am forced to do, otherwise compiler would complain with the following:
Error CS1061 'object' does not contain a definition for 'By' and no accessible extension method 'By' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
Case2:
As for the case of building the expression, converting it to a string, and then compiling to a valid Func
, I am good up until this line:
var castedExp = (Func)compileExp;
where i recieve the following error:
Error System.InvalidCastException 'System.Func
2[<>f__AnonymousType0
2[System.String,System.String],System.Boolean]' to type 'System.Func`2[System.Object,System.Boolean]'.'
However, I know that if I don't explicity cast to Func
, the compiler will complain with the following:
Error CS1503
Argument 2: cannot convert from 'System.Delegate' to 'System.Func'
.
So, my question is, how do I get around both of these situations, while still maintaining the ability use the anonymous type. Just to clarify again, I am forced to create an anonymous type because, I will not know what data set that I will be getting at run time, as these data sets are completely dynamic.
I want to reiterate, that I am open to doing this in a different way as long as the project's constraints are met. Frankly, I have been working on this for a while, I am out of ideas, and I need some guidance.
Below is all of the relevant code.
Test code:
...ANSWER
Answered 2020-Jan-04 at 21:49Here is a minimal working code for what you seemingly want to do:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install csharpi
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page