SQLITE > Get all tables
SELECT name FROM sqlite_master WHERE type='table'
Search This Blog
Friday, July 29, 2016
Friday, July 8, 2016
SQLite C# Example
C# > SQLite
SQLiteConnection.CreateFile("MyDatabase.sqlite");
SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();
string sql = "create table
project (name varchar(100), id int)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into project (name, id) values ('project 1',
1)";
command = new SQLiteCommand(sql,
m_dbConnection);
command.ExecuteNonQuery();
sql = "select * from project order by id desc";
command = new SQLiteCommand(sql,
m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("Name: " + reader["name"] + "\tScore:
" + reader["id"]);
Wednesday, June 29, 2016
PlantUML Set ForeColor and BackColor
PlantUML > Set ForeColor and BackColor
Font Color in Participants
This example will set font color to white and background color to some custom color.
participant "<color:#white>Setup" as Setup #FD9A00
Etichete:
PlantUML
Tuesday, June 7, 2016
C# get property value from object using reflection
C# > Reflection > Property Info > GetValue
Returns the property value of a specified object.
Example
Get property value from object using reflection.
Returns the property value of a specified object.
Example
Get property value from object using reflection.
private static object GetPropValue(object src, string propName)
{
return src.GetType().GetProperty(propName).GetValue(src, null);
}
Etichete:
c#
Tuesday, April 5, 2016
Validate Data Models Using DataAnnotations Attributes C#
C# > System > ComponentModel > DataAnnotations
Provides attribute classes that are used to define metadata.
Example
Validate property class with range numbers
Provides attribute classes that are used to define metadata.
Example
Validate property class with range numbers
using System;
using System.ComponentModel.DataAnnotations;
using System.Windows.Forms;
namespace WindowsFormsApplication8
{
public class Person
{
private int id;
[Display(Name = "Person Id")]
[Range(0, 1000)]
public int Id
{
get { return id; }
set
{
Validator.ValidateProperty(value,
new ValidationContext(this, null, null) { MemberName = "Id" });
id = value;
}
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Person p = new Person();
p.Id = 1;
p.Id = 1001;
}
}
}
Etichete:
c#
Wednesday, March 23, 2016
Rename files from a folder C#
C# > Files > File Class > Move
Moves a specified file to a new location.
- option to specify a new file name
Example
Rename files from a folder
DirectoryInfo d = new DirectoryInfo(@"D:\folder");
FileInfo[] infos = d.GetFiles("*.*");
int i = 1;
foreach (FileInfo f in infos)
{
File.Move(f.FullName, Path.Combine(f.DirectoryName, + i.ToString() + ".jpg"));
i++;
}
Etichete:
c#
Friday, March 11, 2016
Mock Assembly Unit Test C#
C# > Unit tests > Mock Assembly
If you try to mock
var mock = new Mock<Assembly>();
You will get this error:
The type System.Reflection.Assembly implements ISerializable, but failed to provide a deserialization constructor
Solution
Mock _Assembly interface instead of Assembly class.
If you try to mock
var mock = new Mock<Assembly>();
You will get this error:
The type System.Reflection.Assembly implements ISerializable, but failed to provide a deserialization constructor
Solution
Mock _Assembly interface instead of Assembly class.
var mock = new Mock<_Assembly>();
mock.Setup(w => w.GetTypes()).Throws(new Exception());
Etichete:
c#
Subscribe to:
Posts (Atom)