Convert From VB to C#

Last post 02-10-2004 9:52 AM by BonoSoft. 3 replies.

Sort Posts:

  • Convert From VB to C#

    02-10-2004, 8:25 AM
    • Member
      180 point Member
    • Wafi_m
    • Member since 12-10-2003, 3:35 AM
    • Amman-Jordan
    • Posts 41
    Hi There ,,

    I want to know What is the similar code in C# for this Statments

    1. VB.NET :If Not Attribute.IsDefined(paramInfo, GetType(NonCommandParameterAttribute)) Then
    C# : ?

    2. VB.NET :Dim paramAttribute As SqlParameterAttribute = CType(Attribute.GetCustomAttribute(paramInfo, GetType(SqlParameterAttribute)), SqlParameterAttribute)
    C# : ?

    Please answer as soon as possible
    Wafi Mohtaseb
  • Re: Convert From VB to C#

    02-10-2004, 9:14 AM
    • Star
      10,052 point Star
    • Geert
    • Member since 06-18-2002, 11:43 AM
    • The Netherlands
    • Posts 2,011
    Ok, here's what I did :

    - Fire up Google
    - Type in : "convert vb.net to c#"
    - Go to the second link on the first page ....
    - Hit the link convert vb.net to c#
    - Follow link 'Online Demo Version'
    - Type in your statements
    - Look at result


    #1 : if (! Attribute.IsDefined(paramInfo, GetType(NonCommandParameterAttribute))) {

    2# : SqlParameterAttribute paramAttribute = ((SqlParameterAttribute)Attribute.GetCustomAttribute(paramInfo, GetType(SqlParameterAttribute)));

    Hope it works for you

    Geert
    Geert Veenstra
  • Re: Convert From VB to C#

    02-10-2004, 9:36 AM
    • Member
      275 point Member
    • mccloskeym
    • Member since 06-21-2003, 1:35 AM
    • Posts 55
    I can take a stab at this. Obviosly, I am not 100% as I don't know the context of what you are doing. but a straight translation is below :)

    The main difference in the statements you wrote above are in how varibales are defined. The calling of classes and methods are all the same between vb.net & C#. The main thing I noticed is that C# is a little less "codey" - IE - you can create those crazy all in one line strings of craziness ala C++.

    1. if (!Attribute.IsDefined(paramInfo, GetType(NonCommandParameterAttribute)))
    {
    //if yes
    }
    else
    {
    //if no
    }

    2. SqlParameterAttribute paramAttribute = ((string)(Attribute.GetCustomAttribute(paramInfo, GetType(SqlParameterAttribute)), typeof(SqlParameterAttribute)));

    I hope this helps some.

    Thx,
    Michael
  • Re: Convert From VB to C#

    02-10-2004, 9:47 AM
    • Participant
      955 point Participant
    • BonoSoft
    • Member since 06-16-2003, 2:00 PM
    • Denmark
    • Posts 191

    private void GenerateCommandParameters(SqlCommand command,MethodInfo method,object[] values) {
    ParameterInfo[] methodParameters = method.GetParameters();
    int paramIndex = 0;
    foreach (ParameterInfo paramInfo in methodParameters) {
    if (!Attribute.IsDefined(paramInfo, typeof(NonCommandParameterAttribute))) {
    SqlParameterAttribute paramAttribute = (SqlParameterAttribute)Attribute.GetCustomAttribute(paramInfo, typeof(SqlParameterAttribute));
    if (paramAttribute==null) {
    paramAttribute = new SqlParameterAttribute();
    }
    /Bo Norgaard ( dotnetnuke.dk )
Page 1 of 1 (4 items)