protected override void AddPredefinedMethods(PredefinedMethods pm) { string clrType = _t.CLRName + (_t.IsValueType ? "" : "^"); // For operator == if ((PredefinedMethods.Equals & pm) != 0) { _sb.AppendLine("virtual bool Equals(Object^ obj) override;"); _sb.AppendLine("bool Equals(" + clrType + " obj);"); _sb.AppendLine("static bool operator == (" + clrType + " obj1, " + clrType + " obj2);"); _sb.AppendLine("static bool operator != (" + clrType + " obj1, " + clrType + " obj2);"); } // For operator = if ((PredefinedMethods.CopyTo & pm) != 0) { _sb.AppendLine("void CopyTo(" + clrType + " dest)"); _sb.AppendLine("{"); _sb.IncreaseIndent(); _sb.AppendLine("if (_native == NULL) throw gcnew Exception(\"The underlying native object for the caller is null.\");"); _sb.AppendLine("if (dest" + (_t.IsValueType ? "." : "->") + "_native == NULL) throw gcnew ArgumentException(\"The underlying native object for parameter 'dest' is null.\");"); _sb.AppendLine(); _sb.AppendLine("*(dest" + (_t.IsValueType ? "." : "->") + "_native) = *_native;"); _sb.DecreaseIndent(); _sb.AppendLine("}"); } }
public IncludePredefinedMethodAttribute(PredefinedMethods methods) { Methods = methods; }
public static IncludePredefinedMethodAttribute FromElement(XmlElement elem) { PredefinedMethods pm = (PredefinedMethods)Enum.Parse(typeof(PredefinedMethods), elem.InnerText, true); return(new IncludePredefinedMethodAttribute(pm)); }
protected override void AddPredefinedMethods(PredefinedMethods pm) { string cls = GetClassName(); switch (pm) { case PredefinedMethods.Equals: _sb.AppendLine("bool " + cls + "::Equals(Object^ obj)"); _sb.AppendLine("{"); _sb.AppendLine(" " + cls + "^ clr = dynamic_cast<" + cls + "^>(obj);"); _sb.AppendLine(" if (clr == CLR_NULL)"); _sb.AppendLine(" {"); _sb.AppendLine(" return false;"); _sb.AppendLine(" }\n"); _sb.AppendLine(" if (_native == NULL) throw gcnew Exception(\"The underlying native object for the caller is null.\");"); _sb.AppendLine(" if (clr->_native == NULL) throw gcnew ArgumentException(\"The underlying native object for parameter 'obj' is null.\");"); _sb.AppendLine(); _sb.AppendLine(" return " + GetNativeInvokationTargetObject() + " == *(static_cast<" + _t.FullNativeName + "*>(clr->_native));"); _sb.AppendLine("}\n"); if (!_t.HasWrapType(WrapTypes.NativePtrValueType)) { _sb.AppendLine("bool " + cls + "::Equals(" + cls + "^ obj)"); _sb.AppendLine("{"); _sb.AppendLine(" if (obj == CLR_NULL)"); _sb.AppendLine(" {"); _sb.AppendLine(" return false;"); _sb.AppendLine(" }\n"); _sb.AppendLine(" if (_native == NULL) throw gcnew Exception(\"The underlying native object for the caller is null.\");"); _sb.AppendLine(" if (obj->_native == NULL) throw gcnew ArgumentException(\"The underlying native object for parameter 'obj' is null.\");"); _sb.AppendLine(); _sb.AppendLine(" return " + GetNativeInvokationTargetObject() + " == *(static_cast<" + _wrapper.NativeNamespace + "::" + cls + "*>(obj->_native));"); _sb.AppendLine("}"); _sb.AppendLine(); _sb.AppendLine("bool " + cls + "::operator ==(" + cls + "^ obj1, " + cls + "^ obj2)"); _sb.AppendLine("{"); _sb.IncreaseIndent(); _sb.AppendLine("if ((Object^)obj1 == (Object^)obj2) return true;"); _sb.AppendLine("if ((Object^)obj1 == nullptr || (Object^)obj2 == nullptr) return false;"); _sb.AppendLine(); _sb.AppendLine("return obj1->Equals(obj2);"); _sb.DecreaseIndent(); _sb.AppendLine("}"); _sb.AppendLine(); _sb.AppendLine("bool " + cls + "::operator !=(" + cls + "^ obj1, " + cls + "^ obj2)"); _sb.AppendLine("{"); _sb.AppendLine("\treturn !(obj1 == obj2);"); _sb.AppendLine("}"); } else { _sb.AppendLine("bool " + cls + "::Equals(" + cls + " obj)"); _sb.AppendLine("{"); _sb.AppendLine(" if (_native == NULL) throw gcnew Exception(\"The underlying native object for the caller is null.\");"); _sb.AppendLine(" if (obj._native == NULL) throw gcnew ArgumentException(\"The underlying native object for parameter 'obj' is null.\");"); _sb.AppendLine(); _sb.AppendLine(" return *_native == *obj._native;"); _sb.AppendLine("}"); _sb.AppendLine(); _sb.AppendLine("bool " + cls + "::operator ==(" + cls + " obj1, " + cls + " obj2)"); _sb.AppendLine("{"); _sb.AppendLine("\treturn obj1.Equals(obj2);"); _sb.AppendLine("}"); _sb.AppendLine(); _sb.AppendLine("bool " + cls + "::operator !=(" + cls + " obj1, " + cls + " obj2)"); _sb.AppendLine("{"); _sb.AppendLine("\treturn !obj1.Equals(obj2);"); _sb.AppendLine("}"); } break; } }
protected virtual void AddPredefinedMethods(PredefinedMethods pm) { }
public IncludePredefinedMethodAttribute(PredefinedMethods methods) { this.Methods = methods; }
protected virtual void GenerateCodePredefinedMethods(PredefinedMethods pm) { }