Posts

Showing posts with the label Class

Simple way to generate C# class from database table

 Use the below sql script to generate c# model corresponding to the table.   Set @TableName to the name of your table.   declare @TableName sysname = 'TableName' declare @Result varchar (max) = 'public class ' + @TableName + '{' select @Result = @Result + ' public ' + ColumnType + NullableSign + ' ' + ColumnName + ' { get; set; }' from ( select replace(col.name, ' ' , '_' ) ColumnName, column_id ColumnId, case typ.name when 'bigint' then 'long' when 'binary' then 'byte[]' when 'bit' then 'bool' when 'char' then 'string' when 'date' then 'DateTime' when 'datetime' then 'DateTime' when 'datetime2' then 'DateTime' when 'datetim

Email Providers

Step 1: Get the NuGet  package    Click here... Step 2 :             string userName = "userName ";             string password = "password ";             var data = SmtpConfig.ForSendGrid(userName, password);             SmtpEmailProvider obj = new SmtpEmailProvider(data);             var email = new Email()             {                 ReceiverName = "ReceiverName ",                 ToAddress = "ToAddress @domain.com",                 SenderName = "SenderName",                 FromAddress = "FromAddress @domain.com",                 Message = "Message ",                 Subject = "Subject ",                 IsHtmlEmail = false              };             var re = obj.Send(email); There are many Smtp setting available. ForGoDaddy ForGmail ForOutlook ForMailGun ForSendGrid Happy Coding... :)

How to get the list of properties of a class?

public List<string> GetPropertiesNameFromClass(object pObject) { List<string> propertyList = new List<string>(); if (pObject != null) { foreach (var prop in pObject.GetType().GetProperties()) { propertyList.Add(prop.Name); } } return propertyList; } public static Dictionary<string, object> GetPropertDictionaryFromClass(object pObject) { if (pObject == null) return new Dictionary<string, object>(); Type t = pObject.GetType(); PropertyInfo[] props = t.GetProperties(); Dictionary<string, object> dict = new Dictionary<string, object>(); foreach (PropertyInfo prp in props) { object value = prp.GetValue(pObject, new object[] { }); dict.Add(prp.Name, value); } return dic