本文整理汇总了C#中INamingScope类的典型用法代码示例。如果您正苦于以下问题:C# INamingScope类的具体用法?C# INamingScope怎么用?C# INamingScope使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
INamingScope类属于命名空间,在下文中一共展示了INamingScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTypeImplementerMapping
protected virtual IEnumerable<Type> GetTypeImplementerMapping(out IEnumerable<ITypeContributor> contributors,
INamingScope namingScope)
{
var methodsToSkip = new List<MethodInfo>();
var proxyInstance = new ClassProxyInstanceContributor(targetType, methodsToSkip, Type.EmptyTypes,
ProxyTypeConstants.ClassWithTarget);
var proxyTarget = new DelegateProxyTargetContributor(targetType, namingScope) { Logger = Logger };
IDictionary<Type, ITypeContributor> typeImplementerMapping = new Dictionary<Type, ITypeContributor>();
// Order of interface precedence:
// 1. first target, target is not an interface so we do nothing
// 2. then mixins - we support none so we do nothing
// 3. then additional interfaces - we support none so we do nothing
#if !SILVERLIGHT
// 4. plus special interfaces
if (targetType.IsSerializable)
{
AddMappingForISerializable(typeImplementerMapping, proxyInstance);
}
#endif
AddMappingNoCheck(typeof(IProxyTargetAccessor), proxyInstance, typeImplementerMapping);
contributors = new List<ITypeContributor>
{
proxyTarget,
proxyInstance
};
return typeImplementerMapping.Keys;
}
示例2: AddMappingForTargetType
protected virtual ITypeContributor AddMappingForTargetType(IDictionary<Type, ITypeContributor> typeImplementerMapping,
Type proxyTargetType, ICollection<Type> targetInterfaces,
ICollection<Type> additionalInterfaces,
INamingScope namingScope)
{
var contributor = new InterfaceProxyTargetContributor(proxyTargetType, AllowChangeTarget, namingScope)
{ Logger = Logger };
var proxiedInterfaces = targetType.GetAllInterfaces();
foreach (var @interface in proxiedInterfaces)
{
contributor.AddInterfaceToProxy(@interface);
AddMappingNoCheck(@interface, contributor, typeImplementerMapping);
}
foreach (var @interface in additionalInterfaces)
{
if (!ImplementedByTarget(targetInterfaces, @interface) || proxiedInterfaces.Contains(@interface))
{
continue;
}
contributor.AddInterfaceToProxy(@interface);
AddMappingNoCheck(@interface, contributor, typeImplementerMapping);
}
return contributor;
}
示例3: ClassProxyWithTargetTargetContributor
public ClassProxyWithTargetTargetContributor(Type targetType, IList<MethodInfo> methodsToSkip,
INamingScope namingScope)
: base(namingScope)
{
this.targetType = targetType;
this.methodsToSkip = methodsToSkip;
}
示例4: InterfaceProxyWithOptionalTargetContributor
public InterfaceProxyWithOptionalTargetContributor(INamingScope namingScope, GetTargetExpressionDelegate getTarget,
GetTargetReferenceDelegate getTargetReference)
: base(namingScope, getTarget)
{
this.getTargetReference = getTargetReference;
canChangeTarget = true;
}
示例5: InvocationWithDelegateContributor
public InvocationWithDelegateContributor(Type delegateType, Type targetType,MetaMethod method, INamingScope namingScope)
{
Debug.Assert(delegateType.IsGenericType == false, "delegateType.IsGenericType == false");
this.delegateType = delegateType;
this.targetType = targetType;
this.method = method;
this.namingScope = namingScope;
}
示例6: GenerateType
private Type GenerateType(string name, INamingScope namingScope)
{
IEnumerable<ITypeContributor> contributors;
var implementedInterfaces = GetTypeImplementerMapping(out contributors, namingScope);
var model = new MetaType();
// Collect methods
foreach (var contributor in contributors)
{
contributor.CollectElementsToProxy(ProxyGenerationOptions.Hook, model);
}
ProxyGenerationOptions.Hook.MethodsInspected();
var emitter = BuildClassEmitter(name, targetType, implementedInterfaces);
CreateFields(emitter);
CreateTypeAttributes(emitter);
// Constructor
var cctor = GenerateStaticConstructor(emitter);
var targetField = CreateTargetField(emitter);
var constructorArguments = new List<FieldReference> { targetField };
foreach (var contributor in contributors)
{
contributor.Generate(emitter, ProxyGenerationOptions);
// TODO: redo it
if (contributor is MixinContributor)
{
constructorArguments.AddRange((contributor as MixinContributor).Fields);
}
}
// constructor arguments
var interceptorsField = emitter.GetField("__interceptors");
constructorArguments.Add(interceptorsField);
var selector = emitter.GetField("__selector");
if (selector != null)
{
constructorArguments.Add(selector);
}
GenerateConstructors(emitter, targetType, constructorArguments.ToArray());
GenerateParameterlessConstructor(emitter, targetType, interceptorsField);
// Complete type initializer code body
CompleteInitCacheMethod(cctor.CodeBuilder);
// Crosses fingers and build type
Type proxyType = emitter.BuildType();
InitializeStaticFields(proxyType);
return proxyType;
}
示例7: BuildProxiedMethodBody
protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class,
ProxyGenerationOptions options, INamingScope namingScope)
{
var targetReference = getTargetReference(@class, MethodToOverride);
emitter.CodeBuilder.AddStatement(
new ExpressionStatement(
new IfNullExpression(targetReference, IfNull(emitter.ReturnType), IfNotNull(targetReference))));
return emitter;
}
示例8: BuildMethodInterceptorsField
protected FieldReference BuildMethodInterceptorsField(ClassEmitter @class, MethodInfo method, INamingScope namingScope)
{
var methodInterceptors = @class.CreateField(
namingScope.GetUniqueName(string.Format("interceptors_{0}", method.Name)),
typeof(IInterceptor[]),
false);
#if !SILVERLIGHT
@class.DefineCustomAttributeFor<XmlIgnoreAttribute>(methodInterceptors);
#endif
return methodInterceptors;
}
示例9: AddMappingForTargetType
protected override ITypeContributor AddMappingForTargetType(IDictionary<Type, ITypeContributor> interfaceTypeImplementerMapping, Type proxyTargetType, ICollection<Type> targetInterfaces, ICollection<Type> additionalInterfaces, INamingScope namingScope)
{
var contributor = new InterfaceProxyWithoutTargetContributor(namingScope, (c, m) => NullExpression.Instance)
{ Logger = Logger };
foreach (var @interface in TypeUtil.GetAllInterfaces(targetType))
{
contributor.AddInterfaceToProxy(@interface);
AddMappingNoCheck(@interface, contributor, interfaceTypeImplementerMapping);
}
return contributor;
}
示例10: GenerateType
protected override Type GenerateType(string typeName, Type proxyTargetType, Type[] interfaces,
INamingScope namingScope)
{
IEnumerable<ITypeContributor> contributors;
var allInterfaces = GetTypeImplementerMapping(interfaces, targetType, out contributors, namingScope);
var model = new MetaType();
// collect elements
foreach (var contributor in contributors)
{
contributor.CollectElementsToProxy(ProxyGenerationOptions.Hook, model);
}
ProxyGenerationOptions.Hook.MethodsInspected();
ClassEmitter emitter;
FieldReference interceptorsField;
var baseType = Init(typeName, out emitter, proxyTargetType, out interceptorsField, allInterfaces);
// Constructor
var cctor = GenerateStaticConstructor(emitter);
var mixinFieldsList = new List<FieldReference>();
foreach (var contributor in contributors)
{
contributor.Generate(emitter, ProxyGenerationOptions);
// TODO: redo it
if (contributor is MixinContributor)
{
mixinFieldsList.AddRange((contributor as MixinContributor).Fields);
}
}
var ctorArguments = new List<FieldReference>(mixinFieldsList) { interceptorsField,
targetField };
var selector = emitter.GetField("__selector");
if (selector != null)
{
ctorArguments.Add(selector);
}
GenerateConstructors(emitter, baseType, ctorArguments.ToArray());
// Complete type initializer code body
CompleteInitCacheMethod(cctor.CodeBuilder);
// Crosses fingers and build type
var generatedType = emitter.BuildType();
InitializeStaticFields(generatedType);
return generatedType;
}
示例11: BuildProxiedMethodBody
protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class, ProxyGenerationOptions options, INamingScope namingScope)
{
var targetReference = getTargetReference(@class, MethodToOverride);
var arguments = ArgumentsUtil.ConvertToArgumentReferenceExpression(MethodToOverride.GetParameters());
emitter.CodeBuilder.AddStatement(new ReturnStatement(
new MethodInvocationExpression(
targetReference,
MethodToOverride,
arguments) { VirtualCall = true }));
return emitter;
}
示例12: AddMappingForTargetType
protected override ITypeContributor AddMappingForTargetType(IDictionary<Type, ITypeContributor> typeImplementerMapping, Type proxyTargetType, ICollection<Type> targetInterfaces, ICollection<Type> additionalInterfaces, INamingScope namingScope)
{
WCFInterfaceProxyWithTargetInterfaceTargetContributor contributor = new WCFInterfaceProxyWithTargetInterfaceTargetContributor(proxyTargetType, this.AllowChangeTarget, namingScope)
{
Logger = base.Logger
};
foreach (Type @interface in base.targetType.GetAllInterfaces())
{
contributor.AddInterfaceToProxy(@interface);
base.AddMappingNoCheck(@interface, contributor, typeImplementerMapping);
}
return contributor;
}
示例13: BuildProxiedMethodBody
protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class, ProxyGenerationOptions options, INamingScope namingScope)
{
InitOutParameters(emitter, MethodToOverride.GetParameters());
if (emitter.ReturnType == typeof(void))
{
emitter.CodeBuilder.AddStatement(new ReturnStatement());
}
else
{
emitter.CodeBuilder.AddStatement(new ReturnStatement(new DefaultValueExpression(emitter.ReturnType)));
}
return emitter;
}
示例14: GenerateType
protected override Type GenerateType(string typeName, Type proxyTargetType, Type[] interfaces, INamingScope namingScope)
{
IEnumerable<ITypeContributor> contributors;
ClassEmitter emitter;
FieldReference interceptorsField;
IEnumerable<Type> allInterfaces = this.GetTypeImplementerMapping(interfaces, base.targetType, out contributors, namingScope);
MetaType model = new MetaType();
foreach (ITypeContributor contributor in contributors)
{
contributor.CollectElementsToProxy(base.ProxyGenerationOptions.Hook, model);
}
base.ProxyGenerationOptions.Hook.MethodsInspected();
Type baseType = this.Init(typeName, out emitter, proxyTargetType, out interceptorsField, allInterfaces);
ConstructorEmitter cctor = base.GenerateStaticConstructor(emitter);
List<FieldReference> mixinFieldsList = new List<FieldReference>();
foreach (ITypeContributor contributor in contributors)
{
contributor.Generate(emitter, base.ProxyGenerationOptions);
if (contributor is MixinContributor)
{
mixinFieldsList.AddRange((contributor as MixinContributor).Fields);
}
}
List<FieldReference> g__initLocalc = new List<FieldReference>(mixinFieldsList) {
interceptorsField,
base.targetField
};
List<FieldReference> ctorArguments = g__initLocalc;
FieldReference selector = emitter.GetField("__selector");
if (selector != null)
{
ctorArguments.Add(selector);
}
base.GenerateConstructors(emitter, baseType, ctorArguments.ToArray());
base.CompleteInitCacheMethod(cctor.CodeBuilder);
Type generatedType = emitter.BuildType();
base.InitializeStaticFields(generatedType);
return generatedType;
}
示例15: BuildProxiedMethodBody
protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, ClassEmitter @class, ProxyGenerationOptions options,INamingScope namingScope)
{
var invocationType = invocation;
Trace.Assert(MethodToOverride.IsGenericMethod == invocationType.IsGenericTypeDefinition);
Type[] genericMethodArgs = Type.EmptyTypes;
ConstructorInfo constructor = invocation.GetConstructors()[0];
Expression proxiedMethodTokenExpression;
if (MethodToOverride.IsGenericMethod)
{
// bind generic method arguments to invocation's type arguments
genericMethodArgs = emitter.MethodBuilder.GetGenericArguments();
invocationType = invocationType.MakeGenericType(genericMethodArgs);
constructor = TypeBuilder.GetConstructor(invocationType, constructor);
// Not in the cache: generic method
proxiedMethodTokenExpression = new MethodTokenExpression(MethodToOverride.MakeGenericMethod(genericMethodArgs));
}
else
{
var proxiedMethodToken = @class.CreateStaticField(namingScope.GetUniqueName("token_" + MethodToOverride.Name), typeof(MethodInfo));
@class.ClassConstructor.CodeBuilder.AddStatement(new AssignStatement(proxiedMethodToken, new MethodTokenExpression(MethodToOverride)));
proxiedMethodTokenExpression = proxiedMethodToken.ToExpression();
}
var dereferencedArguments = IndirectReference.WrapIfByRef(emitter.Arguments);
var ctorArguments = GetCtorArguments(@class, namingScope, proxiedMethodTokenExpression, dereferencedArguments);
var invocationLocal = emitter.CodeBuilder.DeclareLocal(invocationType);
emitter.CodeBuilder.AddStatement(new AssignStatement(invocationLocal,
new NewInstanceExpression(constructor, ctorArguments)));
if (MethodToOverride.ContainsGenericParameters)
{
EmitLoadGenricMethodArguments(emitter, MethodToOverride.MakeGenericMethod(genericMethodArgs), invocationLocal);
}
emitter.CodeBuilder.AddStatement(
new ExpressionStatement(new MethodInvocationExpression(invocationLocal, InvocationMethods.Proceed)));
GeneratorUtil.CopyOutAndRefParameters(dereferencedArguments, invocationLocal, MethodToOverride, emitter);
if (MethodToOverride.ReturnType != typeof(void))
{
// Emit code to return with cast from ReturnValue
var getRetVal = new MethodInvocationExpression(invocationLocal, InvocationMethods.GetReturnValue);
emitter.CodeBuilder.AddStatement(new ReturnStatement(new ConvertExpression(emitter.ReturnType, getRetVal)));
}
else
{
emitter.CodeBuilder.AddStatement(new ReturnStatement());
}
return emitter;
}