本文整理汇总了C#中Field.TryGetDeclaringType方法的典型用法代码示例。如果您正苦于以下问题:C# Field.TryGetDeclaringType方法的具体用法?C# Field.TryGetDeclaringType怎么用?C# Field.TryGetDeclaringType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Field
的用法示例。
在下文中一共展示了Field.TryGetDeclaringType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFieldToMethodEffects
private static TypeEx AddFieldToMethodEffects(IPexComponent host, TypeEx declaringType, SafeSet<Field> res,
SafeSet<Field> directSetFields,
SafeDictionary<Field, FieldModificationType> modificationTypeDic,
OpCode prevOpcode, Field field, TypeEx fieldType)
{
SafeDebug.AssumeNotNull(field, "field");
SafeDebug.Assume(!field.IsStatic, "!field.IsStatic");
TypeEx fieldDeclaringType;
//The following check ensures that the field belongs to this class
//or its base classes
if (field.TryGetDeclaringType(out fieldDeclaringType) &&
declaringType.IsAssignableTo(fieldDeclaringType))
{
res.Add(field);
var fieldTypeStr = fieldType.ToString();
if (fieldTypeStr == "System.Int32" || fieldTypeStr == "System.Int64" || fieldTypeStr == "System.Int16")
{
if (prevOpcode == OpCodes.Add)
modificationTypeDic[field] = FieldModificationType.INCREMENT;
else if (prevOpcode == OpCodes.Sub)
modificationTypeDic[field] = FieldModificationType.DECREMENT;
else
host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fieldmodificationtype",
"Encountered unknown modification type for integer type " + prevOpcode);
}
else
{
if (field.Type.IsReferenceType)
{
if (prevOpcode == OpCodes.Ldnull)
modificationTypeDic[field] = FieldModificationType.NULL_SET;
else if (prevOpcode == OpCodes.Newarr || prevOpcode == OpCodes.Newobj)
modificationTypeDic[field] = FieldModificationType.NON_NULL_SET;
else
host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fieldmodificationtype",
"Encountered unknown modification type for reference type " + prevOpcode);
}
else if (fieldTypeStr == "System.Boolean")
{
if (prevOpcode == OpCodes.Ldc_I4_0)
modificationTypeDic[field] = FieldModificationType.FALSE_SET;
else if (prevOpcode == OpCodes.Ldc_I4_1)
modificationTypeDic[field] = FieldModificationType.TRUE_SET;
else
host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fieldmodificationtype",
"Encountered unknown modification type for boolean type " + prevOpcode);
}
}
//A heuristic based approach for aliasing analysis for checking whether the field is directly
//assigned any parameters
if (LdArgOpCodes.Contains(prevOpcode))
directSetFields.Add(field);
}
return fieldDeclaringType;
}
示例2: AddFieldToMethodEffects
public static TypeEx AddFieldToMethodEffects(IPexComponent host, TypeEx declaringType, SafeSet<string> res,
SafeSet<string> directSetFields, SafeDictionary<string, FieldModificationType> modificationTypeDic,
OpCode prevOpcode, Field field, TypeEx fieldType)
{
SafeDebug.AssumeNotNull(field, "field");
SafeDebug.Assume(!field.IsStatic, "!field.IsStatic");
TypeEx fieldDeclaringType;
//The following check ensures that the field belongs to this class
//or its base classes
if (field.TryGetDeclaringType(out fieldDeclaringType) &&
declaringType.IsAssignableTo(fieldDeclaringType))
{
res.Add(field.ShortName);
FieldModificationType fmt = FieldModificationType.UNKNOWN;
if (fieldType == SystemTypes.Int32 || fieldType == SystemTypes.Int64 || fieldType == SystemTypes.Int16)
{
if (prevOpcode == OpCodes.Add)
fmt = FieldModificationType.INCREMENT;
else if (prevOpcode == OpCodes.Sub)
fmt = FieldModificationType.DECREMENT;
else if (prevOpcode == OpCodes.Call || prevOpcode == OpCodes.Calli || prevOpcode == OpCodes.Callvirt)
fmt = FieldModificationType.METHOD_CALL;
else
host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fieldmodificationtype",
"Encountered unknown modification type for integer type " + prevOpcode);
}
else
{
if (field.Type.IsReferenceType)
{
if (prevOpcode == OpCodes.Ldnull)
fmt = FieldModificationType.NULL_SET;
else if (prevOpcode == OpCodes.Newarr || prevOpcode == OpCodes.Newobj)
fmt = FieldModificationType.NON_NULL_SET;
else if (LdArgOpCodes.Contains(prevOpcode))
fmt = FieldModificationType.NON_NULL_SET;
else
{
fmt = FieldModificationType.METHOD_CALL; //A method call is invoked on this field, which updates this field
}
}
else if (fieldType == SystemTypes.Bool)
{
if (prevOpcode == OpCodes.Ldc_I4_0)
fmt = FieldModificationType.FALSE_SET;
else if (prevOpcode == OpCodes.Ldc_I4_1)
fmt = FieldModificationType.TRUE_SET;
else
host.Log.LogWarning(WikiTopics.MissingWikiTopic, "fieldmodificationtype",
"Encountered unknown modification type for boolean type " + prevOpcode);
}
}
//Store the value of fmt. Sometimes, the same field
//can be modified in different ways within the method, for example
//setting a boolean field to both true or false. In that case, the modification
//type is left as unknown
FieldModificationType prevFMT;
if (modificationTypeDic.TryGetValue(field.ShortName, out prevFMT))
{
//There is some entry for this field
if (prevFMT != FieldModificationType.UNKNOWN && prevFMT != fmt)
{
modificationTypeDic[field.ShortName] = FieldModificationType.UNKNOWN;
}
}
else
{
modificationTypeDic[field.ShortName] = fmt;
}
//A heuristic based approach for aliasing analysis for checking whether the field is directly
//assigned any parameters
if (LdArgOpCodes.Contains(prevOpcode))
directSetFields.Add(field.ShortName);
}
return fieldDeclaringType;
}
示例3: UpdateDUCoverTable
private bool UpdateDUCoverTable(Field field, out FieldDefUseStore llfs)
{
if (this.lastFieldDefsDic.TryGetValue(field.GlobalIndex, out llfs))
{
TypeEx declType;
if (!field.TryGetDeclaringType(out declType))
{
logger.Error("Failed to retrieve declaring type for the field " + field.FullName);
return false;
}
DeclClassEntity dce;
if (!this.dcs.DeclEntityDic.TryGetValue(declType.FullName, out dce))
{
logger.Error("Failed to retrieve DeclClassEntity for the class " + declType.FullName);
return false;
}
DeclFieldEntity dfe;
if (!dce.FieldEntities.TryGetValue(field.FullName, out dfe))
{
logger.Error("Failed to retrieve DeclFieldEntity for the field " + field.FullName);
return false;
}
return dfe.UpdateDUCoverageTable(llfs.Method, llfs.Offset, this.GetCurrentMethod(), this.currOffset);
}
else
{
//logger.Warn("Encountered load field on " + field.FullName + " at " + this.GetCurrentMethod().FullName
// + "(" + this.currOffset + ") without any field definition");
return false;
}
}