I have no clue what an "anonymous type" is in C# nor how it is used. Can somone give me a good description of it and it's use?
[Note: i really know what it is and how to use it but thought i'd ask for those that don't]
...
I'm trying to loop through the results of a function that is returning an anonymous object of results.
public static object getLogoNav()
{
XDocument loaded = XDocument.Load(HttpContext.Current.Request.MapPath("~/App_Data/LOGO_NAV_LINKS.xml"));
var query = from x in loaded.Elements().Elements()
select new
...
Is there any way to dynamically set the property name of an anonymous type?
Normally we'd do like this:
var anon = new { name = "Kayes" };
Now I'd like to set the name (or identifier) of the property dynamically, so that this name can come from an XML file or a database.
...
In C# 3.0, is it possible to determine whether an instance of Type represents an Anonymous Type?
...
Let's say I have a method:
bool myMethod(int a)
{
//return a bool
}
So let's say I the following
// assume a has prop1 and prop2 both ints
var mySelection = from a in myContainer
where a=somecondition
select new {
a.prop1,
myMethod(a.prop2)
...
Why did the anonymous type property "Points" still have the value "0"?
Public Class Test
Public Sub New(ByVal _ID As Integer)
ID = _ID
End Sub
Public ID As Integer
End Class
Dim list As New List(Of Test)
list.Add(New Test(1))
list.Add(New Test(2))
list.Add(New Test(3))
Dim query = From X In list Select New With {....
When creating a query with EF, Normally we will create an anonymous type in order to limit the number of columns returned.
But anonymous type cannot be returned or used as a parameter to a method call, which means all work related to that anonymous object should be done inside a single method. This is really bad.
And certainly, we don'...
I'm porting an existing class library to Silverlight. I used lambda expression compilation a lot and now I'm experiencing security problems because of it.
In particular, if an anonymous class from a client SL app is participating in a lambda expression, I cannot compile it: I get a MethodAccessException with the following stack trace:
...
Is it possible to implicitly declare next Dictionary<HyperLink, Anonymous>:
{ urlA, new { Text = "TextA", Url = "UrlA" } },
{ urlB, new { Text = "TextB", Url = "UrlB" } }
so I could use it this way:
foreach (var k in dic)
{
k.Key.Text = k.Value.Text;
k.Key.NavigateUrl = k.Value.Url;
}
?
...
So I have this LINQ query that ends in a custom select kinda like this:
select new { this1 = table.this1, this2 = othertable.this2 }
The call to that query from the Controller looks something like this:
ViewData["these"] = theRepo.GetAllThese(someVar, anotherVar);
Now when I pass this on to my view since it is not strongly typed ho...
Hi, i´m trying to query a DataTable object without specifying the fields, like this :
var linqdata = from ItemA in ItemData.AsEnumerable()
select ItemA
but the returning type is
System.Data.EnumerableRowCollection<System.Data.DataRow>
and I need the following returning type
System.Data.EnumerableRowCollection<<object,object>>
(...
How do you query a collection which is populated/created with select new?
I have this BindingSource:
this.bindingSource.DataSource =
from row in db.Table
select new
{
name = row.Name + row.Num.ToString()
};
I'd like to query it like I do with other BindingSources:
var query = from row in (IEnumerable<Table>)a...
When I say Anonymous Type Declaration
var someType = new { Name = "Jon
Skeet", Age = 10 };
However the Keyword
var is implicitly typed
but when i print
Response.Write(someType.GetType().Name);
it produces <>f__AnonymousType02.What is this symbol <> relates to?
...
I have an anonymous type of this form:
new List<MyList>()
{
new Column { Name="blah", Width=100, Hidden=true },
new Column { Name="blah1", Width=60, Hidden=false }
}
How can I go about creating the content within the list dynamically, like:
new List<MyList>()
{
foreach (var columns in col) {
new Column { Name=column...
Note this question is similar this one except I'm not working with linq-to-sql, so the "let" is not usable.
Basically I have a select of the type
... .Select(c => new SampleClass { Id = c.Location.Name, Name = c.Location.Name }).Distinct().ToList()
which used to work when I just had
... .Select(c => c.Location.Name).Distinct().ToLis...
Hi
I have some linq to sql method and when it does the query it returns some anonymous type.
I want to return that anonymous type back to my service layer to do some logic and stuff on it.
I don't know how to return it though.
I thought I could do this
public List<T> thisIsAtest()
{
return query;
}
but I get this error
Error...
The short story: I want to convert a list/dictionary into an anonymous object
Basically what I had before was:
var model = from item in IEnumerable<Item>
select new
{
name = item.Name
value = item.Value
}
etc.
If I have name, item.Name in a list or dictionary, how can I go about creating the same anonymous obje...
I've been watching some videos on asp.net MVC, I think this question is just a general C# one though.
I notice sometimes in the example code, method paramters are called like this
blah.method("something here",
"Something else",
new { blah=item.someProperty });
Can you explain what is happening for the 3rd para...
Dear Group,
I am currently implementing a client-side paging solution using ASP.NET, jQuery and JSON.
I have been following the excellent article from encosia: http://encosia.com/2008/08/20/easily-build-powerful-client-side-ajax-paging-using-jquery/
In my Web Method I retrieve my data from the database as a DataTable:
DataTable c...
I have an asp:DetailsView with several columns, e.g. Foo, Bar.
I want to fill it with an anonymous type, i.e.:
gridView.DataSource = new { Foo = 1, Bar = "2" };
gridVeew.DataBind();
But getting next error:
Data source is an invalid type. It
must be either an IListSource,
IEnumerable, or IDataSource.
How can I do what I wan...