public sealed override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { var type = method.DeclaringType; if (this.cacheName == null) { this.cacheName = type.FullName; } this.isClassGeneric = type.IsGenericType; this.isMethodGeneric = method.IsGenericMethod; this.className = type.FullName; this.methodName = method.Name; var parameters = method.GetParameters(); this.parameterTypeNames = parameters.Select(p => p.ParameterType.FullName).ToArray(); var indexes = new List <int>(); for (int cnt = 0; cnt < parameters.Length; cnt++) { var doNotIncludeInCacheKey = parameters[cnt].CustomAttributes .Any(a => a.AttributeType == typeof(DoNotIncludeInCacheKeyAttribute)); if (doNotIncludeInCacheKey) { indexes.Add(cnt); } } this.indexesNotToCache = indexes.ToArray(); }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { if (method.DeclaringType != null) { _fullMethodName = $"{method.DeclaringType.Name}.{method.Name}"; } }
/// <summary> /// Method executed at build time. Initializes the aspect instance. After the execution of /// <see cref="CompileTimeInitialize" />, the aspect is serialized as a managed /// resource inside the transformed assembly, and De-serialized at runtime. /// </summary> /// <param name="method">Method to which the current aspect instance /// has been applied.</param> /// <param name="aspectInfo">Unused variable.</param> public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { if (method.DeclaringType != null) { this.methodName = method.DeclaringType.FullName + "." + method.Name; } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { this.methodPath = method.DeclaringType.FullName .Replace('.', '/').Replace('+', '/') + "/" + method.Name; this.parameterNames = method.GetParameters().Select(p => p.Name).ToArray(); }
public override void CompileTimeInitialize(LocationInfo targetLocation, AspectInfo aspectInfo) { if (this.settingName == null) { this.settingName = targetLocation.Name; } }
public override void CompileTimeInitialize(Type target, AspectInfo aspectInfo) { Dictionary <int, PropertyInfo> indexes = new Dictionary <int, PropertyInfo>(); foreach (PropertyInfo propertyInfo in target.GetProperties()) { TlvMemberAttribute memberAttr = propertyInfo.GetCustomAttributes() .Where(x => x is TlvMemberAttribute) .Cast <TlvMemberAttribute>() .SingleOrDefault(); if (memberAttr == null) { Message.Write(MessageLocation.Of(propertyInfo), SeverityType.Error, "USR001", "Property {0} should be marked by TlvMemberAttribute.", propertyInfo); continue; } if (indexes.ContainsKey(memberAttr.Index)) { Message.Write(MessageLocation.Of(propertyInfo), SeverityType.Error, "USR002", "Property {0} marked by TlvMemberAttribute uses Index {1}, which is already used by property {2}.", propertyInfo, memberAttr.Index, indexes[memberAttr.Index]); continue; } indexes[memberAttr.Index] = propertyInfo; } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { m_FormattedSessionName = FormatSessionName(method); m_MethodName = FormatMethodName(method); base.CompileTimeInitialize(method, aspectInfo); }
/// <summary> /// アスペクトを描画 /// </summary> /// <param name="cvs">Cvs.</param> /// <param name="info">Info.</param> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <param name="aspectLine">Aspect line.</param> /// <param name="symbol">Symbol.</param> public void DrawAspect(SKCanvas cvs, AspectInfo info, Position from, Position to, SKPaint aspectLine, SKPaint symbol) { System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); SKManagedStream stream = new SKManagedStream(asm.GetManifestResourceStream("microcosm.system.AstroDotBasic.ttf")); { symbol.Typeface = SKTypeface.FromStream(stream); /* * p.TextSize = 48; * Position signValuePt; * SKColor pink = SKColors.Pink; * p.Color = pink; * for (int i = 0; i < signs.Length; i++) * { * signValuePt = Util.Rotate(diameter - 30, 0, 15 + 30 * i - ringsData[0].cusps[1]); * signValuePt.x = signValuePt.x + CenterX - 15; * signValuePt.y = -1 * signValuePt.y + CenterY + 20; * p.Color = CommonData.getSignColor(30 * i); * cvs.DrawText(signs[i], (float)signValuePt.x, (float)signValuePt.y, p); * } * p.Color = SKColors.Black; */ Console.WriteLine(info.aspectKind.ToString()); Console.WriteLine(info.absoluteDegree); Console.WriteLine(info.targetDegree); Console.WriteLine(""); cvs.DrawLine((float)from.x, (float)from.y, (float)to.x, (float)to.y, aspectLine); cvs.DrawText(CommonData.getAspectSymbol(info.aspectKind), (float)((from.x + to.x) / 2), (float)((from.y + to.y) / 2), symbol); } }
public override void CompileTimeInitialize(Type type, AspectInfo aspectInfo) { if (!ObjectAccessorsMap.Map.ContainsKey(type)) { ObjectAccessorsMap.Map.Add(type, new ObjectAccessors(type)); } }
private static void InitializeAspectsManually(object instance, AspectInfo info) { while (info != null) { var baseInfo = info.BaseAspectInfo; if (baseInfo == null) { //current info is of the lowest baseclass (there is no baseinfo), skip because we know this //must already have been initialized (since that triggered us to come here) return; } if (!info.IsEmpty) { var aspect = info.AspectGetter(instance); if (aspect != null) { return; //aspect already initialized, don't do it again! } //actual initialize info.InitializeMethod.Invoke(instance, new object[0]); } info = baseInfo; } }
private static AspectInfo LookupAspectInfoForType(Type typeLevel, out bool created) { AspectInfo aspectInfo; created = false; if (!AspectLookup.TryGetValue(typeLevel, out aspectInfo)) { var aspectField = typeLevel.GetFields(BindingFlags.Instance | BindingFlags.NonPublic) .SingleOrDefault(f => f.FieldType == typeof(EntityAttribute)); if (aspectField != null) { var initializeMethod = typeLevel.GetMethod("<>z__InitializeAspects", BindingFlags.Instance | BindingFlags.NonPublic); aspectInfo = new AspectInfo(FieldGetterUsingIl <EntityAttribute>(typeLevel, aspectField), initializeMethod); } else { aspectInfo = new AspectInfo(); } AspectLookup.Add(typeLevel, aspectInfo); created = true; } return(aspectInfo); }
private static void GetPlanes() { shadowFrustumPlanes[0].planeNormal = shadowCam.transform.right; shadowFrustumPlanes[1].planeNormal = shadowCam.transform.up; shadowFrustumPlanes[2].planeNormal = shadowCam.transform.forward; for (int i = 0; i < 3; ++i) { AspectInfo info = shadowFrustumPlanes[i]; float least = float.MaxValue; float maximum = float.MinValue; Vector3 lessPoint = Vector3.zero; Vector3 morePoint = Vector3.zero; for (int x = 0; x < 8; ++x) { float dotValue = Vector3.Dot(info.planeNormal, frustumCorners[x]); if (dotValue < least) { least = dotValue; lessPoint = frustumCorners[x]; } if (dotValue > maximum) { maximum = dotValue; morePoint = frustumCorners[x]; } } info.size = (maximum - least) / 2f; info.inPlanePoint = lessPoint + info.planeNormal * info.size; shadowFrustumPlanes[i] = info; } shadowFrustumPlanes[2].size = 75; }
public AspectDataOnAsyncMethod(MethodDefinition moveNext, AspectInfo info, AspectMethods methods, MethodDefinition method, ModuleDefinition module) : base(info, methods, method, module) { _moveNext = moveNext; _stateMachineLocal = method.Body.Variables.Single(v => v.VariableType.Resolve() == moveNext.DeclaringType); _stateMachine = _stateMachineLocal.VariableType; }
public override void CompileTimeInitialize( Type type, AspectInfo aspectInfo ) { this.explicitDependencyMap = analyzer.Value.AnalyzeType( type ); this.fieldValueComparer = new FieldValueComparer( type ); this.childPropertyChangedProcessor = ChildPropertyChangedProcessor.CompileTimeCreate( type, analyzer.Value.MethodFieldDependencies, this.fieldValueComparer, this.explicitDependencyMap ); }
public override void CompileTimeInitialize(Type type, AspectInfo aspectInfo) { this.explicitDependencyMap = analyzer.Value.AnalyzeType(type); this.fieldValueComparer = new FieldValueComparer(type); this.childPropertyChangedProcessor = ChildPropertyChangedProcessor.CompileTimeCreate( type, analyzer.Value.MethodFieldDependencies, this.fieldValueComparer, this.explicitDependencyMap); }
public override void CompileTimeInitialize(Type type, AspectInfo aspectInfo) { if ( !ObjectAccessorsMap.Map.ContainsKey( type ) ) { ObjectAccessorsMap.Map.Add( type, new ObjectAccessors( type ) ); } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { if (null == typeof(Cursors).GetProperty(this.cursorName, BindingFlags.Public | BindingFlags.Static)) { MessageSource.MessageSink.Write(new Message(MessageLocation.Of(method), SeverityType.Error, "USR001", "Invalid cursor name", null, "MyComponent", null)); } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { this.eventPath = method.DeclaringType.FullName.Replace(".", "/").Replace("+", "/") + "/" + method.Name; if (this.IncludeArguments) { this.parameterNames = method.GetParameters().Select(p => p.Name).ToArray(); } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { if (string.IsNullOrWhiteSpace(_prefix)) { _prefix = method.DeclaringType.FullName; } base.CompileTimeInitialize(method, aspectInfo); }
private static void SetAspectInfo(RuntimeMethodHandle methodHandle, RuntimeTypeHandle typeHandle, AspectInfo aspectInfo) { if (!AspectInfos.TryGetValue(methodHandle, out var methodsByType)) { AspectInfos[methodHandle] = methodsByType = new Dictionary <RuntimeTypeHandle, AspectInfo>(); } methodsByType[typeHandle] = aspectInfo; }
public override void CompileTimeInitialize(Type type, AspectInfo aspectInfo) { //Assign the class type to the _classType variable, //At compile time this will always be the type of the class we are currently in. _classType = type; base.CompileTimeInitialize(type, aspectInfo); }
public override void CompileTimeInitialize(System.Type type, AspectInfo aspectInfo) { SetHbmMappings(type); if (mappings == null) return; SetMappedMembers(type); }
public override void CompileTimeInitialize(LocationInfo locationInfo, AspectInfo aspectInfo) { RaisePropertyChanged = locationInfo.DeclaringType.GetMethod( "RaisePropertyChanged", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new[] { typeof(string) }, null); }
public AspectData(AspectInfo info, AspectMethods methods, MethodDefinition method, ModuleDefinition module) { Info = info; AspectMethods = methods; _method = method; _module = module; _referenceFinder = new ReferenceFinder(module); _creator = new InstructionBlockChainCreator(method, module); }
//Intialize some fields at compile time to improve performance. public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { base.CompileTimeInitialize(method, aspectInfo); //Compile Time initizalization of the class name. _className = method.ReflectedType.Name; //Compile Time initizalization of the method name. _methodName = _className + "." + method.Name; parameterInfos = new List <ParameterInfo>(method.GetParameters()); }
/// <summary> /// Set Shadowcamera Position /// </summary> /// <param name="shadMap"></param> Shadowmap component /// <param name="settings"></param> Shadowmap Settings public static void SetShadowCameraPositionCloseFit(ref ShadowMapComponent shadMap, ref ShadowmapSettings settings) { Camera shadowCam = shadMap.shadowCam; NativeArray <AspectInfo> shadowFrustumPlanes = shadMap.shadowFrustumPlanes; AspectInfo info = shadowFrustumPlanes[0]; info.planeNormal = shadowCam.transform.right; shadowFrustumPlanes[0] = info; info = shadowFrustumPlanes[1]; info.planeNormal = shadowCam.transform.up; shadowFrustumPlanes[1] = info; info = shadowFrustumPlanes[2]; info.planeNormal = shadowCam.transform.forward; shadowFrustumPlanes[2] = info; for (int i = 0; i < 3; ++i) { info = shadowFrustumPlanes[i]; float least = float.MaxValue; float maximum = float.MinValue; Vector3 lessPoint = Vector3.zero; Vector3 morePoint = Vector3.zero; for (int x = 0; x < 8; ++x) { float dotValue = Vector3.Dot(info.planeNormal, shadMap.frustumCorners[x]); if (dotValue < least) { least = dotValue; lessPoint = shadMap.frustumCorners[x]; } if (dotValue > maximum) { maximum = dotValue; morePoint = shadMap.frustumCorners[x]; } } info.size = (maximum - least) / 2f; info.inPlanePoint = lessPoint + info.planeNormal * info.size; shadowFrustumPlanes[i] = info; } AspectInfo temp = shadowFrustumPlanes[2]; temp.size = settings.farestDistance; //Farest Cascade Distance shadowFrustumPlanes[2] = temp; Transform tr = shadowCam.transform; for (int i = 0; i < 3; ++i) { info = shadowFrustumPlanes[i]; float dist = Vector3.Dot(info.inPlanePoint, info.planeNormal) - Vector3.Dot(tr.position, info.planeNormal); tr.position += dist * info.planeNormal; } shadowCam.orthographicSize = shadowFrustumPlanes[1].size; shadowCam.aspect = shadowFrustumPlanes[0].size / shadowFrustumPlanes[1].size; shadowCam.nearClipPlane = 0; shadowCam.farClipPlane = shadowFrustumPlanes[2].size * 2; tr.position -= shadowFrustumPlanes[2].size * shadowFrustumPlanes[2].planeNormal; }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { _methodFullName = string.Format("{0}.{1}", method.ReflectedType, method.Name); MethodInfo methodInfo = (MethodInfo)method; _isEntityResponse = typeof(EntityResponse).IsAssignableFrom(methodInfo.ReturnType); base.CompileTimeInitialize(method, aspectInfo); }
/// <summary>Method invoked at build time to initialize the instance fields of the current aspect. This method is invoked before any other build-time method.</summary> /// <param name="method">Method to which the current aspect is applied</param> /// <param name="aspectInfo">Reserved for future usage.</param> /// <remarks>This implementation analyzes the annotated method and prepares the conditions for runtime verification.</remarks> public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { try { this.Metadata = this.Analyzer.AnalyzeMethod(method, this.InheritContracts); } catch (Exception exception) { throw new InvalidOperationException(String.Format("Method analysis failed for method {0}::{1}.", method.DeclaringType.Name, method.Name), exception); } }
private void aspectCheckbox_Unchecked(object sender, RoutedEventArgs e) { ListBoxItem uncheckedItem = this.aspectListBox.ItemContainerGenerator.ContainerFromItem((sender as CheckBox).DataContext) as ListBoxItem; if (uncheckedItem != null) { AspectInfo a = (AspectInfo)uncheckedItem.Content; ((App)App.Current).setAspect(a.AspectDeg, false); uncheckedItem.IsSelected = false; } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { if (m_Keys != null && m_Keys.Count > 0) { List <ParameterInfo> parameterList = new List <ParameterInfo>(method.GetParameters()); foreach (ParamCacheKey key in m_Keys) { key.ParamIndex = parameterList.FindIndex(p => p.Name == key.ParamName); } } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { if (m_Keys != null && m_Keys.Count > 0) { List<ParameterInfo> parameterList = new List<ParameterInfo>(method.GetParameters()); foreach (ParamCacheKey key in m_Keys) { key.ParamIndex = parameterList.FindIndex(p => p.Name == key.ParamName); } } }
public override void CompileTimeInitialize(Type type, AspectInfo aspectInfo) { //TODO: What about overloads?!? this.MethodAttributes = new Dictionary <string, MethodSnapshotStrategy>(); foreach (MethodInfo method in type.GetMethods(BindingFlagsSet.PublicInstanceDeclared)) { if (method.GetCustomAttributes(typeof(NoAutomaticChangeTrackingOperationAttribute), true).Any()) { this.MethodAttributes.Add(method.Name, MethodSnapshotStrategy.Never); } else if (method.GetCustomAttributes(typeof(ForceChangeTrackingOperationAttribute), true).Any()) { this.MethodAttributes.Add(method.Name, MethodSnapshotStrategy.Always); } else { this.MethodAttributes.Add(method.Name, MethodSnapshotStrategy.Auto); } } this.TrackedFields = new HashSet <string>(); foreach (var propertyInfo in type.GetProperties(BindingFlagsSet.AllInstanceDeclared).Where(f => f.IsDefined(typeof(ChangeTrackedAttribute), false))) { var propertyInfoClosure = propertyInfo; var fields = ReflectionSearch.GetDeclarationsUsedByMethod(propertyInfo.GetGetMethod(true)) .Select(r => r.UsedDeclaration as FieldInfo) .Where(f => f != null) .Where(f => propertyInfoClosure.PropertyType.IsAssignableFrom(f.FieldType)) .Where(f => f.DeclaringType.IsAssignableFrom(type)) .ToList(); if (fields.Count() != 1) { DomainMessageSource.Instance.Write(propertyInfo, SeverityType.Error, "INPC013", propertyInfo.Name); } else { this.TrackedFields.Add(fields.First().Name); } } foreach (FieldInfo fieldInfo in type .GetFields(BindingFlagsSet.AllInstanceDeclared) .Where(f => f.IsDefined(typeof(ChangeTrackedAttribute), false))) { this.TrackedFields.Add(fieldInfo.Name); } base.CompileTimeInitialize(type, aspectInfo); }
/// <summary> /// Method invoked at build time to initialize the instance fields of the current aspect. This method is invoked /// before any other build-time method. /// </summary> /// <param name="method">Method to which the current aspect is applied</param> /// <param name="aspectInfo">Reserved for future usage.</param> public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { if (method == null) { return; } _methodName = method.Name; if (method.DeclaringType != null) { _declaringType = method.DeclaringType; } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { _printExceptions = method.Name != "ToString"; _printTrace = method.IsPublic && method.Name.StartsWith("get_") == false && method.IsConstructor == false; _methodRelevantForTimeMeasure = method.Name.StartsWith("get_") == false; _methodName = method.Name; if (method.DeclaringType != null) { _shortClassName = method.DeclaringType.Name; } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { this.encodedParams = new List <int>(); ParameterInfo[] allParams = method.GetParameters(); for (int i = 0; i < allParams.Length; i++) { if (allParams[i].GetCustomAttribute(typeof(HTMLEncodeAttribute)) != null) { this.encodedParams.Add(i); } } }
public override void CompileTimeInitialize(Type type, AspectInfo aspectInfo) { //TODO: What about overloads?!? this.MethodAttributes = new Dictionary<string, MethodSnapshotStrategy>(); foreach (MethodInfo method in type.GetMethods(BindingFlagsSet.PublicInstanceDeclared)) { if (method.GetCustomAttributes(typeof(NoAutomaticChangeTrackingOperationAttribute), true).Any()) { this.MethodAttributes.Add(method.Name, MethodSnapshotStrategy.Never); } else if (method.GetCustomAttributes(typeof(ForceChangeTrackingOperationAttribute), true).Any()) { this.MethodAttributes.Add(method.Name, MethodSnapshotStrategy.Always); } else { this.MethodAttributes.Add(method.Name, MethodSnapshotStrategy.Auto); } } this.TrackedFields = new HashSet<string>(); foreach (var propertyInfo in type.GetProperties(BindingFlagsSet.AllInstanceDeclared).Where(f => f.IsDefined(typeof(ChangeTrackedAttribute), false))) { var propertyInfoClosure = propertyInfo; var fields = ReflectionSearch.GetDeclarationsUsedByMethod(propertyInfo.GetGetMethod(true)) .Select(r => r.UsedDeclaration as FieldInfo) .Where(f => f != null) .Where(f => propertyInfoClosure.PropertyType.IsAssignableFrom(f.FieldType)) .Where(f => f.DeclaringType.IsAssignableFrom(type)) .ToList(); if (fields.Count() != 1) { DomainMessageSource.Instance.Write(propertyInfo, SeverityType.Error, "INPC013", propertyInfo.Name); } else { this.TrackedFields.Add(fields.First().Name); } } foreach (FieldInfo fieldInfo in type .GetFields(BindingFlagsSet.AllInstanceDeclared) .Where(f => f.IsDefined(typeof(ChangeTrackedAttribute), false))) { this.TrackedFields.Add(fieldInfo.Name); } base.CompileTimeInitialize(type, aspectInfo); }
public sealed override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { var type = method.DeclaringType; if (this.cacheName == null) { this.cacheName = type.FullName; } this.isClassGeneric = type.IsGenericType; this.isMethodGeneric = method.IsGenericMethod; this.className = type.FullName; this.methodName = method.Name; var parameters = method.GetParameters(); this.parameterTypeNames = parameters.Select(p => p.ParameterType.FullName).ToArray(); this.genericArgumentTypeNames = method.GetGenericArguments().Select(a => a.FullName).ToArray(); var indexes = new List <int>(); for (int cnt = 0; cnt < parameters.Length; cnt++) { var doNotIncludeInCacheKey = parameters[cnt].CustomAttributes .Any(a => a.AttributeType == typeof(DoNotIncludeInCacheKeyAttribute)); if (doNotIncludeInCacheKey) { indexes.Add(cnt); } } this.indexesNotToCache = indexes.ToArray(); TryGetKeyDataTypes(this.dataKeyConverterType, out this.keyType, out this.dataType); this.createDataKeyConverter = this.dataKeyConverterType.GetConstructor(new Type[0]); this.convertDataToKey = this.dataKeyConverterType.GetMethod("GetKey", new [] { this.dataType }); var keyListType = typeof(List <>).MakeGenericType(this.keyType); var dataListType = typeof(List <>).MakeGenericType(this.dataType); var dataEnumerableType = typeof(IEnumerable <>).MakeGenericType(this.dataType); this.createKeyList = keyListType.GetConstructor(new Type[0]); this.createDataList = dataListType.GetConstructor(new Type[0]); this.addKey = keyListType.GetMethod("Add", new[] { this.keyType }); this.addData = dataListType.GetMethod("Add", new[] { this.dataType }); this.addDataRange = dataListType.GetMethod("AddRange", new[] { dataEnumerableType }); this.keysCount = keyListType.GetProperty("Count").GetGetMethod(); }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { var argumentAttributes = method.GetCustomAttributes(typeof(ArgumentsAttribute)).ToArray(); argumentsCollection = new object[argumentAttributes.Length][]; for (int i = 0; i < argumentAttributes.Length; i++) { object[] givenArguments = ((ArgumentsAttribute)argumentAttributes[i]).Arguments; object[] arguments = new object[givenArguments.Length + 1]; Array.Copy(givenArguments, arguments, givenArguments.Length); arguments[givenArguments.Length] = true; argumentsCollection[i] = arguments; } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { _methodName = method.Name; _className = method.DeclaringType; var parameters = method.GetParameters(); for(int i=0;i<parameters.Length;i++) { if(parameters[i].Name == "amount") { _amountParameterIndex = i; } } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { _methodName = method.Name; _className = method.DeclaringType.FullName; ParameterInfo[] parameterInfos = method.GetParameters(); if (parameterInfos.Length > 0) { _methodArguments = new string[parameterInfos.Length]; for (int i = 0; i < parameterInfos.Length; i++) { _methodArguments[i] = parameterInfos[i].Name; } } }
/// <inheritdoc /> public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { if (null != _handlerType) { if (!typeof(GuardedHandler).IsAssignableFrom(_handlerType)) { throw new IncorrectTypeException($"Type {_handlerType.Name} isn't (but must be) derived from GuardedHandler."); } _handler = (GuardedHandler)Activator.CreateInstance(_handlerType); } base.CompileTimeInitialize(method, aspectInfo); }
/// <summary> /// Method invoked at build time to initialize the instance fields of the current aspect. This method is invoked before /// any other build-time method. /// </summary> /// <param name="method">Method to which the current aspect is applied.</param> /// <param name="aspectInfo">Reserved for future usage.</param> /// <exception cref="System.ArgumentNullException">method</exception> public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { if (method == null) { throw new ArgumentNullException("method"); } if (method.DeclaringType != null) { this.methodName = method.DeclaringType.FullName + "." + method.Name; } else { this.methodName = method.Name; } }
/// <summary>Method executed at build time.</summary> public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { this.instanceName = method.DeclaringType.FullName + "." + method.Name; if (showWarningOnlyOnce) { return; } showWarningOnlyOnce = true; Message.Write( MessageLocation.Of(method), SeverityType.Warning, "StackOverflowDetectionAspect", "Getting a StackTrace is very expensive. This aspect should only be used to debug a known issue and should be removed after the issue is located, Method: {0} and other!", method.DeclaringType.Name); }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { PerformanceCounterCategoryData categoryData; if (!sharedDataRef.Categories.TryGetValue(this.CategoryName, out categoryData)) { categoryData = new PerformanceCounterCategoryData() {CategoryType=this.CategoryType}; sharedDataRef.Categories.Add(this.CategoryName, categoryData); } else if (categoryData.CategoryType != this.CategoryType) { // todo: emit error } categoryData.Counters.Add(new CounterCreationData(this.CounterName, "", this.CounterType)); if (this.BaseCounterType.HasValue) { categoryData.Counters.Add(new CounterCreationData(this.BaseCounterName, "", this.BaseCounterType.Value)); } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { if (!typeof(IHasPassport).IsAssignableFrom(method.DeclaringType)) { throw new InvalidAnnotationException(string.Format("{0} does not support {1}" , method.DeclaringType.AssemblyQualifiedName , typeof(IPassport).AssemblyQualifiedName)); } _parameterNames = method.GetParameters().Select(p => p.Name).ToArray(); if (_sessionParameter == null) return; _sessionParameterIndex = Array.IndexOf(_parameterNames, _sessionParameter); if (_sessionParameterIndex == -1) { throw new ArgumentOutOfRangeException(string.Format("Index of {0} not in [{1}]", _sessionParameter, string.Join("|", _parameterNames))); } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { var sb = new StringBuilder(); if (method.DeclaringType != null) { sb.AppendFormat("{0}_", method.DeclaringType.FullName); } sb.Append(method.Name); foreach (var param in method.GetParameters()) { if (param != null) { sb.AppendFormat("_{0}", param.Name); } } _methodHash = CalculateMd5Hash(sb.ToString()); base.CompileTimeInitialize(method, aspectInfo); }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { if (m_IncludeReturnValue) { if (method is MethodInfo) { MethodInfo info = (MethodInfo)method; m_IncludeReturnValue = info.ReturnType != typeof(void); } if (method.IsConstructor) { m_IncludeReturnValue = false; } } base.CompileTimeInitialize(method, aspectInfo); }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { var parameters = method.GetParameters().ToList(); _parameterNames = parameters.Select(p => p.Name).ToArray(); if (_passportParameter != null) { _passportParameterIndex = Array.IndexOf(_parameterNames, _passportParameter); if (_passportParameterIndex == -1) { throw new ArgumentOutOfRangeException(_passportParameter); } if (typeof (IPassport) != parameters[_passportParameterIndex].ParameterType) { throw new InvalidCastException(string.Format("Cannot convert {0} to {1}" , parameters[_passportParameterIndex].ParameterType.AssemblyQualifiedName , typeof (IPassport).AssemblyQualifiedName)); } } else { // Use first IPassport type var firstPassport = parameters.FirstOrDefault(x => typeof(IPassport) == x.ParameterType); if (firstPassport == null) { throw new Exception("Missing IPassport parameter."); } _passportParameterIndex = Array.IndexOf(_parameterNames, firstPassport.Name); } // Safeguard - we don't want to attach the Passport to itself // For example: If you are using an IOC, then depending on the Lifetime of the Passport // it might be the same passport as the caller // Using AutoFac the same Passport instance will be passed to each service/parameter // in the constructor when using InstancePerHttpRequest lifetime _passportParameters = parameters.Where(x => typeof(IPassport).IsAssignableFrom(x.ParameterType)) .Select(p => p.Name).ToArray() ; }
/// <summary> /// </summary> /// <param name="method"></param> /// <param name="aspectInfo"></param> public override void CompileTimeInitialize(System.Reflection.MethodBase method, AspectInfo aspectInfo) { base.CompileTimeInitialize(method, aspectInfo); Type reflectedType; try { reflectedType = method.ReflectedType; } catch (Exception) { reflectedType = method.DeclaringType; } string methodName = method.Name; _entering = "Entering " + reflectedType.Name + "." + methodName; if (!string.IsNullOrEmpty(_message)) _entering += Environment.NewLine; _leaving = "Leaving " + reflectedType.Name + "." + methodName; _leavingWithException = "Leaving " + reflectedType.Name + "." + methodName +" with Exception: "; _error = "Error executing " + reflectedType.Name + "." + methodName; }
public override void CompileTimeInitialize(Type type, AspectInfo aspectInfo) { base.CompileTimeInitialize(type, aspectInfo); if (!typeof(IEditableObject).IsAssignableFrom(type)) { this.interfaceImplementationMap = new Dictionary<MethodBase, MethodBase>(); return; } if (typeof(IEditableObject).IsAssignableFrom(type)) { var targetIEditableMethodsInterfaceMap = type.GetInterfaceMap(typeof(IEditableObject)); var aspectIEditableMethodsInterfaceMap = this.GetType().GetInterfaceMap(typeof(IEditableObject)); var targetIEditableMethodsMap = targetIEditableMethodsInterfaceMap.InterfaceMethods.Zip( targetIEditableMethodsInterfaceMap.TargetMethods, (im, tm) => new { InterfaceMethod = im, TargetMethod = tm }) .ToList(); if (!targetIEditableMethodsMap.All(t => t.TargetMethod.IsToBeImplementedMethod())) { DomainMessageSource.Instance.Write(type, SeverityType.Error, "DOM016", type.FullName); } var aspectIEditableMethodsMap = aspectIEditableMethodsInterfaceMap.InterfaceMethods.Zip( aspectIEditableMethodsInterfaceMap.TargetMethods, (im, tm) => new { InterfaceMethod = im, TargetMethod = tm }) .ToList(); this.interfaceImplementationMap = targetIEditableMethodsMap .Join( aspectIEditableMethodsMap, m => m.InterfaceMethod, m => m.InterfaceMethod, (tm, am) => new { TargetMethod = (MethodBase)tm.TargetMethod, AspectMethod = (MethodBase)am.TargetMethod }) .ToDictionary(r => r.TargetMethod, r => r.AspectMethod); } }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { // fetch the method's name and class full-name where the exception was trown _methodName = method.Name; _className = method.DeclaringType.FullName; // get the method's parameters' name ParameterInfo[] parameterInfos = method.GetParameters(); if (parameterInfos.Length <= 0) return; _methodArguments = new string[parameterInfos.Length]; for (int i = 0; i < parameterInfos.Length; i++) { _methodArguments[i] = parameterInfos[i].Name; } // figuring out if the method must return a value or not MethodInfo methodInfo = method as MethodInfo; if (methodInfo == null) return; _hasToReturnSomething = !methodInfo.ReturnType.FullName.Equals("System.Void"); if (_hasToReturnSomething) { _typeToReturn = methodInfo.ReturnType; } }
// At compile time, initialize the format string that will be // used to create the cache keys. public override void CompileTimeInitialize( MethodBase method, AspectInfo aspectInfo ) { this.formatStrings = Formatter.GetMethodFormatStrings( method ); }
public override void CompileTimeInitialize(PostSharp.Reflection.LocationInfo targetLocation, AspectInfo aspectInfo) { propname = targetLocation.Name; }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { _methodName = method.Name; _className = method.DeclaringType.Name; }
public override void CompileTimeInitialize(System.Reflection.MethodBase method, AspectInfo aspectInfo) { this.formatStrings = Formatter.GetMethodFormatStrings(method); base.CompileTimeInitialize(method, aspectInfo); }
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { // TODO: Initialize any instance field whose value only depends on the method to which the aspect is applied. }
// This method is executed at build-time, inside PostSharp. public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo) { // Computes the field value at build-time so that reflection is not necessary at runtime. this.MethodName = method.DeclaringType.FullName + "." + method.Name; this.ParameterInfo = method.GetParameters(); }
public override void CompileTimeInitialize(System.Reflection.MethodBase method, AspectInfo aspectInfo) { methodName = method.DeclaringType.FullName + "." + method.Name; }
public override void CompileTimeInitialize(LocationInfo targetLocation, AspectInfo aspectInfo) { if (targetLocation.LocationType == typeof(Guid)) IsGuid = true; }