dynamic-language-runtime

How do I implement intellisense support for a custom DLR language in VS2008?

只愿长相守 提交于 2019-12-22 08:52:06
问题 I have just started writing my first language for the .NET DLR. I would like to know if it is possible to extend Visual Studio 2008 IntelliSense to handle the syntax of a custom DLR language? EDIT: I have decided to bypass VS2008 and target VS2010 instead. See accepted answer for more information. 回答1: Visual Studio's primary extensibility method for supporting new languages is through Language Services in a VSPackage. Visual Studio 2010 has radically improved the ability to support a new

DynamicObject implicit casting

僤鯓⒐⒋嵵緔 提交于 2019-12-22 06:39:50
问题 I have a subclass of DynamicObject and I would like to implement implicit casting for primitive types similarly as DO's explicit casting method TryConvert; that is, without writing multiple implicit operator [type] functions. Usage: dynamic myDynamicObject = new MyDynamicObject("1"); int sum = 1 + myDynamicObject; // instead of int i = 1 + (int)myDynamicObject; Is that possible and if so, how? 回答1: There are several things going on here. First, you are performing a binary operation. So, you

NancyFX: How do I check if query-string / form values have been correctly passed to my handler?

蹲街弑〆低调 提交于 2019-12-22 04:58:43
问题 Nancy passes my query-string and form values to my handlers via a dynamic variable. The example below shows form values being passed in to a POST handler via the Nancy request e.g. Request.Form.xxx . Handler Post["/"] = _ => { var userId = (string) Request.Form.userid; if (userId.IsEmpty()) return HttpStatusCode.UnprocessableEntity; return HttpStatusCode.OK; }; You can see that I am casting the userid to a string and then using a string extension method to check if the value is null or empty

Expression.Lambda and query generation at runtime, nested property “Where” example

筅森魡賤 提交于 2019-12-22 04:27:11
问题 I found very nice answer on a question about building Expression Tree for Where query. Expression.Lambda and query generation at runtime, simplest "Where" example Can someone help me and show me how this example could be implemented in the scenario with nested property. I mean instead of: var result = query.Where(item => item.Name == "Soap") With that solution: var item = Expression.Parameter(typeof(Item), "item"); var prop = Expression.Property(item, "Name"); var soap = Expression.Constant(

How do you implement C#4's IDynamicObject interface?

半城伤御伤魂 提交于 2019-12-18 13:34:28
问题 To implement "method-missing"-semantics and such in C# 4.0, you have to implement IDynamicObject: public interface IDynamicObject { MetaObject GetMetaObject(Expression parameter); } As far as I can figure out IDynamicObject is actually part of the DLR, so it is not new. But I have not been able to find much documentation on it. There are some very simple example implementations out there (f.x. here and here), but could anyone point me to more complete implementations or some real

C#'s 'dynamic' in F#

心已入冬 提交于 2019-12-18 12:57:09
问题 One example of using the DLR in C# is as follows: dynamic dyn = new MyObject(); dyn.MyMethod(); //resolved at runtime what would be the equivalent in F#? Thanks. 回答1: The ? operator has similar expressive power to the dynamic keyword in C# (but it can be only used for reading of properties, method invocation and setting of properties). There is no built-in implementation that would allow you to dynamically use properties or methods of a .NET class (via Reflection or DLR), but there are some

Why do I get this .NET error - “TypeError: expected List[DataPoint], got List[DataPoint]”

試著忘記壹切 提交于 2019-12-18 09:46:12
问题 I refactored some code, and now I get this error when calling a function. But everything seems to be fine, I even compared failing_argument.GetType().AssemblyQualifiedName between the old and the new code and they are the same. Any ideas what could be wrong? The invocation of the function is in IronPython code, the function is in C# code (an assembly which didn't change during this refactoring). What sort of thing could generate this error? EDIT: full IronPython traceback: Traceback (most

How do you add a string to a c# IList<string> from IronRuby?

前提是你 提交于 2019-12-13 04:59:43
问题 I get the following exception when I try to use a ruby script to modify a list of c# strings. Unhandled Exception: System.ArgumentException: The value "Scott" is not of type "System.String" and cannot be used in this generic collection. c# IList<string> names = new List<string>(); names.Add("scott"); names.Add("jason"); ScriptRuntime runtime = IronRuby.Ruby.CreateRuntime(); ScriptEngine engine = runtime.GetEngine("IronRuby"); ScriptScope scope = engine.CreateScope(); scope.SetVariable("names"

Parsing Visual Studio Project File as XML

左心房为你撑大大i 提交于 2019-12-12 18:16:38
问题 Using a dynamic xml parser, I'm trying to load a VS Project file as an XElement. Here is a slimmed down version of the project file: <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> </ItemGroup> <ItemGroup> </ItemGroup> </Project> The file appears to load in the sense that when I ToString(), I get the contents. However, when trying to pick out elements, nothing is ever found: