/// <summary> /// Starts the state class extraction from the given role class. /// </summary> /// <param name="sourceType">The role class to extract the state class from.</param> public override void Visit(TypeDefinition sourceType) { Tracer.TraceVerbose("Extract state class: {0} => {1}", sourceType.ToString(), TargetTypeName); TargetType = new TypeDefinition( string.Empty, TargetTypeName, TypeAttributes.NestedPublic | TypeAttributes.Sealed | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit, sourceType.Module.Import(typeof(object)) ); TargetType.CopyGenericParametersFrom(sourceType); AddStateProperty(); CreateDefaultConstructor(); }
/// <summary> /// Starts the code class extraction from the given role class. /// </summary> /// <param name="sourceType">The role class to extract the code class from.</param> public override void Visit(TypeDefinition sourceType) { Tracer.TraceVerbose("Extract code class: {0} => {1}", sourceType.ToString(), TargetTypeName); TargetType = new TypeDefinition( string.Empty, TargetTypeName, TypeAttributes.NestedPublic | TypeAttributes.Abstract | TypeAttributes.Sealed | TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit, sourceType.Module.Import(typeof(object)) ); //CreateConstructor(); // TODO: create a constructor for the static class? make it private? if (!SourceType.Methods.Any(method => method.IsConstructor && !method.IsStatic)) { // there are no constructors in the source type, but to be consistent, and to enable compatibility on new versions, // we still need to have an Init method in the static class CreateDefaultInitMethod(); } }
public RoleComposerResult ComposeRoles(MutationParameters parameters) { parameters.Validate(); _targetType = parameters.SourceType; if (_targetType == null) throw new ArgumentException("parameters must contain a SourceType", "parameters"); Tracer.TraceVerbose("Compose class: {0}", _targetType.ToString()); var result = new RoleComposerResult(); CheckComposition(result); if (!result.Success) { return result; } var roles = RetrieveRoles(); var conflictDetector = new ConflictDetector(_targetType); { var memberProcessResult = conflictDetector.Process(roles); result.AddResult(memberProcessResult); if (!memberProcessResult.Success) { return result; } } if (_targetType.IsRole()) { // roles are not composed return result; } { _container = conflictDetector.Container; var composeResult = ComposeRoles(roles); result.AddResult(composeResult); if (!composeResult.Success) { return result; } } return result; }
private XNodeOut RecompileClass(TypeDefinition classDef, XNodeOut fileNode) { if (!Build.TrackAnon && classDef.Name.StartsWith("<>")) return null; var classNode = SignatureToClass(classDef.ToString(), fileNode); if(classDef.BaseType != null) SetClassDependency(classNode, classDef.BaseType); // add fields if (Build.TrackFields && classDef.HasFields) foreach (var fieldDef in classDef.Fields) { var fieldNode = classNode.AddField(fieldDef); SetClassDependency(classNode, fieldDef.DeclaringType); if (fieldDef.FieldType.IsGenericParameter) Debug.WriteLine("Generic parameter ignored - " + fieldDef.FieldType.ToString()); else fieldNode.ReturnID = GetClassRef(fieldDef.FieldType).ID; } // save source code for methods foreach (var method in classDef.Methods) SaveCode(classNode, method); // track method creation/destruction if (Build.TrackInstances && !classDef.IsValueType) AddInstanceTracking(classDef, classNode); // add enter/exit info to method and call tracking List<MethodDefinition> addMethods = new List<MethodDefinition>(); foreach (var method in classDef.Methods.ToArray()) // toarray because recompile method may add new methods RecompileMethod(classNode, classDef, method); // recompile sub classes foreach (var nestedDef in classDef.NestedTypes) if (nestedDef.MetadataType == MetadataType.Class || nestedDef.MetadataType == MetadataType.ValueType) RecompileClass(nestedDef, fileNode); else Debug.WriteLine("Ignored nested type - " + nestedDef.ToString()); return classNode; }
private void OnTypeSelection (TypeDefinition td) { objectLabel.Text = td.ToString (); // very useful for debugging textview.Buffer.Text = String.Empty; }
private static long SizeOfEnum (TypeDefinition type) { foreach (FieldDefinition field in type.Fields) { // we looking for the special value__ // padding, if required, will be computed by caller if (!field.IsStatic) return SizeOf (field.FieldType); } throw new NotSupportedException (type.ToString () + " should not be usable as an enum type."); }
private XNodeOut RecompileClass(TypeDefinition classDef, XNodeOut fileNode) { if ( !TrackAnon && classDef.Name.StartsWith("<>") ) return null; var classNode = SignatureToClass(classDef.ToString(), fileNode); if(classDef.BaseType != null) SetClassDependency(classNode, classDef.BaseType); RecompileMethods(classDef, classNode); foreach (var nestedDef in classDef.NestedTypes) if (nestedDef.MetadataType == MetadataType.Class || nestedDef.MetadataType == MetadataType.ValueType) RecompileClass(nestedDef, fileNode); else Debug.WriteLine("Ignored nested type - " + nestedDef.ToString()); return classNode; }