本文整理汇总了C#中ProxyGenerationOptions.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# ProxyGenerationOptions.Initialize方法的具体用法?C# ProxyGenerationOptions.Initialize怎么用?C# ProxyGenerationOptions.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProxyGenerationOptions
的用法示例。
在下文中一共展示了ProxyGenerationOptions.Initialize方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClassProxyWithTargetGenerator
public ClassProxyWithTargetGenerator(ModuleScope scope, Type classToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
: base(scope, classToProxy)
{
CheckNotGenericTypeDefinition(targetType, "targetType");
EnsureDoesNotImplementIProxyTargetAccessor(targetType, "targetType");
CheckNotGenericTypeDefinitions(additionalInterfacesToProxy, "additionalInterfacesToProxy");
options.Initialize();
ProxyGenerationOptions = options;
this.additionalInterfacesToProxy = TypeUtil.GetAllInterfaces(additionalInterfacesToProxy).ToArray();
}
示例2: GenerateCode
public Type GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
{
// make sure ProxyGenerationOptions is initialized
options.Initialize();
interfaces = TypeUtil.GetAllInterfaces(interfaces);
CheckNotGenericTypeDefinitions(interfaces, "interfaces");
ProxyGenerationOptions = options;
var cacheKey = new CacheKey(targetType, interfaces, options);
return ObtainProxyType(cacheKey, (n, s) => GenerateType(n, interfaces, s));
}
示例3: GenerateCode
public Type GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
{
// make sure ProxyGenerationOptions is initialized
options.Initialize();
CheckNotGenericTypeDefinition(proxyTargetType, "proxyTargetType");
CheckNotGenericTypeDefinitions(interfaces, "interfaces");
EnsureValidBaseType(options.BaseTypeForInterfaceProxy);
ProxyGenerationOptions = options;
interfaces = TypeUtil.GetAllInterfaces(interfaces).ToArray();
var cacheKey = new CacheKey(proxyTargetType, targetType, interfaces, options);
return ObtainProxyType(cacheKey, (n, s) => GenerateType(n, proxyTargetType, interfaces, s));
}
示例4: GenerateCode
public Type GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
{
// make sure ProxyGenerationOptions is initialized
options.Initialize();
CheckNotGenericTypeDefinition(proxyTargetType, "proxyTargetType");
CheckNotGenericTypeDefinitions(interfaces, "interfaces");
EnsureValidBaseType(options.BaseTypeForInterfaceProxy);
Type proxyType;
interfaces = TypeUtil.GetAllInterfaces(interfaces).ToArray();
CacheKey cacheKey = new CacheKey(proxyTargetType, targetType, interfaces, options);
using (var locker = Scope.Lock.ForReadingUpgradeable())
{
Type cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
Logger.Debug("Found cached proxy type {0} for target type {1}.", cacheType.FullName, targetType.FullName);
return cacheType;
}
// Upgrade the lock to a write lock, then read again. This is to avoid generating duplicate types
// under heavy multithreaded load.
locker.Upgrade();
cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
Logger.Debug("Found cached proxy type {0} for target type {1}.", cacheType.FullName, targetType.FullName);
return cacheType;
}
// Log details about the cache miss
Logger.Debug("No cached proxy type was found for target type {0}.", targetType.FullName);
EnsureOptionsOverrideEqualsAndGetHashCode(options);
ProxyGenerationOptions = options;
var name = Scope.NamingScope.GetUniqueName("Castle.Proxies." + targetType.Name + "Proxy");
proxyType = GenerateType(name, proxyTargetType, interfaces, Scope.NamingScope.SafeSubScope());
AddToCache(cacheKey, proxyType);
}
return proxyType;
}
示例5: DelegateProxyGenerator
public DelegateProxyGenerator(ModuleScope scope, Type delegateType) : base(scope, delegateType)
{
ProxyGenerationOptions = new ProxyGenerationOptions(new DelegateProxyGenerationHook());
ProxyGenerationOptions.Initialize();
}
示例6: GenerateCode
public Type GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
{
// make sure ProxyGenerationOptions is initialized
options.Initialize();
CheckNotGenericTypeDefinition(proxyTargetType, "proxyTargetType");
CheckNotGenericTypeDefinitions(interfaces, "interfaces");
Type generatedType;
ReaderWriterLock rwlock = Scope.RWLock;
rwlock.AcquireReaderLock(-1);
CacheKey cacheKey = new CacheKey(proxyTargetType, targetType, interfaces, options);
Type cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
rwlock.ReleaseReaderLock();
return cacheType;
}
rwlock.UpgradeToWriterLock(-1);
try
{
cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
return cacheType;
}
SetGenerationOptions (options);
String newName = targetType.Name + "Proxy" + Guid.NewGuid().ToString("N");
// Add Interfaces that the proxy implements
ArrayList interfaceList = new ArrayList();
interfaceList.Add(targetType);
if (interfaces != null)
{
interfaceList.AddRange(interfaces);
}
if (!interfaceList.Contains(typeof(ISerializable)))
interfaceList.Add(typeof(ISerializable));
AddMixinInterfaces(interfaceList);
AddDefaultInterfaces(interfaceList);
Type baseType = options.BaseTypeForInterfaceProxy;
ClassEmitter emitter = BuildClassEmitter(newName, baseType, interfaceList);
CreateOptionsField (emitter);
emitter.DefineCustomAttribute(new XmlIncludeAttribute(targetType));
emitter.DefineCustomAttribute(new SerializableAttribute());
// Custom attributes
ReplicateNonInheritableAttributes(targetType, emitter);
// Fields generations
FieldReference interceptorsField = emitter.CreateField("__interceptors", typeof(IInterceptor[]));
targetField = emitter.CreateField("__target", proxyTargetType);
emitter.DefineCustomAttributeFor(interceptorsField, new XmlIgnoreAttribute());
emitter.DefineCustomAttributeFor(targetField, new XmlIgnoreAttribute());
// Implement builtin Interfaces
ImplementProxyTargetAccessor(targetType, emitter,interceptorsField);
// Collect methods
PropertyToGenerate[] propsToGenerate;
EventToGenerate[] eventToGenerates;
MethodInfo[] methods = CollectMethodsAndProperties(emitter, targetType, out propsToGenerate, out eventToGenerates);
if (interfaces != null && interfaces.Length != 0)
{
ArrayList tmpInterfaces = new ArrayList(interfaces);
foreach(Type inter in interfaces)
{
if (inter.IsAssignableFrom(proxyTargetType))
{
PropertyToGenerate[] tempPropsToGenerate;
EventToGenerate[] tempEventToGenerates;
MethodInfo[] methodsTemp =
CollectMethodsAndProperties(emitter, inter, out tempPropsToGenerate, out tempEventToGenerates);
PropertyToGenerate[] newPropsToGenerate =
new PropertyToGenerate[tempPropsToGenerate.Length + propsToGenerate.Length];
MethodInfo[] newMethods = new MethodInfo[methodsTemp.Length + methods.Length];
EventToGenerate[] newEvents = new EventToGenerate[eventToGenerates.Length + tempEventToGenerates.Length];
//.........这里部分代码省略.........
示例7: GenerateCode
public Type GenerateCode(Type[] interfaces, ProxyGenerationOptions options)
{
// make sure ProxyGenerationOptions is initialized
options.Initialize();
CheckNotGenericTypeDefinitions(interfaces, "interfaces");
Type type;
ReaderWriterLock rwlock = Scope.RWLock;
rwlock.AcquireReaderLock(-1);
CacheKey cacheKey = new CacheKey(targetType, interfaces, options);
Type cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
rwlock.ReleaseReaderLock();
return cacheType;
}
rwlock.UpgradeToWriterLock(-1);
try
{
cacheType = GetFromCache(cacheKey);
if (cacheType != null)
{
return cacheType;
}
SetGenerationOptions (options);
String newName = targetType.Name + "Proxy" + Guid.NewGuid().ToString("N");
// Add Interfaces that the proxy implements
ArrayList interfaceList = new ArrayList();
if (interfaces != null)
{
interfaceList.AddRange(interfaces);
}
AddMixinInterfaces(interfaceList);
AddDefaultInterfaces(interfaceList);
if (targetType.IsSerializable)
{
delegateToBaseGetObjectData = VerifyIfBaseImplementsGetObjectData(targetType);
if (!interfaceList.Contains(typeof(ISerializable)))
{
interfaceList.Add(typeof(ISerializable));
}
}
ClassEmitter emitter = BuildClassEmitter(newName, targetType, interfaceList);
CreateOptionsField (emitter);
emitter.DefineCustomAttribute(new XmlIncludeAttribute(targetType));
// Custom attributes
ReplicateNonInheritableAttributes(targetType, emitter);
// Fields generations
FieldReference interceptorsField =
emitter.CreateField("__interceptors", typeof(IInterceptor[]));
// Implement builtin Interfaces
ImplementProxyTargetAccessor(targetType, emitter,interceptorsField);
emitter.DefineCustomAttributeFor(interceptorsField, new XmlIgnoreAttribute());
// Collect methods
PropertyToGenerate[] propsToGenerate;
EventToGenerate[] eventToGenerates;
MethodInfo[] methods = CollectMethodsAndProperties(emitter, targetType, out propsToGenerate, out eventToGenerates);
RegisterMixinMethodsAndProperties(emitter, ref methods, ref propsToGenerate, ref eventToGenerates);
options.Hook.MethodsInspected();
// Constructor
ConstructorEmitter typeInitializer = GenerateStaticConstructor(emitter);
FieldReference[] mixinFields = AddMixinFields(emitter);
// constructor arguments
List<FieldReference> constructorArguments = new List<FieldReference>(mixinFields);
constructorArguments.Add(interceptorsField);
//.........这里部分代码省略.........