|
MSDNBest PracticesHow To's
Cheat Sheets
Prebuilt code from Microsoft
Visual Studio Addons
Other
modified 7-Oct-17 9:47am.
|
|
|
|
|
Security related
- TACO[^], tracking blocker or altenatively; Ghostery[^], tracking-blocker 2
- MVPS HOSTS file[^]
Easiest way to block a lot of annoying websites. It's a plain text file, goes in a special location to have Windows use it.
- Namebench[^]
DNS Benchmark, also indicates whether key-websites have been hijacked. Suggested by OriginalGriff in the Free Tools[^] forum
GeneralCoding Tools
Portable Apps
modified 31-May-13 7:35am.
|
|
|
|
|
Bastard Programmer from Hell
modified 10-Jun-12 17:00pm.
|
|
|
|
|
Bastard Programmer from Hell
modified 12-Aug-19 11:15am.
|
|
|
|
|
General
TCP/IP
Tracing/analysis tools
Profilers
Bastard Programmer from Hell
modified 12-Sep-13 5:14am.
|
|
|
|
|
Bastard Programmer from Hell
|
|
|
|
|
15% of my work is coding, 30% is refactoring that mess again, 20% to add to the testing, 20% documentation, 15% is research/walking around thinking/reading/talking..
This "folder" is focussing mainly on questions and resources on refactoring. A technical scrapbook
To warm things up, consider the code below;
if (value != null) return value;
return defaultvalue;
this is functional equivalent with this;
if (value != null)
{
return value;
}
else
{
return defaultvalue;
}
return (value == null)
? defaultvalue
: value;
These are a mere three variations of the same code.
I are Troll
|
|
|
|
|
return value ?? defaultvalue;
|
|
|
|
|
This is the place where I'm going to organize code that's not ready to be entered / suited for a trick. The toolbox that I'm using most
|
|
|
|
|
Sometimes you'd temporarily want to change the value of a variable, and the most common pattern is probably the one below;
string temp = someObject.SomeValue;
someObject.SomeValue = "Updating, call again later";
try
{
}
finally
{
someObject.SomeValue = temp;
}
I'm currently working in VB.NET, and it would seem like a dandy idea to be able to do something like the pattern below;
Imports System
Imports SubSystem
Public Class SomeLogger
Public CategoryName As String = "None Specified"
Public Sub DoLog(ByVal SomeText As String)
Console.WriteLine("{0}: {1}", CategoryName, SomeText)
End Sub
End Class
Public Class Application
Public Shared Logger As New SomeLogger
Public Shared Sub Main()
Logger.DoLog("Hello World")
Using Temporary.Override(Logger, "CategoryName", "Sub Main")
Logger.DoLog("Hello World")
End Using
Logger.DoLog("Hello World")
End Sub
End Class
Well, that's possible. Temporary is a static class, returning an IDisposable that wraps the property on said object. When the computer leaves the Using statement, the IDisposable will reflect the original value back, even if we exit the procedure by throwing a new exception.
The actual implementation as a reference;
using System;
using System.Collections;
using System.Reflection;
using System.IO;
using System.ComponentModel;
namespace SubSystem
{
public class Temporary
{
public static IDisposable Override (Object aObject, String aMemberName, Object aScopedValue)
{
return init (aMemberName, aObject.GetType (), aObject, aScopedValue);
}
public static IDisposable Override (Type aType, String aMemberName, Object aScopedValue)
{
return init (aMemberName, aType, null, aScopedValue);
}
static IDisposable init (String aMemberName, Type aType, Object aObject, Object aScopedValue)
{
MemberInfo memberInfo = aType.GetMember (aMemberName)[0];
switch (memberInfo.MemberType)
{
case MemberTypes.Property:
return new TemporaryOverrideProperty (
aObject == null ? aType : aObject,
(PropertyInfo)memberInfo,
aScopedValue);
case MemberTypes.Field:
return new TemporaryOverrideField (
aObject == null ? aType : aObject,
(FieldInfo)memberInfo,
aScopedValue);
default:
throw new NotSupportedException ();
}
}
}
public class TemporaryOverrideProperty : TemporaryOverride
{
PropertyInfo _overridenProperty;
public TemporaryOverrideProperty(Object aObject, PropertyInfo aProperty, Object aScopedValue)
{
this._sourceObject = aObject;
this.init(aProperty, aScopedValue);
}
public TemporaryOverrideProperty(Type aSource, PropertyInfo aProperty, Object aScopedValue)
{
this._sourceClass = aSource;
this.init(aProperty, aScopedValue);
}
~TemporaryOverrideProperty()
{
this.Dispose(false);
}
void init(PropertyInfo aProperty, Object aScopedValue)
{
this._overridenProperty = aProperty;
this._originalValue = this._overridenProperty.GetValue(this._sourceObject, null);
this._overridenProperty.SetValue(this._sourceObject, aScopedValue, null);
}
protected override void Dispose(Boolean disposing)
{
if (disposing)
{
this._overridenProperty.SetValue(this._sourceObject, this._originalValue, null);
}
base.Dispose(disposing);
}
}
public class TemporaryOverrideField : TemporaryOverride
{
FieldInfo _overridenField;
public TemporaryOverrideField(Object aObject, FieldInfo aField, Object aScopedValue)
{
this._sourceObject = aObject;
this.init(aField, aScopedValue);
}
public TemporaryOverrideField(Type aSource, FieldInfo aField, Object aScopedValue)
{
this._sourceClass = aSource;
this.init(aField, aScopedValue);
}
~TemporaryOverrideField()
{
this.Dispose(false);
}
void init(FieldInfo aField, Object aScopedValue)
{
this._overridenField = aField;
this._originalValue = this._overridenField.GetValue(this._sourceObject);
this._overridenField.SetValue(this._sourceObject, aScopedValue);
}
protected override void Dispose(Boolean disposing)
{
if (disposing)
{
this._overridenField.SetValue(this._sourceObject, this._originalValue);
}
base.Dispose(disposing);
}
}
public class TemporaryOverride : IDisposable
{
protected Object _sourceObject;
protected Type _sourceClass;
protected Object _originalValue;
protected TemporaryOverride()
{
}
#region IDisposable implementation (MSDN adapted version)
Boolean disposed = false;
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(Boolean disposing)
{
if (!this.disposed)
{
if (disposing)
{
}
this.disposed = true;
}
}
#endregion
}
}
I are Troll
|
|
|
|
|
Imports System
Imports System.Collections
Imports System.Reflection
Imports System.IO
Imports System.ComponentModel
Namespace SubSystem
Public Class Temporary
Public Shared Function Override(aObject As [Object], aMemberName As [String], aScopedValue As [Object]) As IDisposable
Return init(aMemberName, aObject.[GetType](), aObject, aScopedValue)
End Function
Public Shared Function Override(aType As Type, aMemberName As [String], aScopedValue As [Object]) As IDisposable
Return init(aMemberName, aType, Nothing, aScopedValue)
End Function
Private Shared Function init(aMemberName As [String], aType As Type, aObject As [Object], aScopedValue As [Object]) As IDisposable
Dim memberInfo As MemberInfo = aType.GetMember(aMemberName)(0)
Select Case memberInfo.MemberType
Case MemberTypes.[Property]
Return New TemporaryOverrideProperty(If(aObject Is Nothing, aType, aObject), DirectCast(memberInfo, PropertyInfo), aScopedValue)
Case MemberTypes.Field
Return New TemporaryOverrideField(If(aObject Is Nothing, aType, aObject), DirectCast(memberInfo, FieldInfo), aScopedValue)
Case Else
Throw New NotSupportedException()
End Select
End Function
End Class
Public Class TemporaryOverrideProperty
Inherits TemporaryOverride
Private _overridenProperty As PropertyInfo
Public Sub New(aObject As [Object], aProperty As PropertyInfo, aScopedValue As [Object])
Me._sourceObject = aObject
Me.init(aProperty, aScopedValue)
End Sub
Public Sub New(aSource As Type, aProperty As PropertyInfo, aScopedValue As [Object])
Me._sourceClass = aSource
Me.init(aProperty, aScopedValue)
End Sub
Protected Overrides Sub Finalize()
Try
Me.Dispose(False)
Finally
MyBase.Finalize()
End Try
End Sub
Private Sub init(aProperty As PropertyInfo, aScopedValue As [Object])
Me._overridenProperty = aProperty
Me._originalValue = Me._overridenProperty.GetValue(Me._sourceObject, Nothing)
Me._overridenProperty.SetValue(Me._sourceObject, aScopedValue, Nothing)
End Sub
Protected Overrides Sub Dispose(disposing As [Boolean])
If disposing Then
Me._overridenProperty.SetValue(Me._sourceObject, Me._originalValue, Nothing)
End If
MyBase.Dispose(disposing)
End Sub
End Class
Public Class TemporaryOverrideField
Inherits TemporaryOverride
Private _overridenField As FieldInfo
Public Sub New(aObject As [Object], aField As FieldInfo, aScopedValue As [Object])
Me._sourceObject = aObject
Me.init(aField, aScopedValue)
End Sub
Public Sub New(aSource As Type, aField As FieldInfo, aScopedValue As [Object])
Me._sourceClass = aSource
Me.init(aField, aScopedValue)
End Sub
Protected Overrides Sub Finalize()
Try
Me.Dispose(False)
Finally
MyBase.Finalize()
End Try
End Sub
Private Sub init(aField As FieldInfo, aScopedValue As [Object])
Me._overridenField = aField
Me._originalValue = Me._overridenField.GetValue(Me._sourceObject)
Me._overridenField.SetValue(Me._sourceObject, aScopedValue)
End Sub
Protected Overrides Sub Dispose(disposing As [Boolean])
If disposing Then
Me._overridenField.SetValue(Me._sourceObject, Me._originalValue)
End If
MyBase.Dispose(disposing)
End Sub
End Class
Public Class TemporaryOverride
Implements IDisposable
Protected _sourceObject As [Object]
Protected _sourceClass As Type
Protected _originalValue As [Object]
Protected Sub New()
End Sub
#Region "IDisposable implementation (MSDN adapted version)"
Private disposed As [Boolean] = False
Public Sub Dispose() Implements IDisposable.Dispose
Me.Dispose(True)
GC.SuppressFinalize(Me)
End Sub
Protected Overridable Sub Dispose(disposing As [Boolean])
If Not Me.disposed Then
If disposing Then
End If
Me.disposed = True
End If
End Sub
#End Region
End Class
End Namespace
Bastard Programmer from Hell
|
|
|
|
|
Usage;
using (new ScopeSupportInitialize(someISupportInitializeControl)
{
...
}
Instead of
someISupportInitializeControl.BeginInit();
...
someISupportInitializeControl.EndInit();
By doing the same trick again;
using System;
using System.ComponentModel;
public class ScopedSupportInitialize : IDisposable
{
bool disposed = false;
ISupportInitialize _owner;
public ScopedSupportInitialize(ISupportInitialize AOwner)
{
if (AOwner == null) throw new ArgumentNullException("AOwner");
_owner = AOwner;
_owner.BeginInit();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.disposed)
{
if (disposing)
{
_owner.EndInit();
}
disposed = true;
}
}
}
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
class Program
{
public delegate object BakeDel(object[] values);
public class SomeBO
{
int someInt;
public int SomeInt
{
get
{
return someInt;
}
}
SomeBO()
{
}
public SomeBO(object[] values)
{
this.someInt = (int)values[1];
}
public static object Bake(object[] values)
{
return new SomeBO(values);
}
}
static void Main(string[] args)
{
object[] vals = new object[3];
vals[0] = "Hello";
vals[1] = 2;
vals[2] = "world";
SomeBO bo;
int numberOfIterations = 500000;
int theClock = Environment.TickCount;
for (int i = 0; i < numberOfIterations; i++)
{
bo = new SomeBO(vals);
}
Console.WriteLine("Native 'new' statement took {0} ms", (Environment.TickCount - theClock));
theClock = Environment.TickCount;
for (int i = 0; i < numberOfIterations; i++)
{
bo = (SomeBO)Activator.CreateInstance(typeof(SomeBO), new object[] { vals });
}
Console.WriteLine("Activator took {0} ms", (Environment.TickCount - theClock));
Console.ReadKey();
theClock = Environment.TickCount;
ConstructorInfo ci = typeof(SomeBO).GetConstructor(new Type[] { typeof(object[]) });
for (int i = 0; i < numberOfIterations; i++)
{
bo = (SomeBO)ci.Invoke(new object[] { vals });
}
Console.WriteLine("Constructor took {0} ms", (Environment.TickCount - theClock));
Console.ReadKey();
theClock = Environment.TickCount;
Delegate myBakingDelegate = Delegate
.CreateDelegate(typeof(BakeDel), typeof(SomeBO), "Bake", true);
if (myBakingDelegate != null)
{
BakeDel myLocalBaker = (BakeDel)myBakingDelegate;
for (int i = 0; i < numberOfIterations; i++)
{
bo = (SomeBO)myLocalBaker(vals);
}
}
Console.WriteLine("Bakery took {0} ms", (Environment.TickCount - theClock));
Console.ReadKey();
}
}
Results, on my machine:
Native 'new' statement took 15 ms
Activator took 6459 ms
Constructor took 2902 ms
Bakery took 31 ms
|
|
|
|
|
Interop with .NET, tested with Lazarus;
library project1;
uses
Classes;
procedure DoHelloWorld(var Source: string) stdcall; export;
begin
Source := 'Hello world :)';
end;
exports DoHelloWorld;
begin
end.
Imports System.Runtime.InteropServices
Imports System.Text
Module Module1
<DllImport("project1.dll", EntryPoint:="DoHelloWorld", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Ansi)> _
Public Sub DoHelloWorld(ByRef Source As StringBuilder)
End Sub
Sub Main()
Dim sb As New StringBuilder()
DoHelloWorld(sb)
Console.WriteLine(sb.ToString())
Console.ReadKey()
End Sub
End Module
Bastard Programmer from Hell
|
|
|
|
|
One would replace the string-constants in below code to resources or settings, but this is the default template I'm using to read values from a list returned by the database;
var dbProviderFactory = (System.Data.Common.DbProviderFactory)
System.Data.Common.DbProviderFactories.GetFactory(
"System.Data.SqlClient");
using (var con = dbProviderFactory.CreateConnection())
{
con.ConnectionString = "Server=.;Trusted_Connection=True;";
using (var cmd = con.CreateCommand())
{
cmd.CommandText = @"
SELECT *
FROM AdventureWorks.Person.Contact
WHERE ModifiedDate > @ModifiedDate";
var modifiedDateParam = cmd.CreateParameter();
modifiedDateParam.ParameterName = "@ModifiedDate";
modifiedDateParam.Value = new DateTime(year: 2001, month: 1, day: 1);
cmd.Parameters.Add(modifiedDateParam);
con.Open();
using (var rdr = cmd.ExecuteReader(
System.Data.CommandBehavior.CloseConnection))
{
while (rdr.Read())
{
Console.WriteLine(String.Format(
"{0}, {1}",
rdr["FirstName"],
rdr["LastName"]));
}
}
}
} Comments on this boring pattern are welcomed
My 'itch' is that the IDbCommand doesn't have an Parameter.AddWithValue option. So, I created an method-extension;
public static void CreateParamWithValue(
this System.Data.IDbCommand cmd,
string pParamName,
object pValue)
{
System.Data.IDbDataParameter p = cmd.CreateParameter();
p.ParameterName = pParamName;
p.Value = pValue;
cmd.Parameters.Add(p);
}
to reduce the parameter-part to something that we're more used to;
cmd.CommandText = @"
SELECT *
FROM AdventureWorks.Person.Contact
WHERE ModifiedDate > @ModifiedDate";
cmd.CreateParamWithValue("@ModifiedDate", new DateTime(year: 2001, month: 1, day: 1));
con.Open();
Bastard Programmer from Hell
|
|
|
|
|
Partial implementation of an about-box, related to the AttributionAttribute[^];
public partial class MyAboutBox : Form
{
Assembly _entryAssembly = Assembly.GetEntryAssembly();
T getAttribute<T>() where T: System.Attribute
{
object[] attributes = _entryAssembly.GetCustomAttributes(typeof(T), false);
if (attributes.Length == 0)
{
return default(T);
}
return ((T)attributes[0]);
}
public MyAboutBox()
{
InitializeComponent();
this.Text = String.Format("About {0}", AssemblyTitle);
this.labelProductName.Text = AssemblyProduct;
this.labelVersion.Text = String.Format("Version {0}", AssemblyVersion);
this.labelCopyright.Text = AssemblyCopyright;
this.labelCompanyName.Text = AssemblyCompany;
this.textBoxDescription.Text = AssemblyDescription;
this.dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
foreach (AttributionAttribute aa in protoTyping.fetch())
{
int newRowIdx = this.dataGridView1.RowCount;
this.dataGridView1.RowCount++;
this.dataGridView1[0, newRowIdx].Value = aa.Author;
this.dataGridView1[0, newRowIdx].ToolTipText = aa.AuthorLink;
this.dataGridView1[1, newRowIdx].Value = aa.ContributionTitle;
this.dataGridView1[1, newRowIdx].ToolTipText = aa.ContributionLink;
}
}
void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
string link = this.dataGridView1[e.ColumnIndex, e.RowIndex].ToolTipText;
System.Diagnostics.Process.Start(link);
}
#region Assembly Attribute Accessors
public string AssemblyTitle
{
get
{
var a = getAttribute<AssemblyTitleAttribute>();
return a.Title;
}
}
public string AssemblyVersion
{
get
{
return _entryAssembly.GetName().Version.ToString();
}
}
public string AssemblyDescription
{
get
{
var a = getAttribute<AssemblyDescriptionAttribute>();
return a.Description;
}
}
public string AssemblyProduct
{
get
{
var a = getAttribute<AssemblyProductAttribute>();
return a.Product;
}
}
public string AssemblyCopyright
{
get
{
var a = getAttribute<AssemblyCopyrightAttribute>();
return a.Copyright;
}
}
public string AssemblyCompany
{
get
{
var a = getAttribute<AssemblyCompanyAttribute>();
return a.Company;
}
}
#endregion
}
Bastard Programmer from Hell
|
|
|
|
|
using System;
using System.Text;
using System.Collections.Generic;
namespace MyBigInt
{
class Program
{
public static void Main(string[] args)
{
Random rnd = new Random(DateTime.Now.Millisecond);
long t1 = rnd.Next(0, 99999);
long t2 = rnd.Next(0, 99999);
MyBigInt bi1 = new MyBigInt(t1.ToString());
MyBigInt bi2 = new MyBigInt(t2.ToString());
MyBigInt addition = bi1 + bi2;
MyBigInt multiplication = bi1 * bi2;
Console.WriteLine("Verification: {0} + {1} = {2}", t1, t2, (t1 + t2));
Console.WriteLine("MyBigInt: {0} + {1} = {2}", bi1, bi2, addition);
Console.WriteLine(string.Empty);
Console.WriteLine("Verification: {0} * {1} = {2}", t1, t2, (t1 * t2));
Console.WriteLine("MyBigInt: {0} * {1} = {2}", bi1, bi2, multiplication);
Console.WriteLine(string.Empty);
Console.WriteLine("Any key for a big test :)\n");
Console.ReadKey(true);
string t3 = string.Empty;
string t4 = string.Empty;
StringBuilder builder = new StringBuilder(50);
for (int i = 0; i < 50; i++)
builder.Append(rnd.Next(0, 9));
t3 = builder.ToString();
builder = new StringBuilder(50);
for (int i = 0; i < 50; i++)
builder.Append(rnd.Next(0, 9));
t4 = builder.ToString();
MyBigInt bi3 = new MyBigInt(t3);
MyBigInt bi4 = new MyBigInt(t4);
Console.WriteLine("Huge addition:\n {0}\n + {1}\n = {2}\n", bi3, bi4, bi3 + bi4);
Console.WriteLine("\nHuge multiplication:\n {0}\n * {1}\n = {2}", bi3, bi4, bi3 * bi4);
Console.WriteLine(string.Empty);
Console.WriteLine("Any key closes :)");
Console.ReadKey(true);
}
}
class MyBigInt
{
string _value;
public MyBigInt(string value)
{
_value = value;
}
public MyBigInt() : this("0") { }
public static MyBigInt operator +(MyBigInt b1, MyBigInt b2)
{
string result = string.Empty;
if (b1.Size < b2.Size)
{
MyBigInt b3 = b2;
b2 = b1;
b1 = b3;
}
int d1, d2;
string sumD1D2;
string d3;
int c = 0;
for (int idx1 = 1; idx1 <= b1.Size; idx1++)
{
d1 = b1.GetDigit(idx1);
d2 = b2.GetDigit(idx1);
sumD1D2 = (d1 + d2 + c).ToString();
d3 = sumD1D2.Substring(sumD1D2.Length - 1, 1);
result = d3 + result;
if (sumD1D2.Length > 1)
c = int.Parse(sumD1D2.Remove(sumD1D2.Length - 1, 1));
else
c = 0;
}
return new MyBigInt((c == 0 ? "" : c.ToString()) + result);
}
public static MyBigInt operator *(MyBigInt b1, MyBigInt b2)
{
string result = string.Empty;
if (b1.Size < b2.Size)
{
MyBigInt b3 = b2;
b2 = b1;
b1 = b3;
}
int d1, d2;
string sumD1D2;
string d3;
int c = 0;
List<MyBigInt> sumList = new List<MyBigInt>();
for (int idx2 = 1; idx2 <= b1.Size; idx2++)
{
c = 0;
result = string.Empty;
for (int idx1 = 1; idx1 <= b2.Size; idx1++)
{
d1 = b1.GetDigit(idx2);
d2 = b2.GetDigit(idx1);
sumD1D2 = ((d1 * d2) + c).ToString();
d3 = sumD1D2.Substring(sumD1D2.Length - 1, 1);
result = d3 + result;
if (sumD1D2.Length > 1)
c = int.Parse(sumD1D2.Remove(sumD1D2.Length - 1, 1));
else
c = 0;
}
MyBigInt subTtl = new MyBigInt((c == 0 ? "" : c.ToString()) + result + new string('0', idx2 - 1));
sumList.Add(subTtl);
}
MyBigInt grandTotal = new MyBigInt("0");
foreach (MyBigInt subTotal in sumList)
grandTotal += subTotal;
return grandTotal;
}
int GetDigit(int index)
{
if (Size - index < 0)
return 0;
if (Size - index > _value.Length)
return 0;
return _value[Size - index] - '0';
}
public int Size
{
get { return _value.Length; }
}
public override string ToString()
{
return _value;
}
}
}
Bastard Programmer from Hell
|
|
|
|
|
Exceptions are not "expensive". Yes, they slow the application down if a debugger is attached, but the average user usually runs without a debugger attached. Exceptions might be expensive if you are writing some optimized low-level graphic routines, but not for the average application. In almost all cases, the alternative to using exceptions is worse.
Let's have a little test-application;
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
long i = 0;
sw.Start();
while (sw.ElapsedMilliseconds < 1000)
{
try
{
throw new Exception();
}
catch
{
i++;
}
}
long e = sw.ElapsedMilliseconds;
Console.WriteLine(string.Format("{0} exceptions thrown and caught in {1} ms", i, e));
Console.ReadKey();
}
}
Throws 67 exceptions (on my machine*) per second if a debugger is attached. Throws 49830 exceptions in 1000 ms without the debugger.
*) i3 @180 Ghz
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Well, while I agree with you, there's not much call stack involved in your code, so it's pretty much just demonstrating the overhead that's caused by the debugger -- which is great, people need to know that.
It still remains that developers have to test what they write and choose what they prefer -- and no one should blindly follow what the "experts" say.
|
|
|
|
|
Thanks for the confirmation
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
DECLARE @TableName AS VARCHAR(4000)
SET @TableName = <table_name,,'EmployeeTable'>
SELECT COLUMN_NAME
, DATA_TYPE
, IS_NULLABLE
, CHARACTER_MAXIMUM_LENGTH
, COLUMN_DEFAULT
, [value] AS [MS_Description]
FROM INFORMATION_SCHEMA.COLUMNS is_c,
::fn_listextendedproperty
(NULL, 'user', 'dbo', 'table', @TableName, 'column', default) p
WHERE TABLE_NAME = @TableName
AND objname COLLATE Latin1_General_CI_AI = COLUMN_NAME COLLATE Latin1_General_CI_AI
AND name = 'MS_Description'
ORDER BY ORDINAL_POSITION ASC;
Fetches some basic metadata for a table in Sql Server 2000+
I are Troll
|
|
|
|
|
SELECT *
FROM sysobjects
WHERE xtype='U'
AND name NOT IN
(
SELECT object_name(parent_obj)
FROM sysobjects
WHERE xtype = 'PK'
)
Sql 2000+
I are Troll
|
|
|
|
|
SELECT *
FROM sysobjects
WHERE xtype='U'
AND name NOT IN
(
SELECT object_name(id)
FROM sysindexes
WHERE indid = 1
)
ORDER BY 1
I are Troll
|
|
|
|
|
Ooohhh... now bring in Extended Properties.
(I experimented with that a while back.)
|
|
|
|
|
Public Sub SearchGoogle()
DTE.ItemOperations.Navigate( _
"http://www.google.com/search?q=" & GetSelectedWord())
End Sub
Public Sub SearchMsdn()
DTE.ItemOperations.Navigate( _
"http://www.google.com/search?btnI=I%27m+Feeling+Lucky&hl-en&q=site%3Amsdn.microsoft.com+" & _
GetSelectedWord())
End Sub
Private Function GetSelectedWord() As String
Dim selection As TextSelection = DTE.ActiveDocument.Selection()
If selection.Text <> "" Then
Return selection.Text
Else
DTE.ExecuteCommand("Edit.SelectCurrentWord")
selection = DTE.ActiveDocument.Selection()
Return selection.Text
End If
End Function
SearchGoogle does as implied, SearchMsdn is using the "Feeling Lucky" feature to jump to (hopefully) MSDN.
To assign their hotkey's;
- Go to the menu Tools / Options
- Select "Environment, Keyboard" from the categories
- In the box labeled "Show commands containing", type "Googl"
- Select the Macro from the list
- Click the box labeled "Press shortcut keys", and press
F1
- Click the "Assign" button (!)
- Assign'd
Shift-F1 to MSDN.
I are Troll
|
|
|
|
|