anonymous-types

How to return Boolean value from Action Delegate under List.ForEach()

I am trying to implement following thing. I need to return true if any of the button is found to be changed. I don't want any more looping. Since ForEach is looking for Action Type Delegate. So is it possible to return bool value from within a deletage public bool AreSettingChanged() { objRpmButtonHolder.RpmButtonCollection.ForEach...

Reflection failed for properties on anonymous types in Silverlight

Hi, I'm using Silverlight 4 with VS 2010 and trying to do reflection on anonymous type and I got some "Attempt by method '...' to access method '...' failed.". I tried various workarounds for this but I couldn't find and simple ones. class.CallAnonymous("SimpleClass", "HelloFunc", new { strIn = "Boo" }); public void CallA...

Linq to NHibernate projection to anon. type results in mystifying cast error

I have an TaxWork entity which is persisted using NHibernate. This entity has the following properties (among others): public virtual TaxWorkType Type { get; set; } //Kctc.TaxWorkType is an enumeration public virtual TaxWorkStatus Status { get; set; } //Kctc.TaxWorkStatus is an enumeration public virtual LegalWorkPriority Priority { get...

Finding an Anonymous Type's Source

I have a reflection method finds all the types in a namespace: var models = Assembly.GetAssembly(application).GetTypes().Where( @t => @t.Namespace == typeof(ViewModelNamespaceBeacon).Namespace).OrderBy(@m => @m.Name).ToList(); My problem is I'm returning an Anonymous type with the name of: {Name = "...

Anonymous type and intersection of 2 lists

public class thing { public int Id{get;set;} public decimal shouldMatch1 {get;set;} public int otherMatch2{get;set;} public string doesntMatter{get;set;} public int someotherdoesntMatter{get;set;} } List<thing> firstList = new List<thing>(); List<thing> secondList = new List<thing>(); firstList.Add( new thing{ Id=1,shouldMatch1 = 1.11M,...

How to dynamic new Anonymous Class ?

In C# 3.0 you can create anonymous class with the following syntax var o1 = new { Id = 1, Name = "Foo" }; Is there a way to dynamic create these anonymous class to a variable? Example: var o1 = new { Id = 1, Name = "Foo" }; var o2 = new { SQ = 2, Birth = DateTime.Now }; Dynamic create Example: var o1 = DynamicNewAnonymous(new...

How to use Expression to build an Anonymous Type?

In C# 3.0 you can use Expression to create a class with the following syntax: var exp = Expression.New(typeof(MyClass)); var lambda = LambdaExpression.Lambda(exp); object myObj = lambda.Compile().DynamicInvoke(); But how do you use Expression to create an Anonymous class? //anonymousType = typeof(new{ Name="abc", Num=123}); Type anon...

asynchronous threads and anonymous delegates

Ok, now I can use 2 techniques to launch my threads: Dispatcher and BackgroundWorker. Dispatcher: ' I launch the asynchronous process Dim a As New Action(AddressOf operazioneLunga) a.BeginInvoke(Nothing, Nothing) ' I update the GUI passing some parameters Dim a As New Action(Of Integer, String)(AddressOf aggiorna_UI) Me.Dispatcher.Beg...

.net mvc4 view / c# anonymous type and object htmlAttributes: new {class="mycssclass"} error

Ok, I cant find the answer to this: <%: Html.ActionLink("Click Here", "Action", null, new {class="myClass"})%> I want to set the CSS class attribute of the generated element. Obviously, C# will not allow me to use "class" as the name of an object's member. What should I do? ...

C#: Memory allocation for Anonymous Variables

I'm having a doubt regarding the memmory allocation for anonymous type variable. if i declare a variable int Vaiable_Name it will allocate 4 bytes but in case of Anonymous types , what will happen , and when the memory will get deallocated ? Need we deallocate that manually?? for example List<String> MyList=new List<String>{"0","1"...

Objective-C equivalent to Java's anonymous classes in class methods

I want to set the delegate of an object inside a class method in Objective-C. Pseudo-code: + (ClassWithDelegate*) myStaticMethod { if (myObject == nil) { myObject = [[ClassWithDelegate alloc] init]; // myObject.delegate = ? } return myObject; } In Java I would simply create an anonymous class that implement...

How to cast anonymous type to specified cast to get all its properties

This code is returning me a list that I am trying to pass to another function. _ucItem.lblItemName.Text = itemRow.Field<string>("ITEM_NAME").ToString(); _ucItem.pbxItemImg.Image = itemRow.Field<string>("IMAGE").ToString(); _ucItem.lblItemName.Text = itemRow.Field<string>("FK_ITEM_ID").ToString(); Here I want to replace this set of lin...

Does VB.NET 2010 support arrays of anonymous objects?

In C#, one can create an array of anonymous objects with new []. This was not supported in earlier versions of VB.NET, but a comment by Chris Dwyer in another StackOverflow post suggests to me that it might be supported in VB.NET 2010. I haven't been able to confirm this though. Does VB.NET 2010 support arrays of anonymous objects? ...

Disadvantages of using anonymous types in place of dictionaries?

I wrote this function private string BuildXPathQuery(string prefix = "descendant::", string tag = "*", object attrs = null) { StringBuilder sb = new StringBuilder(prefix); sb.Append(tag); if (attrs != null) foreach (var a in attrs.GetType().GetProperties()) sb.Append(string.For...

Entity Data Model, Dynamic Linq, multiple table dynamic Where clause, strongly typed return types

Hello, When writing a method for an oData service I have the below linq, for which I need to have a dynamic "where" clause to filter the results (the "new"s in the joins are for composite PKs in the Entity Data Model): var query = from pl in CurrentDataSource.ProductListing join pla in CurrentDataSource.ProductListingAttri...

Dictionary(string -> tuple) in .NET 3.5 ?

I was wondering if there's a way to create a dictionary using an anonymous type for its values. Something like { { "first", {1, true} }, { "second", {2, false} }, } I want to use this in .NET 3.5, so there's no vanilla implementation of Tuple<...> available. Any suggestions? ...

IQuerable, converting Anonymous Type to Strong Type

Is there a more elegant/concise way of this; I'd like to get rid of foreach loop with the WorkListItem initialization code. var queryable = registrations.Select( r => new { r.Id, r.AccountNumber, r.DateAdded, r.DateUpdated, r.Patient, r.Patient.InsuranceInfos ...

Naming an anonymous function

Is it possible to somehow set a name for anonymous functions? There is no need to add function names to the namespace for anonymous functions but I would like to avoid seeing a large amount of (?) in my javascript debugger so I can keep the call stack trace informative. Also can I safely pass normal declared functions as arguments inst...

VB.Net Serialize anonymous type to xml

In MVC I can do something like the following to serialise an object with an anonymous type to JSON... Public Function GetStateList() As JsonResult Dim MyObject = New With {.Id = 1, .Property = "SomeValue"} Return Me.Json(MyObject) End Function which would return something like; { "Id": 1, "Property"Som...

How can i check if this XElement is not null before adding it to an anonymous object?

I'm populating an anonymous object from an XML file. Up until now, commentary.Elements("Commentator") has always had a value so i've never had to check for null. I've had to remove that though, and now it's failing when it tries to read that line. I'm looking at the code and I don't know what to change though, because its being selec...