.net-2.0

How can I expose only a fragment of IList<>?

痴心易碎 提交于 2019-12-03 17:22:57
问题 I have a class property exposing an internal IList<> through System.Collections.ObjectModel.ReadOnlyCollection<> How can I pass a part of this ReadOnlyCollection<> without copying elements into a new array (I need a live view, and the target device is short on memory)? I'm targetting Compact Framework 2.0. 回答1: Try a method that returns an enumeration using yield: IEnumerable<T> FilterCollection<T>( ReadOnlyCollection<T> input ) { foreach ( T item in input ) if ( /* criterion is met */ )

migratordotnet - Run migrations from within application (w/o nant or build)

匆匆过客 提交于 2019-12-03 16:38:52
问题 is there a way to run migrations from within the application itself? Thanks! 回答1: I instantiate an instance of the Migrator class, and then you can call member methods like MigrateToLastVersion() or MigrateTo(long versionnr) Migrator.Migrator m = new Migrator.Migrator ("SqlServer", connectionString, migrationsAssembly) m.MigrateToLastVersion(); 回答2: I don't see why not. Have a look at the nant task http://code.google.com/p/migratordotnet/source/browse/trunk/src/Migrator.NAnt/MigrateTask.cs

.NET 2.0 Setup Project in Visual Studio 2008

血红的双手。 提交于 2019-12-03 16:30:55
I developed a win forms app targeting .net 2.0. All of this is in Visual Studio 2008 sp1. I did this because I didn't really need 3.0+ features in the app. and I didn't want the clients to have to install a gigantic framework when they could just install a semi-huge one. Well, when I create a setup project for the app, build it, install it, it wants me to install .net 3.5. I am targeting 2.0 in both the windows app and the setup project. Is it possible to make the setup project with only a prerequisite of 2.0 in VS 2008? Yes. By default a setup project in VS2008 will want to include the 3.5

Can we add parameter in datatable.select in c#

坚强是说给别人听的谎言 提交于 2019-12-03 16:19:20
I like to know is it possible to add parameter in datatable.select(expression).For example string query="Name=@Name"; //dt is comming from database. dt.Select(query); How to add this parameter @Name . I need to compare a value which contains single quote and it gets failed in the above case. Thanks in advance You can use String.Format , you need to escape single quotes with two: string query = string.Format("Name='{0}'", name.Replace(@"'", "''")); var rows = dt.Select(query); or, if you want to use Like : string query = string.Format("Name LIKE '%{0}%'", name.Replace(@"'", "''")); (note that a

Implementing conditional in a fluent interface

*爱你&永不变心* 提交于 2019-12-03 15:41:32
I've been trying to implement a fluent interface for a set of rules in my system. What I am trying to accomplish is this TicketRules .RequireValidation() .When(quartType => quartType == QuartType.Before).TotalMilageIs(64) .When(quartType => quartType == QuartType.After).TotalMilageIs(128); However, I have trouble implementing the When conditional how I intended to be. Currently, I need to call When() twice like in this snippet: rules.When(param => param.Remarque == "Test").TotalMilageIs(100); rules.When(param => param.Remarque == "Other").TotalMilageIs(50); var params1 = new

string array.Contains?

点点圈 提交于 2019-12-03 15:07:59
问题 .NET 2 string[] myStrings = GetMyStrings(); string test = "testValue"; How can I verify if myStrings contains test ? 回答1: In .NET 2.0, you could do the following if you want the index: int index = Array.FindIndex( myStrings, delegate(string s) { return s.Equals(test); } ); index will be -1 if myStrings does not contain test . If you merely want to check for existence: bool exists = Array.Exists( myStrings, delegate(string s) { return s.Equals(test); } ); 回答2: I have found an elegant answer at

Difference between EventLog.WriteEntry and EventLog.WriteEvent methods

£可爱£侵袭症+ 提交于 2019-12-03 14:28:16
问题 I tried using WriteEntry and WriteEvent methods of EventLog class. EventLog.WriteEntry("Saravanan", "Application logs an entry", EventLogEntryType.Information, 2, 3); EventLog.WriteEvent("Saravanan", new EventInstance(2, 3), "Application logs an event"); Both output the same result. Is there any difference in usage of these methods? If there are only minor difference, why was it not done through a overload of either WriteEvent() or WriteEntry() methods, instead of introducing a new method?

Exception error message with incorrect line number

人盡茶涼 提交于 2019-12-03 14:01:25
When an exception is thrown in an Asp.Net web page, an error message is displayed with the complete stack trace. Example below: Stack Trace: IndexOutOfRangeException: Index was outside the bounds of the array. MyNameSpace.SPAPP.ViewDetailsCodeBehind.LoadView() +5112 MyNameSpace.SPAPP.ViewDetailsCodeBehind.Page_Load(Object sender, EventArgs e) +67 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +43 System.Web.UI.Control.OnLoad(EventArgs e) +98 ... ... The

Winform user authorization via active directory

浪尽此生 提交于 2019-12-03 13:11:59
问题 I have a situation where I am using the following code to verify user membership in AD before executing tasks in my app using System.Security.Principal; WindowsIdentity identity = WindowsIdentity.GetCurrent(); WindowsPrincipal principal = new WindowsPrincipal(identity); return principal.IsInRole("someGroup"); The above code works fine for machines on my domain, however I do have some machines which are not on my domain on which I have the WINFORM application installed. How can I verify the

Updating images in resource section of an exe (in c#/C)

一笑奈何 提交于 2019-12-03 13:10:08
I have few images embedded in my executable in resource section. I followed these steps to create my executable: Generated .resx file for all the images (.jpg) in a directory using some utility. The images are named image1.jpg, image2.jpg and so on. created .resources file from .resx file using: resgen myResource.resx Embedded the generated .resource file using /res flag as: csc file.cs /res:myResource.resources 4 I am accessing these images as: ResourceManager resources = new ResourceManager("myResource", Assembly.GetExecutingAssembly()); Image foo = (System.Drawing.Image)(resources.GetObject