C# Dynamic Keyword — Run-time penalty?

The question is very confusing. Does defining an instance as dynamic in C# mean: By “defining an instance” do you mean “declaring a variable”? The compiler does not perform compile-time type checking, but run-time checking takes place like it always does for all instances. What do you mean by “run-time checking like it always does”? … Read more

get the Type for a object declared dynamic

You need to do this… Type unknown = ((ObjectHandle)tmp).Unwrap().GetType(); By the way, this is a little confusing because if you call Activator.CreateInstance on a type in your current assembly… Activator.CreateInstance(typeof(Foo)) …the object is not wrapped and the original code works fine.

How do I dynamically generate columns in a WPF DataGrid?

Ultimately I needed to do two things: Generate the columns manually from the list of properties returned by the query Set up a DataBinding object After that the built-in data binding kicked in and worked fine and didn’t seem to have any issue getting the property values out of the ExpandoObject. <DataGrid AutoGenerateColumns=”False” ItemsSource=”{Binding Results}” … Read more

Dynamic class in Angular.js

You can simply assign a function as an expression and return proper class from there. Edit: there is also better solution for dynamic classes. Please see note below. Snippet from view: <div ng-class=”appliedClass(myObj)”>…</div> and in the controller: $scope.appliedClass = function(myObj) { if (myObj.someValue === “highPriority”) { return “special-css-class”; } else { return “default-class”; // Or … Read more

Why can’t I index into an ExpandoObject?

how the Expando was able to hide the method of one of its interfaces. Because as you correctly found out in the documentation, the indexer is an explicit interface implementation. From Explicit Interface Implementation Tutorial: A class that implements an interface can explicitly implement a member of that interface. When a member is explicitly implemented, … Read more

How to create own dynamic type or dynamic object in C#?

dynamic MyDynamic = new System.Dynamic.ExpandoObject(); MyDynamic.A = “A”; MyDynamic.B = “B”; MyDynamic.C = “C”; MyDynamic.Number = 12; MyDynamic.MyMethod = new Func<int>(() => { return 55; }); Console.WriteLine(MyDynamic.MyMethod()); Read more about ExpandoObject class and for more samples: Represents an object whose members can be dynamically added and removed at run time.

XSLT Transformation – dynamic element names

This XSL Stylesheet: <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:output indent=”yes”/> <xsl:strip-space elements=”*”/> <xsl:template match=”node()|@*”> <xsl:copy> <xsl:apply-templates select=”node()|@*”/> </xsl:copy> </xsl:template> <xsl:template match=”Field”> <xsl:element name=”{@Name}”> <xsl:value-of select=”@Value”/> </xsl:element> </xsl:template> </xsl:stylesheet> Applied to well-formed input: <SiebelMessage MessageId=”1-18J35″ IntObjectName=”XRX R5 Letter Instance” MessageType=”Integration Object” IntObjectFormat=”Siebel Hierarchical”> <LetterInstance Id=”1-1RUYIF” Language=”ENU” TemplateType=”SA”> <Field Value=”CO Last Name” Datatype=”String” Name=”ContractingOfficerLastName”/> </LetterInstance> </SiebelMessage> Produces: <SiebelMessage MessageId=”1-18J35″ … Read more

Does Perl have PHP-like dynamic variables?

What you’re attempting to do is called a “symbolic reference.” While you can do this in Perl you shouldn’t. Symbolic references only work with global variables — not lexical (my) ones. There is no way to restrict their scope. Symbolic references are dangerous. For that reason they don’t work under the strict pragma. In general, … Read more

Android – Dynamically Get the Current Activity in Foreground

I’m not sure if this is what you’re looking for, but it seemed pretty straightforward. http://iamvijayakumar.blogspot.com/2011/09/get-current-activity-and-package-name.html ActivityManager am = (ActivityManager) this .getSystemService(ACTIVITY_SERVICE); List<RunningTaskInfo> taskInfo = am.getRunningTasks(1); ComponentName componentInfo = taskInfo.get(0).topActivity; Log.d(WebServiceHelper.TAG, “CURRENT Activity ::” + taskInfo.get(0).topActivity.getClassName()+” Package Name : “+componentInfo.getPackageName()); Hope this helps.