anonymous-types

How To Test if a Type is Anonymous?

I have the following method which serialises an object to a HTML tag. I only want to do this though if the type isn't Anonymous. private void MergeTypeDataToTag(object typeData) { if (typeData != null) { Type elementType = typeData.GetType(); if (/* elementType != AnonymousType */) { _tag.Att...

Anonymous Type where Properties are unknown until runtime

I have the following scenario, I want to create a DataGrid and then populate the contents at runtime. The issue I am having is that because I do not know what the fields are until I am creating the grid I do not know how to set the item source correctly. As you can see in the following code I am adding the Field names as columns, I am ...

How can I access the group of a linq group-by query from a nested repeater control?

I'm using a linq group by query (with two grouping parameters) and would like to use the resulting data in a nested repeater. var dateGroups = from row in data.AsEnumerable() group row by new { StartDate = row["StartDate"], EndDate = row["EndDate"] }; "data" is a DataTable from an SqlDataAdapter-filled DataSet. "dateGroups" is us...

How do I iterate over the properties of an anonymous object in C#?

I want to take an anonymous object as argument to a method, and then iterate over its properties to add each property/value to a a dynamic ExpandoObject. So what I need is to go from new { Prop1 = "first value", Prop2 = SomeObjectInstance, Prop3 = 1234 } to knowing names and values of each property, and being able to add them to t...

Is there any reasonable use of a function returning an anonymous struct?

Here is an (artificial) example of using a function that returns an anonymous struct and does "something" useful: #include <iostream> template<typename T> T* func( T* t, float a, float b ) { if(!t) { t = new T; t->a = a; t->b = b; } else { t->a += a; t->b += b; } retu...

C# 4.0 dynamics

Hi. Code bellow is working well until I have class ClassSameAssembly in same assembly as class Program. But when I move class ClassSameAssembly to separate assembly I have runtime error. Is it posible to resolve it? using System; namespace ConsoleApplication2 { public static class ClassSameAssembly { public static dynamic GetV...

Silverlight 4 Data Binding with anonymous types.

Does anyone know if you can use data binding with anonymous types in Silverlight 4? I know you can't in previous versions of silverlight, you can only databind to public class properties and anonymous type properties are internal. Just wondering if anyone has tried it in silverlight 4? Thanks in advanced ...

Anonymous union definition/declaration in a macro GNU vs VS2008

I am attempting to alter an IAR specific header file for a lpc2138 so it can compile with Visual Studio 2008 (to enable compatible unit testing). My problem involves converting register definitions to be hardware independent (not at a memory address) The "IAR-safe macro" is: #define __IO_REG32_BIT(NAME, ADDRESS, ATTRIBUTE, BIT_STRUCT)...

Why LINQ to Entities won't let me initialize just some properties of an Entity?

So I've started to add Entity Framework 4 into a legacy web application (ASP.NET WebForms). As a start I have auto-generated some entities from the database. Also I want to apply Repository Pattern. There is an entity called Visitor and its repository VisitorRepository In VisitorRepository I have the following method: public IEnumera...

Why can't an Anonymous Type be used outside the method it's created in?

I understand that if I cast it to a named type I can do whatever I want with it, but it'd make for much tidier code if I could keep the anonymity between method calls. ...

How does objective-c know what is going to be returned by an anonymous object?

- (void) doSomething: (id)with { int a; a = [with doSomething]; } How does the compiler know what type [with doSomething] is going to return? Does it assume an int, since that's what I'm assigning to? ...

Use of var in linq

What does var really do in the following case? var productInfos = from p in products select new { p.ProductName, p.Category, Price = p.UnitPrice }; ...

Create an anonymous type object from an arbitrary text file

I need a sensible way to draw arbitrary text files into a C# program, and produce an arbitrary anonymous type object, or perhaps a composite dictionary of some sort. I have a representative text file that looks like this: adapter 1: LPe11002 Factory IEEE: 10000000 C97A83FC Non-Volatile WWPN: 10000000 C93D6A8A , WWNN: 20000000 C93D6...

set value of a property of an anonymous type using reflection / TypeDescriptor is it possible ?

I tried using TypeDescriptor and the value is not changing, and via reflection I get an error that there is no setter for that property ...

Possible to assign a data type to an anonymous type's members in a linq query?

If I have a linq query that creates the anonymous type below: select new { lf.id, lf.name, lf.desc, plf.childId }; Is it possible to assign a specific type to one of the members? ...

How to perform Linq select new with datetime in SQL 2008

In our C# code I recently changed a line from inside a linq-to-sql select new query as follows: OrderDate = (p.OrderDate.HasValue ? p.OrderDate.Value.Year.ToString() + "-" + p.OrderDate.Value.Month.ToString() + "-" + p.OrderDate.Value.Day.ToString() : "") To: OrderDate = (p.OrderDate.HasValue ? p.OrderDate.Value.T...

how to convert an instance of an anonymous type to a NameValueCollection

Suppose I have an anonymous class instance var foo = new { A = 1, B = 2}; Is there a quick way to generate a NameValueCollection? I would like to achieve the same result as the code below, without knowing the anonymous type's properties in advance. NameValueCollection formFields = new NameValueCollection(); formFields["A"] = 1; form...

What are anonymous types in C#?

Possible Duplicate: How should anonymous types be used in C#? What are anonymous types in C#, and when should they be used? ...

Is there a var type equivalent in C++?

So I know that C++ is strongly typed and was just wondering if there was any library (or any thing for that fact of the matter) that would allow you to make a variable that has no initial specific type like var in Python. ...

If I select from an IQueryable then the Include is lost

The include does not work after I perform a select on the IQueryable query. Is there a way arround this? My query is public IQueryable<Network> GetAllNetworks() { var query = (from n in _db.NetworkSet .Include("NetworkContacts.Contact") .Include("NetworkContacts.Contact.RelationshipSource.Target") ...