jump to navigation

Refactoring tool of Visual Studio 2005 September 7, 2007

Posted by addisu in Software - .NET 2.0, Software - .NET General, Software - ASP .NET 2.0, Software - C#.
1 comment so far

How much do u use refactoring tool of Visual Studio 2005?

  • Rename: i probably use this tool more often. Once you declare a class or a variable and used it everywhere, “rename” tool is the best if you are not happy with the name. Naming is one of best practice and the name of a class or a variable should be descriptive. You might not come up with the best name at the beginning.
  • Extract Method: This is another tool i use. Every time there is a reusable portion of code that exist in my method, i used “Extract Method” to have another smaller method. … for two purposes sometimes,..one to reuse the code and two, to make smaller size and readable method
  • Generate Method Stub: even though it is not part of the Refactoring tool part, i like to use this tool. I write a method call to an object that doesn’t exist. I use this tool to generate the method stub. The best part of this tool is, it knows if private or internal or public should be used. … the name and type of parameter, return value…

‘ref’ and ‘out’ in C# is Bizarre and confusing… September 4, 2007

Posted by addisu in Software - .NET 2.0, Software - .NET General, Software - C#.
add a comment

i tried to really see the difference of these key words in C# and i still get it weired.

http://msdn2.microsoft.com/en-us/vcsharp/aa336814.aspx

  • for ‘out’, we can pass the variable unassigned but we have to make sure we assign it before use in the callee method
  • for ‘ref’, we have to assign the variable before we pass it…

i still see both as pass by reference kind of thing…

any suggestions….?

.NET 2.0 Generics, … i am in love with it…. August 24, 2007

Posted by addisu in Software - .NET 2.0, Software - .NET General, Software - C#.
add a comment

I had a number of collection classes with similar functionalities like this…

public class PermissionCollectionEntity : IEntity
{
List<PermissionEntity> list;

public PermissionCollectionEntity()
{
this.list = new List<PermissionEntity>();
}

public List<PermissionEntity> Items
{
get
{
return this.list;
}
}

public void Add(PermissionEntity entity)
{
if (entity != null)
{
this.list.Add(entity);
}
}

public Boolean Remove(PermissionEntity entity)
{
if (entity != null && this.list.Contains(entity))
{
return this.list.Remove(entity);
}
else
{
return false;
}
}

public void RemoveAt(int index)
{
if (this.list.Count > index && index >= 0)
{
this.list.RemoveAt(index);
}
}

public void Clear()
{
if (this.list.Count > 0)
{
this.list.Clear();
}
}

public int Count
{
get
{
return this.list.Count;
}
}
}

Now i am replacing those Collection classes with one Generics class like this…

public class TCollectionEntity<T> : IEntity
where T : IEntity
{
List<T> list;

public TCollectionEntity()
{
this.list = new List<T>();
}

public List<T> Items
{
get
{
return this.list;
}
}

public void Add(T entity)
{
if (entity != null)
{
this.list.Add(entity);
}
}

public Boolean Remove(T entity)
{
if (entity != null && this.list.Contains(entity))
{
return this.list.Remove(entity);
}
else
{
return false;
}
}

public void RemoveAt(int index)
{
if (this.list.Count > index && index >= 0)
{
this.list.RemoveAt(index);
}
}

public void Clear()
{
if (this.list.Count > 0)
{
this.list.Clear();
}
}

public int Count
{
get
{
return this.list.Count;
}
}
}

I can re-use this collection for all my Entity classes…I can also enforce the Entity Classes shouldimpliment certain Interfaces…

Cool stuff…

Using keyword “using” in code block March 3, 2007

Posted by addisu in Software - .NET 2.0, Software - .NET General, Software - ASP .NET 2.0, Software - C#.
2 comments

Recently, I have been asked about the alternative way to Dispose objects as we often do in the “finally” block in “Try .. Catch .. Finally” block for connection object. I have seen “using” keyword in some sample codes but I never aware of it does dispose the objects declared as “using

Example:

using (IDataReader dataReader = _db.ExecuteReader(“GetCategories”))
{
// Processing code
while (dataReader.Read())
{
Category item = new Category(
dataReader.GetInt32(0),
dataReader.GetString(1),
dataReader.GetString(2));
this.cmbCategory.Items.Add(item);
}
}

  1. One thing to note is the objects inside the “using” block should implement “IDisposable” interface.
  2. Still if we want to cache Exception, we need to inside and for me it seems a little bit redundant if we do the dispose inside the “finally” block as we often do for the connection object

Use authorization to establish the rights of an authenticated user in ASP .NET December 8, 2006

Posted by addisu in MCPD Web Developer, Software - .NET 2.0, Software - .NET General, Software - ASP .NET, Software - ASP .NET 2.0, Software - Certifications.
add a comment
  • Manage roles in the Web Site Administration Tool.
  • Ascertain whether a specific user is in role.
  • Get the roles for a specific user by using the Roles object or the User object.
  • Store role information in a cookie.
  • Restrict access to files by using file authorization.
  • Restrict access to portions of an application by using URL authorization.

Summary

The Web Site Administration Tool allows you to manage roles and add users to roles on the security tab.

You can use the Roles Object static method IsUserInRole to determine if a user is a member of a role.

You can get the roles for a specific user by using the GetRolesForUser method of the Roles Object.

You can configure the RoleManager in the web config of the application to store a users role information in a cookie.

To apply authorization rules to a specific file or folder, enclose the <authorization> element inside a <location> element as shown here. The example of how to restrict access to portions of an application using URL authorization is from the resource Security Practices: ASP.NET 2.0 Security Practices at a Glance

<location path="Secure" >

  <system.web>

    <authorization>

      <deny users="?" />

    </authorization>

  </system.web>

</location>

Other Resources & Links:

Web Site Administration Tool Security Tab
http://msdn2.microsoft.com/en-us/library/ssa0wsyf.aspx

Roles Class
http://msdn2.microsoft.com/en-us/library/system.web.security.roles(VS.80).aspx

MembershipUser Class
http://msdn2.microsoft.com/en-us/library/system.web.security.membershipuser(VS.80).aspx

How to Use Role Manager in ASP.Net 2.0
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/paght000013.asp

Security Practices: ASP.NET 2.0 Security Practices at a Glance
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/PAGPractices0001.asp

Forms Authentication for ASP .NET Sub-Directories
http://www.theserverside.net/tt/articles/showarticle.tss?id=FormAuthentication