/// <summary> /// 字段属性信息 /// </summary> /// <param name="cp">字段代码位置</param> /// <param name="fInfo">字段信息</param> /// <param name="belongEntity">所属实体</param> public EntityParamField(CodeElementPosition cp, ClrField fInfo, EntityConfig belongEntity) { _cp = cp; _fInfo = fInfo; GetEntityParamInfo(fInfo); _belongEntity = belongEntity; }
public static ClrType GetDeclaringType(this ClrField field, ClrType containingType) { if (field.Offset == -1) { return(containingType); } List <ClrType> types = new List <ClrType>(); ClrType t = containingType; while (t != null) { types.Add(t); t = t.BaseType; } types.Reverse(); foreach (var type in types) { if (type.Fields.Any(item => item.Offset == field.Offset)) { return(type); } } return(containingType); }
public void NoFieldCachingTest() { using DataTarget dt = TestTargets.Types.LoadFullDump(); dt.CacheOptions.CacheFields = false; dt.CacheOptions.CacheFieldNames = StringCaching.None; using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrModule module = runtime.GetModule("sharedlibrary.dll"); ClrType type = module.GetTypeByName("Foo"); Assert.NotEqual(0ul, type.MethodTable); // Sanity test Assert.NotEqual(type.Fields, type.Fields); ClrField field = type.GetFieldByName("o"); ClrField field2 = type.Fields.Single(f => f.Name == "o"); Assert.NotSame(field, field2); Assert.NotSame(field.Name, field.Name); dt.CacheOptions.CacheFieldNames = StringCaching.Intern; Assert.Same(field.Name, field.Name); Assert.Same(field.Name, string.Intern(field.Name)); }
/// <summary> /// 实体映射 /// </summary> /// <param name="cp"></param> /// <param name="fInfo"></param> /// <param name="belongEntity"></param> public EntityRelationItem(CodeElementPosition cp, ClrField fInfo, EntityConfig belongEntity) { _cp = cp; _fInfo = fInfo; //_isParent = GetIsParent(fInfo); GetInfo(fInfo); _belongEntity = belongEntity; }
/// <summary> /// 获取此字段是否主表属性 /// </summary> /// <param name="fInfo"></param> /// <returns></returns> private static bool GetIsParent(ClrField fInfo) { if (fInfo.MemberType != null && fInfo.MemberType.Generic) { return(false); } return(true); }
public static bool IsOfObjectReferenceType(this ClrField field) { return (field.ElementType == ClrElementType.String || field.ElementType == ClrElementType.Class || field.ElementType == ClrElementType.Array || field.ElementType == ClrElementType.SZArray || field.ElementType == ClrElementType.Object); }
private static DynamicInstance FromField(object fieldValue, ClrField field, ClrHeap heap) { if (field.IsPrimitive || field.Type.IsString) { return(new DynamicInstance(fieldValue, field.Type, heap)); } return(new DynamicInstance((ulong)fieldValue, field.Type, heap)); }
public FieldInfo(ClrField Field) { TypeName = Field.Type.Name; Name = Field.Name; MethodTable = HeapStatItem.GetMTOfType(Field.Type); Offset = Field.Offset; IsStatic = false; IsThreadStatic = false; Token = Field.Type.MetadataToken; }
public static string GetFieldTypeNameTrimmed(this ClrField field, int trim = 16) { var fieldTypeName = field.Type == null?field.ElementType.ToString() : field.Type.Name; if (fieldTypeName.Length > trim) { fieldTypeName = "..." + fieldTypeName.Substring(fieldTypeName.Length - trim); } return(fieldTypeName); }
public void PrintFieldVisibility(ClrField field, bool isStatic = false) { Write("{0}", field.IsInternal ? "internal " : field.IsProtected ? "protected " : field.IsPrivate ? "private " : field.IsPublic ? "public " : "undefinedvisibility "); if (isStatic) { Write("static "); } Write("{0} ", field.Type == null ? "object" : field.Type.Name); WriteLine("{0};", field.Name); }
public static bool IsOfPrimitiveType(this ClrField field) { return (field.ElementType != ClrElementType.Struct && field.ElementType != ClrElementType.String && field.ElementType != ClrElementType.Class && field.ElementType != ClrElementType.Array && field.ElementType != ClrElementType.SZArray && field.ElementType != ClrElementType.Object); }
/// <summary> /// 获取字段的配置信息 /// </summary> /// <param name="fInfo"></param> private void GetEntityParamInfo(ClrField fInfo) { _propertyName = ToPascalName(FieldName); _paramName = FieldName.Trim('_'); DataTypeInfos info = EntityFieldBase.GetTypeInfo(fInfo); if (info != null) { _dbType = info.DbTypes[0].ToString(); _length = info.DbLength; } }
private string DateToString(ClrField field) { string stringres = string.Empty; var dt = DateTimeReader.FromObjToDate(this.Obj, field); if (dt == DateTime.MinValue) { return(string.Format(fieldPrintFormat, field.Name, "[EmptyDate]", Environment.NewLine)); } var timeSince = MetadataManager.GetDumpTime(this.Obj) - dt; return(dt.ToString("s") + " ( " + timeSince.ToString("g") + " ago)"); }
// Get the serialization data for this object. public void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info"); } if (value_ == IntPtr.Zero) { throw new SerializationException (_("Serialize_StateMissing")); } ClrField field = (ClrField)(FieldInfo.GetFieldFromHandle(this)); info.AddValue("FieldObj", field, typeof(ClrField)); }
/// <summary> /// 初始化字段信息 /// </summary> private void InitField() { List <ClrField> lstFields = GetAllMember <ClrField>(_classType, false); _fields = new Dictionary <string, CodeElementPosition>(); for (int j = 0; j < lstFields.Count; j++) { ClrField field = lstFields[j]; if (field == null) { continue; } if (field.SourceCodePositions == null) { continue; } foreach (CodeElementPosition cp in field.SourceCodePositions) { if (!IsManyOne(field)) { EntityParamField epf = new EntityParamField(cp, field, this); epf.AllowNull = EntityFieldBase.IsNullProperty(field.MemberTypeShortName); _eParamFields.Add(epf); } else { EntityRelationItem erf = new EntityRelationItem(cp, field, this); _eRelation.Add(erf); } _fields[field.Name] = cp; } _eParamFields.SortItem(); _eRelation.SortItem(); } _hasConfig = EntityMappingConfig.LoadConfigInfo(this); }
public void TestInstanceFieldModifiers() { using DataTarget dt = TestTargets.NestedTypes.LoadFullDump(); using ClrRuntime runtime = dt.ClrVersions.Single().CreateRuntime(); ClrModule module = runtime.GetModule(TypeTests.NestedTypesModuleName); ClrType program = module.GetTypeByName("Program"); ClrField publicField = program.GetInstanceFieldByName("publicField"); Assert.True(publicField.IsPublic); ClrField privateField = program.GetInstanceFieldByName("privateField"); Assert.True(privateField.IsPrivate); ClrField internalField = program.GetInstanceFieldByName("internalField"); Assert.True(internalField.IsInternal); ClrField protectedField = program.GetInstanceFieldByName("protectedField"); Assert.True(protectedField.IsProtected); }
public static bool IsOfValueClass(this ClrField field) { return(field.ElementType == ClrElementType.Struct); }
/// <summary> /// 获取字段的配置信息 /// </summary> /// <param name="fInfo"></param> private void GetInfo(ClrField fInfo) { _propertyName = ToPascalName(FieldName); }
public static bool IsObjectReferenceNotString(this ClrField field) { return((field.ElementType != ClrElementType.String) && field.IsObjectReference()); }
private DynamicProxy LinkToStruct(ClrField field) { var childAddress = AddressWithoutHeader + (ulong)field.Offset; return(new DynamicProxy(_heap, childAddress, field.Type)); }
protected virtual void AppendFieldToStringBuilder(StringBuilder sb, ClrField field) { Assert.ArgumentNotNull(sb, "stringbuilder"); Assert.ArgumentNotNull(field, "field"); switch (field.ElementType) { case ClrElementType.String: { sb.AppendFormat(fieldPrintFormat, field.Name, this.Obj.GetStringSafe(field.Name), Environment.NewLine); break; } case ClrElementType.Object: { sb.AppendFormat("{0}: {1}: {2}{3}", field.Name, field.Type.Name, this.Obj.GetRefFld(field.Name).HexAddress, Environment.NewLine); break; } case ClrElementType.Int32: { sb.AppendFormat(fieldPrintFormat, field.Name, this.Obj.GetSimpleFld <int>(field.Name), Environment.NewLine); break; } case ClrElementType.Int64: { sb.AppendFormat(fieldPrintFormat, field.Name, this.Obj.GetSimpleFld <long>(field.Name), Environment.NewLine); break; } case ClrElementType.Boolean: { sb.AppendFormat(fieldPrintFormat, field.Name, this.Obj.GetBoolFld(field.Name), Environment.NewLine); break; } case ClrElementType.Double: { sb.AppendFormat(fieldPrintFormat, field.Name, this.Obj.GetDoubleFld(field.Name), Environment.NewLine); break; } case ClrElementType.UInt64: { sb.AppendFormat(fieldPrintFormat, field.Name, this.Obj.GetUInt64Fld(field.Name), Environment.NewLine); break; } case ClrElementType.Struct: { var t = field.Type; if (t == null) { break; } // check date string stringres = string.Empty; var fld = field.Type.GetFieldByName("dateData"); if (fld != null) { stringres = this.DateToString(field); } else if (TimeSpanReader.CanRead(this.Obj, field.Name)) { stringres = TimeSpanReader.Read(this.Obj, field.Name).ToString("g"); } else { break; // Cannot Read anyway =\ } sb.AppendFormat(fieldPrintFormat, field.Name, stringres, Environment.NewLine); break; } } sb.AppendLine(string.Empty); // delimitor to simplify reading for human eye }
/// <summary> /// Reads date from given object field. /// </summary> /// <param name="obj">The object.</param> /// <param name="fld">The field.</param> /// <returns></returns> public static DateTime FromObjToDate(ClrObject obj, ClrField fld) { Assert.ArgumentNotNull(fld, "field"); return(FromObjToDate(obj, fld.Name)); }