本文整理汇总了C#中ILGen.EmitFieldAddress方法的典型用法代码示例。如果您正苦于以下问题:C# ILGen.EmitFieldAddress方法的具体用法?C# ILGen.EmitFieldAddress怎么用?C# ILGen.EmitFieldAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILGen
的用法示例。
在下文中一共展示了ILGen.EmitFieldAddress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OverrideDeserializer
private void OverrideDeserializer(ConstructorInfo/*!*/ baseCtor) {
// ctor(SerializationInfo! info, StreamingContext! context) : base(info, context) {
// RubyOps.DeserializeObject(out this._instanceData, out this._immediateClass, info);
// }
ConstructorBuilder cb = _tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, _deserializerSignature);
ILGen il = new ILGen(cb.GetILGenerator());
il.EmitLoadArg(0);
il.EmitLoadArg(1);
il.EmitLoadArg(2);
il.Emit(OpCodes.Call, baseCtor);
il.EmitLoadArg(0);
il.EmitFieldAddress(InstanceDataField);
il.EmitLoadArg(0);
il.EmitFieldAddress(ImmediateClassField);
il.EmitLoadArg(1);
il.EmitCall(Methods.DeserializeObject);
il.Emit(OpCodes.Ret);
}
示例2: DefineConstructors
private void DefineConstructors() {
BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
ConstructorInfo defaultCtor = _tb.BaseType.GetConstructor(bindingFlags, null, Type.EmptyTypes, null);
// constructor with a single parameter of type RubyClass:
ConstructorInfo defaultRubyCtor = null;
bool deserializerFound = false;
foreach (var baseCtor in _tb.BaseType.GetConstructors(bindingFlags)) {
if (!baseCtor.IsPublic && !baseCtor.IsFamily) {
continue;
}
Type[] paramTypes;
ParameterInfo[] baseParams = baseCtor.GetParameters();
int additionalParamCount;
bool isDeserializer = false;
bool isDefaultRubyCtor = false;
if (baseParams.Length > 0 && baseParams[0].ParameterType == typeof(RubyClass)) {
// Build a simple pass-through constructor
paramTypes = ReflectionUtils.GetParameterTypes(baseParams);
additionalParamCount = 0;
isDefaultRubyCtor = true;
#if !SILVERLIGHT
} else if (baseParams.Length == 2 &&
baseParams[0].ParameterType == typeof(SerializationInfo) && baseParams[1].ParameterType == typeof(StreamingContext)) {
// Build a deserializer
deserializerFound = true;
isDeserializer = true;
paramTypes = ReflectionUtils.GetParameterTypes(baseParams);
additionalParamCount = 0;
#endif
} else {
// Special-case for Exception
if (_tb.IsSubclassOf(typeof(Exception)) && IsAvailable(defaultCtor)) {
if (baseParams.Length == 0) {
// Skip this constructor; it would conflict with the one we're going to build next
continue;
} else if (baseParams.Length == 1 && baseParams[0].ParameterType == typeof(string)) {
// Special case exceptions to improve interop. Ruby's default message for an exception is the name of the exception class.
BuildExceptionConstructor(baseCtor);
}
}
// Add RubyClass to the head of the parameter list
paramTypes = new Type[baseParams.Length + 1];
paramTypes[0] = typeof(RubyClass);
for (int i = 0; i < baseParams.Length; i++) {
paramTypes[i + 1] = baseParams[i].ParameterType;
}
additionalParamCount = 1;
if (baseParams.Length == 0) {
isDefaultRubyCtor = true;
}
}
// Build a new constructor based on this base class ctor
ConstructorBuilder cb = _tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, paramTypes);
ILGen il = new ILGen(cb.GetILGenerator());
il.EmitLoadArg(0);
for (int i = 1; i < baseParams.Length + 1; i++) {
il.EmitLoadArg(i + additionalParamCount);
}
il.Emit(OpCodes.Call, baseCtor);
if (!isDeserializer) {
// ctor(RubyClass! class, {params}) : base({params}) { this._class = class; }
il.EmitLoadArg(0);
il.EmitLoadArg(1);
il.EmitFieldSet(_classField);
if (isDefaultRubyCtor) {
defaultRubyCtor = cb;
}
} else {
// ctor(SerializationInfo! info, StreamingContext! context) : base(info, context) {
// RubyOps.DeserializeObject(out this._instanceData, out this._class, info);
// }
il.EmitLoadArg(0);
il.EmitFieldAddress(_instanceDataField);
il.EmitLoadArg(0);
il.EmitFieldAddress(_classField);
il.EmitLoadArg(1);
il.EmitCall(typeof(RubyOps).GetMethod("DeserializeObject"));
}
il.Emit(OpCodes.Ret);
}
#if !SILVERLIGHT
if (defaultRubyCtor != null && !deserializerFound) {
// We didn't previously find a deserialization constructor. If we can, build one now.
BuildDeserializationConstructor(defaultRubyCtor);
}
#endif
}
示例3: BuildDeserializationConstructor
private void BuildDeserializationConstructor(ConstructorInfo thisCtor) {
// ctor(SerializationInfo! info, StreamingContext! context) : this((RubyClass)context.Context) {
// RubyOps.DeserializeObject(out this._instanceData, out this._class, info);
// }
ConstructorBuilder ctor = _tb.DefineConstructor(MethodAttributes.Family, CallingConventions.Standard, _deserializerSignature);
ILGen il = new ILGen(ctor.GetILGenerator());
il.EmitLoadArg(0);
il.EmitLoadArgAddress(2);
il.EmitCall(typeof(StreamingContext).GetProperty("Context").GetGetMethod());
il.Emit(OpCodes.Castclass, typeof(RubyClass));
il.Emit(OpCodes.Call, thisCtor);
il.EmitLoadArg(0);
il.EmitFieldAddress(_instanceDataField);
il.EmitLoadArg(0);
il.EmitFieldAddress(_classField);
il.EmitLoadArg(1);
il.EmitCall(typeof(RubyOps).GetMethod("DeserializeObject"));
il.Emit(OpCodes.Ret);
}
示例4: DefineConstructors
private void DefineConstructors() {
BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance;
ConstructorInfo emptyCtor = _tb.BaseType.GetConstructor(bindingFlags, null, Type.EmptyTypes, null);
ConstructorInfo classArgCtor = null;
bool deserializerFound = false;
foreach (var baseCtor in _tb.BaseType.GetConstructors(bindingFlags)) {
if (!baseCtor.IsPublic && !baseCtor.IsFamily) {
continue;
}
int oldLength = baseCtor.GetParameters().Length;
List<Type> newParams = new List<Type>(oldLength + 1);
foreach (var param in baseCtor.GetParameters()) {
newParams.Add(param.ParameterType);
}
int offset = 1;
bool isDeserializer = false;
if (oldLength > 0 && newParams[0] == typeof(RubyClass)) {
// Build a simple pass-through constructor
offset = 0;
#if !SILVERLIGHT
} else if (oldLength == 2 && newParams[0] == typeof(SerializationInfo) && newParams[1] == typeof(StreamingContext)) {
// Build a deserializer
deserializerFound = true;
isDeserializer = true;
offset = 0;
#endif
} else {
// Special-case for Exception
if (_tb.IsSubclassOf(typeof(Exception)) && IsAvailable(emptyCtor)) {
if (oldLength == 0) {
// Skip this constructor; it would conflict with the one we're going to build next
continue;
} else if (oldLength == 1 && newParams[0] == typeof(string)) {
// Special case exceptions to improve interop. Ruby's default message for an exception is the name of the exception class.
BuildExceptionConstructor(baseCtor);
}
}
// Add RubyClass to the head of the parameter list
newParams.Insert(0, typeof(RubyClass));
}
// Build a new constructor based on this base class ctor
ConstructorBuilder cb = _tb.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, newParams.ToArray());
ILGen il = new ILGen(cb.GetILGenerator());
il.EmitLoadArg(0);
for (int i = 1; i < newParams.Count; i++) {
il.EmitLoadArg(i + offset);
}
il.Emit(OpCodes.Call, baseCtor);
if (!isDeserializer) {
// ctor(RubyClass! class, ...) : ... { this._class = class; }
il.EmitLoadArg(0);
il.EmitLoadArg(1);
il.EmitFieldSet(_classField);
} else {
// ctor(SerializationInfo! info, StreamingContext! context) : base {
// RubyOps.DeserializeObject(out this._instanceData, out this._class, info);
// }
il.EmitLoadArg(0);
il.EmitFieldAddress(_instanceDataField);
il.EmitLoadArg(0);
il.EmitFieldAddress(_classField);
il.EmitLoadArg(1);
il.EmitCall(typeof(RubyOps).GetMethod("DeserializeObject"));
}
il.Emit(OpCodes.Ret);
if (oldLength == 0) {
classArgCtor = cb;
}
}
#if !SILVERLIGHT
if (classArgCtor != null && !deserializerFound) {
// We didn't previously find a deserialization constructor. If we can, build one now.
BuildDeserializationConstructor(classArgCtor);
}
#endif
}