Linked Questions

0 votes
1 answer
1k views

C# create class with dynamic number of properties [duplicate]

I'm new to c# but need to have it so depending on what d equals , there are a equal number of properties so if d=3 it would be D1, D2, D3, and the same if d=10000 I don't see how I can have a dynamic ...
user2394367's user avatar
27 votes
8 answers
37k views

How can I dynamically add a field to a class in C#

Is there any way to add Field (or FieldInfo, maybe this is the same) to a class at runtime?
Pavel Podlipensky's user avatar
28 votes
1 answer
25k views

Data binding dynamic data

I have a set of 'dynamic data' that I need to bind to the GridControl. Up until now, I have been using the standard DataTable class that's part of the System.Data namespace. This has worked fine, but ...
Chris Moutray's user avatar
17 votes
5 answers
8k views

Creating a class like ASP.NET MVC 3 ViewBag?

I have a situation where I would like to do something simular to what was done with the ASP.NET MVC 3 ViewBag object where properties are created at runtime? Or is it at compile time? Anyway I was ...
Alex Hope O'Connor's user avatar
14 votes
6 answers
45k views

Adding properties dynamically to a class

In my class I have private variables and properties like this. private string _itemCOde=string.Empty; private string _itemName=string.Empty; public string ItemCode { get { return _itemCode; } ...
Snj's user avatar
  • 943
11 votes
7 answers
12k views

Generate properties programmatically

I want to load a properties file (it's a .csv file having on each line a name and associated numeric value) and then access those property values like so: FileLoader.PropertyOne or FileLoader....
Johnny's user avatar
  • 7,163
16 votes
1 answer
10k views

Add property to dynamic object .NET

I probably want too much, but my scenario is public dynamic CreateConfigObject(JobConfigurationModel config) { dynamic configObject = new { }; configObject.Git = new GitCheckout { ...
Alexander Beletsky's user avatar
7 votes
4 answers
2k views

Is there a better data structure than Dictionary if the values are objects and a property of those objects are the keys?

I have a Dictionary<int, object> where the int is a property of obj. Is there a better data structure for this? I feel like using a property as the key is redundant. This Dictionary<int, ...
Brian Triplett's user avatar
3 votes
2 answers
10k views

C#: Dynamic add field to class

I search on Google but the result is misunderstand. This is a code flow: public class Store { public dynamic GetList(List<string> propertyFields) { // Body here // ...
Steve Lam's user avatar
  • 1,049
6 votes
5 answers
17k views

Dynamic class creation in C#

Is it possible in runtime to create a class from DataTable where ColumnName will be dynamic-class properties?
Polaris's user avatar
  • 3,713
3 votes
1 answer
7k views

C# How to Create a Custom (dynamic) class with Dynamic Linq using XElement in runtime

Hi I'm trying to make a list of a generic/dynamic class using XElement and DynamicLinq, to then show in a dataGridView1.DataSource First off lets make the xml by using the XElement class. // a List ...
Tinus Heystek's user avatar
5 votes
2 answers
1k views

Use C# Linq Lambda to combine fields from two objects into one, preferably without anonymous objects

I have a class setup like this: public class Summary { public Geometry geometry { get; set; } public SummaryAttributes attributes { get; set; } } public class SummaryAttributes { public ...
VBAHole's user avatar
  • 1,508
0 votes
3 answers
3k views

Linq to Compare 2 Objects

I have two objects. public class GlobalSettings { public bool A { get; set; } public bool B { get; set; } public bool C { get; set; } public bool D { get; set; } } public class ...
user avatar
2 votes
2 answers
830 views

C# - Class with dynamic number of properties that are bind-able

I have X number of RadioButtons (Silverlight). Normally this value is between 2-5. Call it "Switch". Each radio button is binded to a property of that class. Example property looks like private bool ...
Luke's user avatar
  • 1,870
0 votes
2 answers
3k views

how to add properties to objects dynamically in c#

I want to add the properties to the class / object dynamically in c# in VS 3.5. how can i do this?
Red Swan's user avatar
  • 15.4k

15 30 50 per page