本文整理汇总了C#中Function.AddElement方法的典型用法代码示例。如果您正苦于以下问题:C# Function.AddElement方法的具体用法?C# Function.AddElement怎么用?C# Function.AddElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Function
的用法示例。
在下文中一共展示了Function.AddElement方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateGetNextInstanceMethodCode
protected virtual void GenerateGetNextInstanceMethodCode(Function getNextInstanceMethod)
{
getNextInstanceMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", getNextInstanceMethod.Parameter[0].Name);
getNextInstanceMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", getNextInstanceMethod.Parameter[1].Name);
getNextInstanceMethod.AddCodeFormat("LWIP_UNUSED_ARG({0});", getNextInstanceMethod.Parameter[2].Name);
VariableDeclaration returnValue = new VariableDeclaration((VariableType)getNextInstanceMethod.ReturnType.Clone(), LwipDefs.Def_ErrorCode_NoSuchInstance);
returnValue.Type.Name = "err";
getNextInstanceMethod.Declarations.Add(returnValue);
StringBuilder indexColumns = new StringBuilder();
foreach (SnmpScalarNode indexNode in this.indexNodes)
{
indexColumns.AppendFormat(
" {0} ({1}, OID length = {2})\n",
indexNode.Name,
indexNode.DataType,
(indexNode.OidRepresentationLen >= 0) ? indexNode.OidRepresentationLen.ToString() : "variable");
}
if (indexColumns.Length > 0)
{
indexColumns.Length--;
getNextInstanceMethod.Declarations.Insert(0, new Comment(String.Format(
"The instance OID of this table consists of following (index) column(s):\n{0}",
indexColumns)));
}
string augmentsHint = "";
if (!String.IsNullOrWhiteSpace(this.augmentedTableRow))
{
augmentsHint = String.Format(
"This table augments table '{0}'! Index columns therefore belong to table '{0}'!\n" +
"You may simply call the '*{1}' method of this table.\n\n",
(this.augmentedTableRow.ToLowerInvariant().EndsWith("entry")) ? this.augmentedTableRow.Substring(0, this.augmentedTableRow.Length-5) : this.augmentedTableRow,
LwipDefs.FnctSuffix_GetNextInstance);
}
getNextInstanceMethod.AddElement(new Comment(String.Format(
"TODO: analyze '{0}->id'/'{0}->len' and return the subsequent row instance\n" +
"Be aware that '{0}->id'/'{0}->len' must not point to a valid instance or have correct instance length.\n" +
"If '{0}->len' is 0, return the first instance. If '{0}->len' is longer than expected, cut superfluous OID parts.\n" +
"If a valid next instance is found, store it in '{0}->id'/'{0}->len' and set '{1} = {2};'\n\n" +
"snmp_oid_* methods may be used for easier processing of oid\n\n" +
"{3}" +
"In order to avoid decoding OID a second time in subsequent get_value/set_test/set_value methods,\n" +
"you may store an arbitrary value (like a pointer to target value object) in '{4}->reference'/'{4}->reference_len'.\n" +
"But be aware that not always a subsequent method is called -> Do NOT allocate memory here and try to release it in subsequent methods!\n\n" +
"You also may replace function pointers in '{4}' param for get/test/set methods which contain the default values from table definition,\n" +
"in order to provide special methods, for the currently processed cell. Changed pointers are only valid for current request.",
getNextInstanceMethod.Parameter[1].Name,
returnValue.Type.Name,
LwipDefs.Def_ErrorCode_Ok,
augmentsHint,
getNextInstanceMethod.Parameter[2].Name
)));
getNextInstanceMethod.AddElement(new Comment(String.Format(
"For easier processing and getting the next instance, you may use the 'snmp_next_oid_*' enumerator.\n" +
"Simply pass all known instance OID's to it and it returns the next valid one:\n\n" +
"{0} state;\n" +
"{1} result_buf;\n" +
"snmp_next_oid_init(&state, {2}->id, {2}->len, result_buf, LWIP_SNMP_OBJ_ID_LEN);\n" +
"while ({{not all instances passed}}) {{\n" +
" {1} test_oid;\n" +
" {{fill test_oid to create instance oid for next instance}}\n" +
" snmp_next_oid_check(&state, test_oid->id, test_oid->len, {{target_data_ptr}});\n" +
"}}\n" +
"if(state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {{\n" +
" snmp_oid_assign(row_oid, result_buf->oid, result_buf->len);\n" +
" {3}->reference.ptr = state.reference; //==target_data_ptr, for usage in subsequent get/test/set\n" +
" {4} = {5};\n" +
"}}"
,
LwipDefs.Vt_StNextOidState,
LwipDefs.Vt_StObjectId,
getNextInstanceMethod.Parameter[1].Name,
getNextInstanceMethod.Parameter[2].Name,
returnValue.Type.Name,
LwipDefs.Def_ErrorCode_Ok
)));
getNextInstanceMethod.AddCodeFormat("return {0};", returnValue.Type.Name);
}
示例2: GenerateGetInstanceMethodCode
protected virtual void GenerateGetInstanceMethodCode(Function getInstanceMethod)
{
VariableDeclaration returnValue = new VariableDeclaration((VariableType)getInstanceMethod.ReturnType.Clone(), LwipDefs.Def_ErrorCode_NoSuchInstance);
returnValue.Type.Name = "err";
getInstanceMethod.Declarations.Add(returnValue);
int instanceOidLength = 0;
StringBuilder indexColumns = new StringBuilder();
foreach (SnmpScalarNode indexNode in this.indexNodes)
{
if (instanceOidLength >= 0)
{
if (indexNode.OidRepresentationLen >= 0)
{
instanceOidLength += indexNode.OidRepresentationLen;
}
else
{
// at least one index column has a variable length -> we cannot perform a static check
instanceOidLength = -1;
}
}
indexColumns.AppendFormat(
" {0} ({1}, OID length = {2})\n",
indexNode.Name,
indexNode.DataType,
(indexNode.OidRepresentationLen >= 0) ? indexNode.OidRepresentationLen.ToString() : "variable");
}
if (indexColumns.Length > 0)
{
indexColumns.Length--;
getInstanceMethod.Declarations.Insert(0, new Comment(String.Format(
"The instance OID of this table consists of following (index) column(s):\n{0}",
indexColumns)));
}
string augmentsHint = "";
if (!String.IsNullOrWhiteSpace(this.augmentedTableRow))
{
augmentsHint = String.Format(
"This table augments table '{0}'! Index columns therefore belong to table '{0}'!\n" +
"You may simply call the '*{1}' method of this table.\n\n",
(this.augmentedTableRow.ToLowerInvariant().EndsWith("entry")) ? this.augmentedTableRow.Substring(0, this.augmentedTableRow.Length-5) : this.augmentedTableRow,
LwipDefs.FnctSuffix_GetInstance);
}
CodeContainerBase ccb = getInstanceMethod;
if (instanceOidLength > 0)
{
IfThenElse ite = new IfThenElse(String.Format("{0} == {1}", getInstanceMethod.Parameter[2].Name, instanceOidLength));
getInstanceMethod.AddElement(ite);
ccb = ite;
}
ccb.AddCodeFormat("LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[0].Name);
ccb.AddCodeFormat("LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[1].Name);
if (instanceOidLength <= 0)
{
ccb.AddCodeFormat("LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[2].Name);
}
ccb.AddCodeFormat("LWIP_UNUSED_ARG({0});", getInstanceMethod.Parameter[3].Name);
ccb.AddElement(new Comment(String.Format(
"TODO: check if '{0}'/'{1}' params contain a valid instance oid for a row\n" +
"If so, set '{2} = {3};'\n\n" +
"snmp_oid_* methods may be used for easier processing of oid\n\n" +
"{4}" +
"In order to avoid decoding OID a second time in subsequent get_value/set_test/set_value methods,\n" +
"you may store an arbitrary value (like a pointer to target value object) in '{5}->reference'/'{5}->reference_len'.\n" +
"But be aware that not always a subsequent method is called -> Do NOT allocate memory here and try to release it in subsequent methods!\n\n" +
"You also may replace function pointers in '{5}' param for get/test/set methods which contain the default values from table definition,\n" +
"in order to provide special methods, for the currently processed cell. Changed pointers are only valid for current request.",
getInstanceMethod.Parameter[1].Name,
getInstanceMethod.Parameter[2].Name,
returnValue.Type.Name,
LwipDefs.Def_ErrorCode_Ok,
augmentsHint,
getInstanceMethod.Parameter[3].Name
)));
getInstanceMethod.AddCodeFormat("return {0};", returnValue.Type.Name);
}