Home Comments

C# classes

Does anyone have an interest in having the ICE class's data members be generated in C# as properties instead of public fields? The advantage is is that you can drop a class object with properties into a property grid & easily view the data. This make debugging [realtime programs] easier. It would be a "nice to have" to have ZeroC implement this as an option [for C# & VB]

Comments

  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    I guess we could make this available as a metadata directive. I considered mapping to properties at one point, but couldn't see any advantage for a type whose code is generated.

    Cheers,

    Michi.
  • semerichsemerich Member
    C# properties instead of public fields

    Having C# public properties instead of public fields is something that we can really benefit from, so I took a stab at it. below is the replacement VisitDataMember in "slice2cs\Gen.cpp file. It seems to work just fine, & the default functionality remains the same. Could this be added to your code baseline ? vb.net would be easy to do also.

    THANKS
    Scott Emerich
    [email protected]


    Slice::Gen::TypesVisitor::visitDataMember(const DataMemberPtr& p)
    {
    int baseTypes = 0;
    bool isClass = false;
    ContainedPtr cont = ContainedPtr::dynamicCast(p->container());
    assert(cont);
    if(StructPtr::dynamicCast(cont) && cont->hasMetaData("clr:class"))
    {
    baseTypes = DotNet::ICloneable;
    }
    else if(ExceptionPtr::dynamicCast(cont))
    {
    baseTypes = DotNet::ApplicationException;
    }
    else if(ClassDefPtr::dynamicCast(cont))
    {
    baseTypes = DotNet::ICloneable;
    isClass = true;
    }
    _out << sp << nl;

    string nameS = fixId(p->name(), baseTypes, isClass);
    string ty = typeToString(p->type());
    if (p->hasMetaData("clr:property") || cont->hasMetaData("clr:property"))
    {
    _out << "private " << ty << " _" << nameS << ";" << nl;
    emitAttributes(p);
    _out << "public " << ty << " " << nameS << nl;
    _out << "{ get { return _" << nameS << "; }" << nl;
    _out << " set { _" << nameS << " = value; } }" << nl;
    }
    else
    {
    emitAttributes(p);
    _out << "public " << ty << " " << nameS << ";";
    }
    }
  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    Thanks for that! I'll add something like this for the next release.

    Cheers,

    Michi.
  • filgoodfilgood Member Filip WuytackOrganization: JS CapitalProject: financial middleware
    properties (getter / setter) of slice2cs generated classes?
    michi wrote: »
    Thanks for that! I'll add something like this for the next release.

    Cheers,

    Michi.


    Hi Michi,

    Was this ever added? I'm evaluating to use Ice here (version 3.5.0), but would be keen to get get; set; properties to be generated by the slice2cs compiler (as I want to keep the slice generated classes in some WPF projects to display them in things like a listbox (don't work with the slice2cs generated classes, but do work if I manually convert those classes to use public properties instead of fields).

    Thanks,

    filgood
  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi Filip,

    You can map attributes to properties using the "clr:property" metadata

    see C-Sharp Mapping for Classes - Ice 3.5 - ZeroC

    Regards,
    Jose
  • filgoodfilgood Member Filip WuytackOrganization: JS CapitalProject: financial middleware
    Many thanks! That solved it.

    ~ filgood
Sign In or Register to comment.