My Proposals for c# 7.0
1: REFLECTION ON PURE DYNAMIC INSTANCE
Expected Behavior:
list members
Actual Behavior:
error
2: CLASS SERIALIZATION
`
// NOTHING IN THIS CLASS IS MADE FOR SERIALIZATION PURPOSE
public class SmthgVeryComplicatedThatIDontKnowWithManyProperties
{
//...
}
public class SerializationTest
{
public byte[] Serialize(object smthg)
{
}
[System.UniversalFunction]
float someCoolFunctionWithoutClass()
{
}
public static int Main()
{
var smthg = new SmthgVeryComplicatedThatIDontKnowWithManyProperties();
// would be so cool if whatever the object is, we could just serialize the memory of it and unwrap it
//back later. Would be greater as well working with dynamic things loaded at runtime.
var serialized = Serialize(smthg);
string serializedUniversalFunction = SerializeFunction(someCoolFunctionWithoutClass);
console.WriteLine(serializedUniversalFunction);
// output idk some nicely arranged data describing function that is easy to parse and eval in another
// language, and bindings in many languages.
// function should not contains types that dont have [System.UniversalClass] attribute
// Generics have universal bindings, if Element Type has System.UniversalClass attribute, and
// int, float, etc.. have universal bindings too.
// for, while, etc... have universal binding too.
// lot of things not usable but would be so cool if we could just send a function to a javascript
// server/client, unpack it and use it.
}
}
`
3: MORE REFLECTION TOOLS
`
public class HasManyMethods
{
public void Method1(){return;};
public void Method2(int smthg, float smthgelse){return;};
public int Method3(int smthg)
{
return (smthg * 2);
}
}
public class Program
{
public static int Main()
{
HasManyMethods test = new HasManyMethods();
MethodInfo[] methods = test.GetType().GetMethods();
MethodInfo method = methods[0];
* Console.WriteLine(method.name + method.lineNumber + method.fileName + method.text); *
}
}
`
System.Reflection.Emit namespace.yea but if c# has native things to serialize root binary data of object graph would be cool.
its a bad idea right now, of course, but for example, javascript can serialize a whole object without knowing a shit about it.
bad ideas are only bad ideas until they run well with correct implementation. Store each references persistently if needed, maybe a parameter of compilation would do it, idk, so peoples arent forced to use it.
Why not save references persistently? Maybe some binary file used with programs targetting that type of things.
Also, ability to make dump of a whole program would be cool too.
maybe add maps of object graphs from the begining and know a reference is only a reference of object having refs... value type members...
i talked about ref 512254... we serialize ref 512254, he talk about ref 521424, we allready spoke about ref 521424...
and add options to not serialize references, not serialize references of type, not serialize until that lvl of deepness in ref
edit: and graphs maps automatically generate protocol buffer templates used later for serializations/deserialization
edit1: that would be cool for user side scripts use, like in game engines, modelization engines/tools etc... that i love to do.
edit2: add a big math/physic/graphic/pathfinding/self learning library to System, that'd support either opengl or latest direct x (just a boolean to change), with really high lvl bindings. (And, make use of graphic card for most calculations, when possible)
edit3: also add direct support for socket.io(client AND server)
edit4: do all that and i think c# become the best language ever, and i think world technology/games/tools explose from everywhere.
Whoa, whoa slow down a bit.
bad ideas are only bad ideas until they run well with correct implementation. Store each references persistently if needed, maybe a parameter of compilation would do it, idk, so peoples arent forced to use it.
The reason it is bad difficult is because ref 1234 in my machine right will not be the same as any of these:
You would need to store persistent copies of every object that was referenced by a serialized object. This is not impossible, in fact it is very common. But it involves a database that lives outside of the process, which turns this from a serialization technique into an ORM
Another concern with this is what about objects that need initialization or special setup. Some objects require certain constructors or init methods to make them valid according to business rules. Also what about objects that look like this:
C#
class myAnnoyingType
{
private readonly string MyMachineName = System.Diagnostics.Process.Current.Id;
...
}
This type holds data that assumes it the PID will not change, and moving it out of process could violate that assumption.
I am assuming that when the .Net BCL design team was looking at serialization, they assumed that it was only really safe to serialize types you had control over (and therefore could mark them ISerializable) and a few simple primitives and collections.
Also, ability to make dump of a whole program would be cool too.
It would hypothetically be powerful and useful to dump a whole program and send it to another machine, but i think real world objects that could depend on machine/process local data would not always be safe to freeze and ship anywhere in this manner.
maybe add maps of object graphs from the beginning and know a reference is only a reference of object having refs... value type members... i talked about ref 512254... we serialize ref 512254, he talk about ref 521424, we already spoke about ref 521424...
This is a common pattern today, except instead of moving the objects directly, the reference is a Primary Key in a database that is passed around. Now purely for the sake of argument i could imagine a type of shared memory space where you can call objects across the wire transparently and i think it would-.
Wait a minute, that is .Net remoting. You're asking basically for .Net remoting i think.
edit2: add a big math/physic/graphic/pathfinding/self learning library to System, that'd support either opengl or latest direct x (just a boolean to change), with really high lvl bindings. (And, make use of graphic card for most calculations, when possible)
This kind of request should be in dotnet/CoreFX. But is probably best left as 3rd party libraries and NuGet packages.
edit3: also add direct support for socket.io(client AND server)
Does System.Net.Sockets not work well enough for your usecase? Or what about the super fast libuv based socket work in aspnet/Kestrel
edit4: do all that and i think c# become the best language ever, and i think world technology/games/tools explode from everywhere.
C# is many things to many people, but it cannot be everything to everyone and nobody is completely happy with it i would imagine. Picking the correct set of features is very very difficult and needs to balance a lot of things, most notably time and resources. Eric Lippert has written a lot about these problems.
As a contrast I wanted Destructible Types and Move to make C# 7 awesome but...well...it didn't make it.
C# 7.0 is pretty much locked up right now. You can feel free to propose stuff for future versions. You might want to start by breaking this up into multiple separate proposals and target them specifically as what components would be effected. Include use cases. You'll also be expected to actually provide implementation details.
I don't see much here that has anything to do with C# or the Roslyn compiler.
1 is already handled by dynamic modules and reflection. It's pretty easy to emit completely dynamic types with dynamically constructed methods. And you can reflect over those methods just like you could any other assembly.
2 sounds like it belongs in the corefx repo, although it is fairly vague. Most of it sounds like it would be covered by binary serialization, which has always existed in the full framework but doesn't currently exist in the core framework.
3 sounds like it could apply to Roslyn, but it could probably be covered by generators by emitting replacement methods which have attributes to the original source file locations. Or corefx could add helpers which can correlate assemblies with their debugging symbol databases. As for the original function text, why exactly do you think that would be useful? What if the assembly is compiled in one of the other several dozen BCL-targeting languages?
@HaloFour
1: yea but use that emit things is damn boring. (but i ll look at it for more arguments, just using .GetType().GetProperties() would be better.
2: yea, but i think serializations apis are really boring right now, even the ones from the framework.
If serialization fail, exception, and cant set parameters or what to tell to just ignore them.
I dont know maybe im wrong but i had very bad experiences trying to make user scripts serialized well without asking them to put attributes over each things.
3: if the assembly is compiled in one of the other several dozen BCL-targeting languages, so it would not work to get the function text, no problem.
why i think it would be useful: i write actually a typescript/nodejs server, with logic frames, to work with Unity3D.
@gdefraiteur I reformatted your original post
make a class in a dll loaded at runtime
use an instance of the class with reflection to list class members
Expected Behavior:
list members
Actual Behavior:
error
// NOTHING IN THIS CLASS IS MADE FOR SERIALIZATION PURPOSE
public class SmthgVeryComplicatedThatIDontKnowWithManyProperties
{
//...
}
public class SerializationTest
{
public byte[] Serialize(object smthg)
{
}
[System.UniversalFunction]
float someCoolFunctionWithoutClass()
{
}
public static int Main()
{
var smthg = new SmthgVeryComplicatedThatIDontKnowWithManyProperties();
// would be so cool if whatever the object is, we could just serialize the memory of it and unwrap it
//back later. Would be greater as well working with dynamic things loaded at runtime.
var serialized = Serialize(smthg);
string serializedUniversalFunction = SerializeFunction(someCoolFunctionWithoutClass);
Console.WriteLine(serializedUniversalFunction);
// output idk some nicely arranged data describing function that is easy to parse and eval in another
// language, and bindings in many languages.
// function should not contains types that dont have [System.UniversalClass] attribute
// Generics have universal bindings, if Element Type has System.UniversalClass attribute, and
// int, float, etc.. have universal bindings too.
// for, while, etc... have universal binding too.
// lot of things not usable but would be so cool if we could just send a function to a javascript
// server/client, unpack it and use it.
}
}
public class HasManyMethods
{
public void Method1(){return;};
public void Method2(int smthg, float smthgelse){ return; }
public int Method3(int smthg)
{
return (smthg * 2);
}
}
public class Program
{
public static int Main()
{
HasManyMethods test = new HasManyMethods();
MethodInfo[] methods = test.GetType().GetMethods();
MethodInfo method = methods[0];
Console.WriteLine(method.name + method.lineNumber + method.fileName + method.text);
}
}
Also @gdefraiteur,
For runtime code generation, have you looked at the Sigil Library?
And for the reflection helpers, do the newish Caller Info Attributes?
@amcasey Would some of the interactive facilities satisfy this request?
@gafter, @tmat might have a more up-to-date understanding of the implementation and goals of the interactive facilities.
C# 7 is now closed to additional features. If there are specific features that you would like included in future versions, please open a separate issue for each.