diff --git a/cpp/include/Slice/CsUtil.h b/cpp/include/Slice/CsUtil.h index 28c8b57..ca935b3 100644 --- a/cpp/include/Slice/CsUtil.h +++ b/cpp/include/Slice/CsUtil.h @@ -34,6 +34,7 @@ public: protected: static std::string fixId(const std::string&, int = 0, bool = false); + static std::string fixId(const ContainedPtr&, int = 0, bool = false); static std::string typeToString(const TypePtr&); static bool isValueType(const TypePtr&); diff --git a/cpp/src/Slice/CsUtil.cpp b/cpp/src/Slice/CsUtil.cpp index 061033b..387de74 100755 --- a/cpp/src/Slice/CsUtil.cpp +++ b/cpp/src/Slice/CsUtil.cpp @@ -130,6 +130,21 @@ Slice::CsGenerator::fixId(const string& name, int baseTypes, bool mangleCasts) } string +Slice::CsGenerator::fixId(const ContainedPtr& cont, int baseTypes, bool mangleCasts) +{ + ContainerPtr container = cont->container(); + ContainedPtr contained = ContainedPtr::dynamicCast(container); + if(contained && contained->hasMetaData("clr:property")) + { + return cont->name() + "_prop"; + } + else + { + return fixId(cont->name(), baseTypes, mangleCasts); + } +} + +string Slice::CsGenerator::typeToString(const TypePtr& type) { if(!type) @@ -476,7 +491,10 @@ Slice::CsGenerator::writeMarshalUnmarshalCode(Output &out, else { string typeS = typeToString(type); - out << nl << param << " = new " << typeS << "();"; + if(param.size() < 6 || param.substr(param.size() - 5) != "_prop") + { + out << nl << param << " = new " << typeS << "();"; + } if(streamingAPI) { out << nl << param << ".ice_read(" << stream << ");"; diff --git a/cpp/src/slice2cs/Gen.cpp b/cpp/src/slice2cs/Gen.cpp index 5f83f8f..80c096b 100755 --- a/cpp/src/slice2cs/Gen.cpp +++ b/cpp/src/slice2cs/Gen.cpp @@ -728,8 +728,7 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) _out << nl << "os__.startWriteSlice();"; for(d = members.begin(); d != members.end(); ++d) { - writeMarshalUnmarshalCode(_out, (*d)->type(), - fixId((*d)->name(), DotNet::ICloneable, true), + writeMarshalUnmarshalCode(_out, (*d)->type(), fixId(*d, DotNet::ICloneable, true), true, false, false); } _out << nl << "os__.endWriteSlice();"; @@ -831,8 +830,7 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) patchParams << ", " << classMemberCount++; } } - writeMarshalUnmarshalCode(_out, (*d)->type(), - fixId((*d)->name(), DotNet::ICloneable, true), + writeMarshalUnmarshalCode(_out, (*d)->type(), fixId(*d, DotNet::ICloneable, true), false, false, false, patchParams.str()); } _out << nl << "is__.endReadSlice();"; @@ -850,8 +848,7 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) _out << nl << "outS__.startSlice();"; for(d = members.begin(); d != members.end(); ++d) { - writeMarshalUnmarshalCode(_out, (*d)->type(), - fixId((*d)->name(), DotNet::ICloneable, true), + writeMarshalUnmarshalCode(_out, (*d)->type(), fixId(*d, DotNet::ICloneable, true), true, true, false); } _out << nl << "outS__.endSlice();"; @@ -877,8 +874,7 @@ Slice::CsVisitor::writeDispatchAndMarshalling(const ClassDefPtr& p, bool stream) patchParams << ", " << classMemberCount++; } } - writeMarshalUnmarshalCode(_out, (*d)->type(), - fixId((*d)->name(), DotNet::ICloneable, true), + writeMarshalUnmarshalCode(_out, (*d)->type(), fixId(*d, DotNet::ICloneable, true), false, true, false, patchParams.str()); } _out << nl << "inS__.endSlice();"; @@ -2187,8 +2183,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out << nl << "os__.startWriteSlice();"; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - writeMarshalUnmarshalCode(_out, (*q)->type(), - fixId((*q)->name(), DotNet::ApplicationException), + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId(*q, DotNet::ApplicationException), true, false, false); } _out << nl << "os__.endWriteSlice();"; @@ -2295,8 +2290,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) patchParams << ", " << classMemberCount++; } } - writeMarshalUnmarshalCode(_out, (*q)->type(), - fixId((*q)->name(), DotNet::ApplicationException), + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name(), DotNet::ApplicationException), false, false, false, patchParams.str()); } _out << nl << "is__.endReadSlice();"; @@ -2314,8 +2308,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) _out << nl << "outS__.startSlice();"; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - writeMarshalUnmarshalCode(_out, (*q)->type(), - fixId((*q)->name(), DotNet::ApplicationException), + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name(), DotNet::ApplicationException), true, true, false); } _out << nl << "outS__.endSlice();"; @@ -2345,8 +2338,7 @@ Slice::Gen::TypesVisitor::visitExceptionEnd(const ExceptionPtr& p) patchParams << ", " << classMemberCount++; } } - writeMarshalUnmarshalCode(_out, (*q)->type(), - fixId((*q)->name(), DotNet::ApplicationException), + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId((*q)->name(), DotNet::ApplicationException), false, true, false, patchParams.str()); } _out << nl << "inS__.endSlice();"; @@ -2457,6 +2449,8 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << eb; } + bool propertyMapping = p->hasMetaData("clr:property"); + _out << sp << nl << "public " << name << spar; vector paramDecl; vector paramNames; @@ -2471,7 +2465,12 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << sb; for(vector::const_iterator i = paramNames.begin(); i != paramNames.end(); ++i) { - _out << nl << "this." << *i << " = " << *i << ';'; + _out << nl << "this." << *i; + if(propertyMapping) + { + _out << "_prop"; + } + _out << " = " << *i << ';'; } _out << eb; @@ -2595,8 +2594,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << sb; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - writeMarshalUnmarshalCode(_out, (*q)->type(), - fixId((*q)->name(), isClass ? DotNet::ICloneable : 0), + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId(*q, isClass ? DotNet::ICloneable : 0), true, false, false); } _out << eb; @@ -2688,8 +2686,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) patchParams << ", " << classMemberCount++; } } - writeMarshalUnmarshalCode(_out, (*q)->type(), - fixId((*q)->name(), isClass ? DotNet::ICloneable : 0 ), + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId(*q, isClass ? DotNet::ICloneable : 0 ), false, false, false, patchParams.str()); } _out << eb; @@ -2700,8 +2697,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) _out << sb; for(q = dataMembers.begin(); q != dataMembers.end(); ++q) { - writeMarshalUnmarshalCode(_out, (*q)->type(), - fixId((*q)->name(), isClass ? DotNet::ICloneable : 0), + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId(*q, isClass ? DotNet::ICloneable : 0), true, true, false); } _out << eb; @@ -2721,8 +2717,7 @@ Slice::Gen::TypesVisitor::visitStructEnd(const StructPtr& p) patchParams << ", " << classMemberCount++; } } - writeMarshalUnmarshalCode(_out, (*q)->type(), - fixId((*q)->name(), isClass ? DotNet::ICloneable : 0 ), + writeMarshalUnmarshalCode(_out, (*q)->type(), fixId(*q, isClass ? DotNet::ICloneable : 0 ), false, true, false, patchParams.str()); } _out << eb;