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...
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 ...
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...
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...
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...
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...
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
...
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)...
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...
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.
...
- (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?
...
What does var really do in the following case?
var productInfos =
from p in products
select new { p.ProductName, p.Category, Price = p.UnitPrice };
...
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...
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
...
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? ...
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...
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...
Possible Duplicate:
How should anonymous types be used in C#?
What are anonymous types in C#, and when should they be used?
...
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.
...
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")
...