FileHelpers dynamic class generation to support [TypeConverter(typeof(ExpandableObjectConverter))] - filehelpers

I am using FileHelpers class for dynamic generating the class
I got the result also but when I bind to property grid its not showing the nested object. Its says class need to have this attribute
[TypeConverter(typeof(ExpandableObjectConverter))]
But the class is dynamically generated through FileHelpers so how can I provide this attribute?
I even appended the string by fails fail to create the class now dynamically.
Please advise is there a way I can add this attribute to the class created dynamically through FileHelpers.

Related

can we pass Listview with data to another class library project class in vb net

I want to pass list view to another class library project class. I want all data in another class without loss of data and without change in original values. Is their any way??

How to get whole viewmodel in taghelper process method?

Is it possible to get the whole view model in tag helper Process method (.NET Core MVC)?
Everything passed to the tag helper is done via attributes. If you want the whole view model, then you'd simply so domething like:
<mytag model="#Model" />
And then you'd need a property on your tag helper to bind this to like:
public MyViewModel Model { get; set; }
The name of the attribute corresponds to the name of the property. There's nothing special about "model" here.
However, the utility of that is going to be limited. Tag helpers are intended to be somewhat generic. That's the point: encapsulating reusable logic. If you tie it to a particular view model class (based on the property), then it will only work with that particular view model. The only way to make it more generic would be to use a base class or to literally type it as object, so that anything could be passed. However, with a base class, 1) you need to have every view model inherit from this base class and 2) even then, you'd only be able to use properties on the base class. With object, you wouldn't really be able to reference any properties unless you downcast it to a particular view model class first. While that would allow you to handle any scenario, in principle, you'd be forced to have long blocks of switch or if statements in your tag helper to conditionally handle different scenarios.
Long and short, it's not a great idea for many reasons to pass the whole model. The tag helper should have one specific purpose, and you should only pass things that are specifically needed by it, which also allows you to be explicit about those needs.
If you're looking for something to handle a whole model, you're more likely looking for a partial view or view component, rather than a tag helper.
The viewmodel is actually available if you bind first the for element as :
[HtmlAttributeName("asp-for")]
public ModelExpression For { get; set; }
Then you can access it in your tag helper Process or ProcessAsync through:
For.ModelExplorer.Container.Model

Overloading DataTable methods in partial Dataset class

I have a Dataset with several partial class definitions in the Dataset.Designer.vb file. They are all partial class definitions, for example: Partial Public Class ItemTable{}
The problem is that when I define the other partial class to extend the functionality, it has no access to the properties and functions that were defined in the original partial class.
The pictures below are of the first/original Partial class definition, and the one i created to extend it.... Why cant I access "Adapter"?

Namespace resolution in MVC 4

I am working on an MVC 4 website that makes use of areas, lets call it 'MyMVC'.
As in most MVC projects there is a folder called 'Models' in the root of the website.
Inside this 'Models' directory there is a class called 'MyViewModel.cs' which contains a public class called 'MyViewModel' with a namespace of 'MyMVC.Models'.
Now, in one of the areas, call it 'Area1', there is also the typical MVC structure that also contains a directory called 'Models'. It also contains a class 'MyViewModel.cs' which also contains a class called 'MyViewModel', this time with a namespace of 'MyMVC.Areas.Area1.Models'.
Inside a view I am working on that is inside of the 'Area1\Views' directory I have at the top:
#model MyMVC.Areas.Area1.Models.MyViewModel
#using MyMVC.Areas.Area1.Models
When I go to reference the the MyViewModel like so, for example:
MyViewModel mvm = new MyViewModel();
I get an ambiguous error and it thinks I am referring to the other MyViewModel class although as you can see I have clearly specified with the #model directive and the #using directive which one I am referring to.
Can anyone explain what the ambiguity is?
Can anyone explain what the ambiguity is?
The ambiguity is not in your view. It's in your controller code:
MyViewModel mvm = new MyViewModel();
If in this controller you have both:
using MyMVC.Models;
using MyMVC.Areas.Area1.Models;
it's more than obvious that the C# compiler has no way of knowing which class you are referring to. You could remove the ambiguity by fully specifying the name of the class:
var mvm = new MyMVC.Areas.Area1.Models.MyViewModel();
UPDATE:
You might also have the namespace referenced in the <namespaces> section of your ~/Views/web.config file which is effectively bringing it into scope globally in all your views.

Xaml Serialization

I want to use xaml serialization to store the configuration data of my application. This info is represented as readonly properties of a custom configuration class. When loading the application, the configuration class is deserialized through xamlservices api from a text file. However, I get an error in the form:
Cannot set unknown member 'property_name'.' Line number '24' and line position '4'.
This is because the setters are private. Is there a way to deserialize the object with readonly properties through xaml?
Yes, but you won't get round-trip serialization. You write a XAML document in which the object you want is created using a non-default constructor.
Look up info about the directive.
If its a collection property you can try using the ContentWrapperAttribute.
You can also look at the ValueSerializerAttribute
More info can be found here http://msdn.microsoft.com/en-us/library/ff354959.aspx