How to write a plug

Apr 21, 2012 at 11:28 AM

I want to write a plug but it doesn't work. I already read this: http://www.codeproject.com/Articles/220076/Csharp-Open-Source-Managed-Operating-System-Intro

I already write a plug and it worked:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.IL2CPU.Plugs;

namespace Cosmos.System.Plugs.System
{
    [Plug(Target=typeof(global::System.Environment))]
    public static class EnvImpl
    {
        public static string CurrentDirectory
        {
            get
            {
                return "Bla";
            }
        }
    }
}

But when i try to implement this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.IL2CPU.Plugs;

namespace Cosmos.System.Plugs.System
{
    [Plug(Target=typeof(global::System.ValueType))]
    public class ValueTypeImpl
    {
        public static int GetHashCode()
        {
            return 0;
        }
    }
}
it doesn't work.

Coordinator
Apr 21, 2012 at 11:31 AM
That's because the signature of the plug method is not correct. for instance methods, you need to have a first parameter which is the instance.

As you're trying to plug ValueType, have a look at how this is done for Int32.ToString for example..


On Sat, Apr 21, 2012 at 1:28 PM, WiiPlayer2 <notifications@codeplex.com> wrote:

From: WiiPlayer2

I want to write a plug but it doesn't work. I already read this: http://www.codeproject.com/Articles/220076/Csharp-Open-Source-Managed-Operating-System-Intro

I already write a plug and it worked:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.IL2CPU.Plugs;

namespace Cosmos.System.Plugs.System
{
    [Plug(Target=typeof(global::System.Environment))]
    public static class EnvImpl
    {
        public static string CurrentDirectory
        {
            get
            {
                return "Bla";
            }
        }
    }
}

But when i try to implement this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.IL2CPU.Plugs;

namespace Cosmos.System.Plugs.System
{
    [Plug(Target=typeof(global::System.ValueType))]
    public class ValueTypeImpl
    {
        public static int GetHashCode()
        {
            return 0;
        }
    }
}
it doesn't work.

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Developer
Apr 21, 2012 at 2:26 PM

With a value type, the 'this' parameter needs to be declared as 'ref'. This is because the 'this' parameters of value types are passed as managed pointers internally. Reference type objects however, pass the actual reference, and thus, don't need the 'ref' parameter. Also, don't just return 0 for the hash code of a value type, that will mess up every hash table in existence. (perhaps use a simple overflow addition over the size of the data?)

Apr 21, 2012 at 3:06 PM

Thanks! It worked!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.IL2CPU.Plugs;

namespace Cosmos.System.Plugs.System
{
    [Plug(Target=typeof(global::System.ValueType))]
    public class ValueTypeImpl
    {
        public static int GetHashCode(ValueType aThis)
        {
            return 0;
        }
    }
}

But when i try the ref parameter

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.IL2CPU.Plugs;

namespace Cosmos.System.Plugs.System
{
    [Plug(Target=typeof(global::System.ValueType))]
    public class ValueTypeImpl
    {
        public static int GetHashCode(ref ValueType aThis)
        {
            return 0;
        }
    }
}

it doesn't work.

Later i will not only return 0. At the moment i only want to implement this.

Coordinator
Apr 22, 2012 at 7:52 AM
"it doesn't work" -> what happens? errors? Please be more detailed..


What could be a problem, is that ValueTYpe is not considered a valuetype, and therefore cannot be a ref parameter, not sure though. need to get the error first...


On Sat, Apr 21, 2012 at 5:06 PM, WiiPlayer2 <notifications@codeplex.com> wrote:

From: WiiPlayer2

Thanks! It worked!

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Cosmos.IL2CPU.Plugs; namespace Cosmos.System.Plugs.System { [Plug(Target=typeof(global::System.ValueType))] public class
ValueTypeImpl { public static int GetHashCode(ValueType aThis) { return 0; } } }

But when i try the ref parameter

using System; using System.Collections.Generic; using System.Linq; using System.Text; using Cosmos.IL2CPU.Plugs; namespace Cosmos.System.Plugs.System { [Plug(Target=typeof(global::System.ValueType))] public class
ValueTypeImpl { public static int GetHashCode(ref ValueType aThis) { return 0; } } }

it doesn't work.

Later i will not only return 0. At the moment i only want to implement this.

Read the full discussion online.

To add a post to this discussion, reply to this email (Cosmos@discussions.codeplex.com)

To start a new discussion for this project, email Cosmos@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com