|
I'm trying to understand what this piece of code does from Prajeesh's Blog
I've never seen a statement with any 'where' statements in the method before
using FluentValidation;
....
public static ValidationResult Validate(K entity)
where T : IValidator, new()
where K : class
{
IValidator __Validator = new T();
return __Validator.Validate(entity);
}
Can you help...???
|
|
|
|
|
Did you ask the author of the blog?
It's time for a new signature.
|
|
|
|
|
yes, no reply as yet, so I thought I'd ask here, seeing as I use CP loads ![Big Grin | :-D](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_biggrin.gif)
|
|
|
|
|
The where statements are used to constrain which Types the generic can be used for. So:
Sevententh wrote: where T : IValidator, new()
Means that the type T must inherit from IValidator and must have an accessible constructor that takes no arguments.
Sevententh wrote: where K : class
This states that the type must be a Reference Type, not a Value Type.
|
|
|
|
|
So is the above code wrong? It should be
public static ValidationResult Validate<T>(K entity)
where T : IValidator, new()
where K : class
{
IValidator __Validator = new T();
return __Validator.Validate(entity);
}
As I get the Error: Constraints are not allowed on non-generic declarations, if I use the code from the blog...?
I think I need to wait until the author gets back to me! I run into even more problems if i use this change!!
Thanks for your help tho
|
|
|
|
|
You could try:
public static ValidationResult Validate<T, K>(K entity)
where T : IValidator, new()
where K : class
{
IValidator __Validator = new T();
return __Validator.Validate(entity);
}
But, without more context this is nothing more than an educated guess, so the blog writer will definitly know best.
|
|
|
|
|
Fantastic! that resolved all the other problems I was having with this code
Thanks
|
|
|
|
|
hi guys
how to send file via bluetooth from pc to another device such as phone or pc?
thanks a lot
|
|
|
|
|
|
hello
If my sql statement has multiple lines with comments (i.e. line starting with "//") - how am I going to get it work with Sql cmd and Adapters...? Is there a carriage return escape character ...?
<br />
Cmd = Conn.CreateCommand();<br />
Cmd.CommandType = CommandType.Text;<br />
Cmd.CommandTimeout = 0;<br />
Cmd.CommandText = SomeSQL; << This is multiple lines concatenate to a single string.<br />
ConnFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");<br />
SomeDataSet = new DataSet("MultilineSQL");<br />
SomeTable = new DataTable("MultilineSQL");<br />
SomeDataSet.Tables.Add(SomeTable);<br />
DbAdapter = ConnFactory.CreateDataAdapter();<br />
DbAdapter.SelectCommand = (DbCommand)Cmd;<br />
DbAdapter.Fill(OutputSet, "MultilineSQL");
Thanks
dev
|
|
|
|
|
Are you getting an error while using it now? Could you post a sample of your string query?
|
|
|
|
|
for example
<br />
IF OBJECT_ID('TEMPDB..#SomeTmp) IS NOT NULL DROP TABLE #SomeTmp<br />
CREATE TABLE #SomeTmp<br />
(<br />
a datetime,<br />
b float,<br />
c float,<br />
...<br />
)<br />
// Some comment BLOWS UP HERE <br />
insert into #SomeTmp<br />
exec SomeProc xxxxx
dev
|
|
|
|
|
You probably need some GO 's in there to batch commands up.
IF OBJECT_ID('TEMPDB..#SomeTmp) IS NOT NULL DROP TABLE #SomeTmp
CREATE TABLE #SomeTmp
(
a datetime,
b float,
c float,
...
GO
// insert into #SomeTmp
GO
exec SomeProc xxxxx
GO
|
|
|
|
|
Should the comment be done with -- ?
And when I pass more than one statement in one Command I separate them with semi-colons (; ).
|
|
|
|
|
Hi,
I'm trying to determine if the row has been modified. I have used Visual Studio 2010 and dragged the controls onto the form, so VS has built everything. When a direction button on the navigator is clicked, I run this code.
x = Convert.ToInt32(reunionBindingNavigator.PositionItem.Text);
DataRow dr = KTReunionDataSet.Reunion.Rows[x];
Debug.WriteLine(dr.RowState.ToString());
if (dr.RowState == DataRowState.Modified)
return;
I start with row one, change the date on the calendar, click next, row 2 is now showing, don't modify anything on row 2, click the back button so we are now on Row 1, yet dr.RowState shows as UnModified.
Did I do something wrong or am I missing something?
Thank you,
Glenn
|
|
|
|
|
Hi Glenn,
I have used this code. It will work correctly.
int x = Convert.ToInt32(bindingNavigator1.PositionItem.Text);
DataRow dr = dt.Rows[x-1];
if (dr.RowState == DataRowState.Modified)
{
MessageBox.Show("Modified");
}
I don't know what you have done in second line. Which component(KTReunionDataSet)you are using?.
Thanks,
Gopal.S
Gopal.S
|
|
|
|
|
OKay, so I am writing a server program that connects many clients and sends them out data. The problem is that when a client disconnects, when trying to read from another client I get the error.."Unable to read data from the transport connection: An established connection was aborted by the software in your host machine."
I have the connections saved in a Dictionary
private Dictionary<TcpClient, string> Connections = new Dictionary<TcpClient, string>();
Connections.Add(tcpClient, currUser);
Connections.Remove(tcpUser);
string message = srReceiver.ReadLine();
tcpServer = new TcpClient();
tcpServer.Connect(IPAddress.Parse(ipaddress), port);
swSender = new StreamWriter(tcpServer.GetStream());
swSender.WriteLine("Whatever");
swSender.Flush();
swSender.WriteLine("Close");
swSender.Flush();
swSender.Close();
tcpServer.Close();
|
|
|
|
|
I wanted to add that the dictionary looks fine after the user has been removed.
And this works fine as long as everyone stays connected
|
|
|
|
|
hi all,
i have 3 devlopers work on a web application using visual studio 2005, i want to add this web application to vss (visual source safe), to decrease the problem between them developers.
can help me about how to add this web application to vss??
thanx all.
|
|
|
|
|
This is not really a C# question.
I think you should be consulting the VSS docuementation before proceeding further.
Here is something that can act as a guide to start using VSS.
|
|
|
|
|
hi,
i worked on vss for windows application and its succeeded, but i can not use it for web, i didn't know why its not work successfuly for web.
can u help me?
thank u
|
|
|
|
|
You have already asked this same question, and received many responses.
Continuing to ask the same question will just get you ignored.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yes, we've recognized you. From the new wording of your question, I deduce that your 3 developers are working concurrently on a live copy of your website (or maybe even THE live website). (that's why all the stuff we told you yesterday didn't work .
This is the stupidest thing I've ever seen. Vss can't help you in this case. The codeproject can't help you. Your personal god may find it a challenge.
|
|
|
|
|
If you have Visual Source Safe installed, go into File > Source Control and then add the projects to Source Safe there.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi
i'm working with dataSetDesigner in my app,lately when i create a new tableAdapter, it's select command is null at runTime, but it configure correctly in dataSetDesigner. where is my problem and how to solve it ?
thanks
|
|
|
|