Jump to content

  • Log In with Google      Sign In   
  • Create Account

Leandro GR

Member Since 27 Sep 2007
Online Last Active Today, 01:45 PM

Posts I've Made

In Topic: Why "double declare" classes? (Lack of better terminology)

12 December 2013 - 07:19 AM

Speaking of C# that's because variable declaration and object instantiation are two different things

Here we are just declaring a variable of type List<T>
List<T> myList;

It has no value, and is not initialized, it can't be used unless it's used in an out parameter

What would happen if it automatically create a new instance of the object just by declaring it? If it was a value type, like an int or float there would be no problem at all, but it would never work for a reference type.

First of all a reference type may not have a parameterless constructor, or it could be an abstract class or even an Interface, there would be no way to initialize then this way, or it could have no public constructors at all, what if it uses some kind of factory class to initialize the objects?

And of course, what if you just want the variable to receive an instance from somewhere else? You do not always want a new object, sometimes you will receive it as a parameter or from calling some other function

So you say it's a "List<T>", but how can the compiler know you really want a "new List<T>" and not an existing one, or some other object that inherits from List<T>? What if you really want a new List<T> but you want it to be created by a function that initializes it with some values?

In Topic: about style - why use hex instead of int in this function

25 September 2013 - 09:07 AM

I just think it's way easier to write and read this
enum MyFlags
{
    Flag1 = 0x1,
    Flag2 = 0x2,
    Flag3 = 0x4,
    Flag4 = 0x8,
    Flag5 = 0x10,
    Flag6 = 0x20,
    Flag7 = 0x40,
    Flag8 = 0x80
}
Than this
enum MyFlags
{
    Flag1 = 1,
    Flag2 = 2,
    Flag3 = 4,
    Flag4 = 8,
    Flag5 = 16,
    Flag6 = 32,
    Flag7 = 64,
    Flag8 = 128
}
Both ways are easy to do, if I use decimal I just have to double the last value, but with hexadecimal I just have to remember the sequence 1, 2, 4 and 8 as it will just repeat itself over and over, just adding zeros to the end

In Topic: MEF and releasing imports.

26 July 2013 - 07:08 AM

It's been a while since I worked with MEF but I think the problem is that you put the PartCreationPolicy in your custom attribute, it should be directly in the exported class, base class or interface.

In Topic: C# Constrained Generic's and derived static methods.

06 April 2013 - 08:48 AM

Have you ever considered using a custom attribute? If the value is static you could get the custom attribute on OtherClass<T> static constructor and hold it in a static field for later use, this way you only have to do it once for each type of OtherClass<T>

In Topic: [.net] Bitwise check - best way?

08 February 2008 - 12:42 AM

You are only missing one nice feature of .Net, the FlagsAttribute

[Flags]
public enum DataType
{
None=0,
Vertex=1,
Index = 2,
UV = 4,
XYZ = 8,
Norm = 16
}




If you have something like

DataType dt = DataType.Vertex | DataType.Index;

If you are not using the FlagsAttribute, when you check the value while debugging or when you use the ToString you will see the value 3, as expected, but with FlagsAttribute you will see the value "Vertex | Index" while debugging and ToString will return "Vertex, Index" instead of 3, so you don't have to figure out which bits are set while debugging.

PARTNERS