Rhino ETL C# DelimitedRecord - rhino-etl

I would like to know if are there a way to ignore the DelimitedRecord if it found in my file a string like "70,000 - 99,999"
File Sample:
1, "70,000 - 99,999"
6, "20,000 - 99,999"
8, "50,000 - 99,999"
[DelimitedRecord(",")]
public class MyClass
{
public string id;
public string Size;
}

I got the solution.
I need to use [FieldQuoted()] annotation on that field.

Related

Propery injection not working with Prism Unity

We have a WPF application using Prism (7.2.0.1422) and Unity as the DI container. I have the following class where I am attempting to use Unity Property injection
public class LocalizedDescriptionAttribute : DescriptionAttribute
{
[Dependency]
IStringResource _stringResource { get; set; }
string _resourceKey;
public LocalizedDescriptionAttribute(string resourceKey)
{
_resourceKey = resourceKey;
}
public override string Description
{
get
{
string description = _stringResource.GetString(_resourceKey);
return string.IsNullOrWhiteSpace(description) ? string.Format("[[{ 0}]]", _resourceKey) : description;
}
}
}
_stringResource is always null. I have registered the type as a singleton like this in RegisterTypes
containerRegistry.RegisterSingleton<IStringResource, StringResource>();
Anyone any ideas.
Thanks
Based on the name of the class, I assume it's an actual attribute? That cannot have anything injected by Unity, because the container can only inject into instances it creates itself.
You can, however, use the container from the attribute's code through a detour: the CommonServiceLocator. That's a static class that you only use if you have to, and this may be one of the rare cases where it's a good idea. You can use it to resolve the IStringResource from the container at runtime.

In Windows Phone 8, how to bind enum and listpicker

Can someone please give me an example how to bind enum to listpicker on Windows Phone 8?
Can't find any on the internet... and the lack of documentation regarding this toolkit won't help.
Thanks
Binding that is easy. The only problem is that the extension method GetNames() is not available in windows phone. However, you can write one.
public static class EnumExtensions {
public static IEnumerable<string> GetNames<TEnum>() where TEnum : struct {
var type = typeof(TEnum);
if (!type.IsEnum)
throw new ArgumentException(String.Format("Type '{0}' is not an enum", type.Name));
return (
from field in type.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static)
where field.IsLiteral
select field.Name)
.ToList<string>();
}
}
Once you have that it is easy to bind it to any list.
public enum MyEnum {
v1, v2, v3
}
// Binding
myListPicker.ItemsSource = EnumExtensions.GetNames<MyEnum>();
// Getting selected value
var myEnum = (MyEnum)Enum.Parse(typeof(MyEnum), myListPicker.SelectedItem.ToString());

How to implement fluent api in ASP.NET MVC?

I want to implement fluent api to my mvc sites. I got the basics.
So implement object library such as:
public class UIElement{/*...*/}
public class ButtonBase : UIElement{/*...*/}
public class LinkButton : ButtonBase {/*...*/}
public static class Extensions
{
public static T UIElementMethod<T>(this T element, string title)
where T : UIElement
{
return element;
}
public static T ButtonBaseMethod<T>(this T element, string title)
where T : ButtonBase
{
return element;
}
public static T LinkButtonMethod<T>(this T element, string title)
where T : LinkButton
{
return element;
}
}
But how to use it in razor view without some flush method calling.
#Html.UIproject().LinkButton()
.UIElementMethod("asd")
.ButtonBaseMethod("asd")
.LinkButtonMethod("asd")
But it returns the name of the class. I tried to make an implicit operator to MvcHtmlString but it's not called.
Any idea how to achieve this. How to know it's the and of the chain. I like the way how the Kendo UI work.
Thanks,
Péter
Your UIElement classes need to implement the IHtmlString interface. This interface's ToHtmlString method gets called by Razor and should return an HTML-encoded string.
So I would implement this on the abscract base UIElement and create RenderHtml method which can be implemented by the concrete LinkButton, etc. classes:
public abstract class UIElement : IHtmlString
{
public string ToHtmlString()
{
return RenderHtml(); // This should return an HTML-encoded string.
}
public override string ToString()
{
return ToHtmlString();
}
protected abstract string RenderHtml();
}
If you check KendoUI in Reflector/JustDecompile/dotPeek in the WidgetBase class you will see the same pattern.
I haven't tried it, in this particular situation, but you might be able to use an implicit cast to convert from a fluent builder to the object you need (see this blog).

enums in EF code first

please, how to work with enums in Entity Framework code first. i want that in my class "Annonce" i can have this proprety
public Status EtatAnnonce { get; set; }
and Status is defined like this
public enum Status
{
Pending,
Approved
}
You need to create a converter field to store the value as int in the database.
public int MyEnumValueInt {get;set;}
[NotMapped]
public MyEnum MyEnumValue
{
get{ return (MyEnum)MyEnumValueInt;
set{ MyEnumValueInt = (int)value;
}
Note: The enum support will be improved in EF 5.
Will point you towards
EF5 does not create enum columns
To give a summary of enum support in Entity Framework code first:
EF4: Not supported
EF5: only supported if you are targeting .net framework 4.5 and higher
EF6: only supported if you target .net 4.0 and higher
Cheers!
I've answered two questions regarding Enums in EF; these should help you along:
Enums with EF code-first - standard method to seeding DB and then using?
and
EF 4.1 Code First - map enum wrapper as complex type
You can use private properties in your model to map your data to whatever property type you want.
// Model
public class Piece
{
// Subclass Piece to add mappings for private properties
public class PieceConfig : EntityTypeConfiguration<Piece>
{
public PieceConfig()
{
Property(b => b.dbtype); // needed for EF to see the private property
}
}
[Column("type", TypeName = "VARCHAR")]
private string dbtype { get; set; }
[NotMapped]
public PIECE type
{
get { return (PIECE)Enum.Parse(typeof(PIECE), dbtype); }
set { dbtype= value.ToString(); }
}
}
Then you just need to add the configuration to your OnModelCreating method
modelBuilder.Configurations.Add(new Piece.PieceConfig());

Type not being instantiated correctly by StructureMap (using XML configuration)

OK, I'm stumped over a seemingly trivial piece of functionality.
How can I get StructureMap to initialize the properties on type instances retrieved from the container, using XML configuration (unfortunately I have to use XML)?
My current code is:
The type and interface:
public interface IMyType
{
decimal MyProperty { get; set; }
}
public MyType : IMyType
{
public decimal MyProperty {get; set; }
}
The container initialization and instance retrieval code:
ObjectFactory
.Initialize(x => x.AddConfigurationFromXmlFile(#"StructureMap.config"));
IMyType instance = ObjectFactory.GetNamedInstance<IMyType>("Blah");
var myPropertyValue = instance.MyProperty; //expected 1, is actually 0
XML Configuration:
<?xml version="1.0" encoding="utf-8" ?>
<StructureMap MementoStyle="Attribute">
<AddInstance
PluginType="MyNamespace.IMyType, MyAssemblyName"
PluggedType="MyNamespace.MyType, MyAssemblyName"
Key="Blah"
Name="Blah
MyProperty="1" />
</StructureMap>
This looks like a typing issue with StructureMap. Using an int, float or double works. Using a decimal does not.
Workaround is to use another floating point type such as float or double.

Resources